From bf15830f15570493ced7cd5c8a7451e0e9756083 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Tue, 10 Jul 2012 14:30:45 +0300 Subject: [PATCH] Script: Removed various Lua functions (check LuaModifications.txt) --- Library/Library.vcxproj | 1 + Library/Library.vcxproj.filters | 3 +++ Library/lua/LuaManager.cpp | 20 +------------------- Library/lua/LuaModifications.txt | 14 ++++++++++++++ Library/lua/lua/lbaselib.c | 12 ++++++------ Library/lua/lua/linit.c | 4 ++-- Library/lua/lua/liolib.c | 16 ++++++++-------- Library/lua/lua/loslib.c | 19 ++++++++++--------- Library/lua/lua/luaconf.h | 2 +- 9 files changed, 46 insertions(+), 45 deletions(-) create mode 100644 Library/lua/LuaModifications.txt diff --git a/Library/Library.vcxproj b/Library/Library.vcxproj index 78a0eafd..79720eb4 100644 --- a/Library/Library.vcxproj +++ b/Library/Library.vcxproj @@ -360,6 +360,7 @@ + diff --git a/Library/Library.vcxproj.filters b/Library/Library.vcxproj.filters index c9d2d621..bb74fd35 100644 --- a/Library/Library.vcxproj.filters +++ b/Library/Library.vcxproj.filters @@ -180,6 +180,9 @@ Lua\Lua + + Lua\Lua + Lua\Lua diff --git a/Library/lua/LuaManager.cpp b/Library/lua/LuaManager.cpp index a193625f..332e8525 100644 --- a/Library/lua/LuaManager.cpp +++ b/Library/lua/LuaManager.cpp @@ -30,25 +30,7 @@ void LuaManager::Initialize() // Initialize Lua c_State = luaL_newstate(); - // Initialize standard libraries except debug, modified from linit.c - const luaL_Reg lualibs[] = - { - { "", luaopen_base }, - { LUA_LOADLIBNAME, luaopen_package }, - { LUA_TABLIBNAME, luaopen_table }, - { LUA_IOLIBNAME, luaopen_io }, - { LUA_OSLIBNAME, luaopen_os }, - { LUA_STRLIBNAME, luaopen_string }, - { LUA_MATHLIBNAME, luaopen_math }, - { NULL, NULL } - }; - - for (const luaL_Reg* lib = lualibs; lib->func; ++lib) - { - lua_pushcfunction(c_State, lib->func); - lua_pushstring(c_State, lib->name); - lua_call(c_State, 1, 0); - } + luaL_openlibs(c_State); // Register custom types and functions RegisterGlobal(c_State); diff --git a/Library/lua/LuaModifications.txt b/Library/lua/LuaModifications.txt new file mode 100644 index 00000000..7b164a7e --- /dev/null +++ b/Library/lua/LuaModifications.txt @@ -0,0 +1,14 @@ +lbaselib.c +- Commented out collectgarbage, getfenv, print, and setfenv functions in base_funcs array +- Commented out luaL_register for coroutine library + +liolib.c +- Commented out popen in iolib array +- Commented out createstdfile calls for stdin/stdout/stderr in luaopen_io +- Commented out popen related calls in luaopen_io + +linit.c +- Commented out debug and package libraries + +loslib.c +- Commented out exit function in syslib array diff --git a/Library/lua/lua/lbaselib.c b/Library/lua/lua/lbaselib.c index 2ab550bd..232fe146 100644 --- a/Library/lua/lua/lbaselib.c +++ b/Library/lua/lua/lbaselib.c @@ -446,23 +446,23 @@ static int luaB_newproxy (lua_State *L) { static const luaL_Reg base_funcs[] = { {"assert", luaB_assert}, - {"collectgarbage", luaB_collectgarbage}, +// {"collectgarbage", luaB_collectgarbage}, {"dofile", luaB_dofile}, {"error", luaB_error}, - {"gcinfo", luaB_gcinfo}, - {"getfenv", luaB_getfenv}, +// {"gcinfo", luaB_gcinfo}, +// {"getfenv", luaB_getfenv}, {"getmetatable", luaB_getmetatable}, {"loadfile", luaB_loadfile}, {"load", luaB_load}, {"loadstring", luaB_loadstring}, {"next", luaB_next}, {"pcall", luaB_pcall}, - {"print", luaB_print}, +// {"print", luaB_print}, {"rawequal", luaB_rawequal}, {"rawget", luaB_rawget}, {"rawset", luaB_rawset}, {"select", luaB_select}, - {"setfenv", luaB_setfenv}, +// {"setfenv", luaB_setfenv}, {"setmetatable", luaB_setmetatable}, {"tonumber", luaB_tonumber}, {"tostring", luaB_tostring}, @@ -647,7 +647,7 @@ static void base_open (lua_State *L) { LUALIB_API int luaopen_base (lua_State *L) { base_open(L); - luaL_register(L, LUA_COLIBNAME, co_funcs); +// luaL_register(L, LUA_COLIBNAME, co_funcs); return 2; } diff --git a/Library/lua/lua/linit.c b/Library/lua/lua/linit.c index c1f90dfa..0ebd1a03 100644 --- a/Library/lua/lua/linit.c +++ b/Library/lua/lua/linit.c @@ -16,13 +16,13 @@ static const luaL_Reg lualibs[] = { {"", luaopen_base}, - {LUA_LOADLIBNAME, luaopen_package}, +// {LUA_LOADLIBNAME, luaopen_package}, {LUA_TABLIBNAME, luaopen_table}, {LUA_IOLIBNAME, luaopen_io}, {LUA_OSLIBNAME, luaopen_os}, {LUA_STRLIBNAME, luaopen_string}, {LUA_MATHLIBNAME, luaopen_math}, - {LUA_DBLIBNAME, luaopen_debug}, +// {LUA_DBLIBNAME, luaopen_debug}, {NULL, NULL} }; diff --git a/Library/lua/lua/liolib.c b/Library/lua/lua/liolib.c index 649f9a59..e716fb35 100644 --- a/Library/lua/lua/liolib.c +++ b/Library/lua/lua/liolib.c @@ -484,7 +484,7 @@ static const luaL_Reg iolib[] = { {"lines", io_lines}, {"open", io_open}, {"output", io_output}, - {"popen", io_popen}, +// {"popen", io_popen}, {"read", io_read}, {"tmpfile", io_tmpfile}, {"type", io_type}, @@ -543,14 +543,14 @@ LUALIB_API int luaopen_io (lua_State *L) { luaL_register(L, LUA_IOLIBNAME, iolib); /* create (and set) default files */ newfenv(L, io_noclose); /* close function for default files */ - createstdfile(L, stdin, IO_INPUT, "stdin"); - createstdfile(L, stdout, IO_OUTPUT, "stdout"); - createstdfile(L, stderr, 0, "stderr"); +// createstdfile(L, stdin, IO_INPUT, "stdin"); +// createstdfile(L, stdout, IO_OUTPUT, "stdout"); +// createstdfile(L, stderr, 0, "stderr"); lua_pop(L, 1); /* pop environment for default files */ - lua_getfield(L, -1, "popen"); - newfenv(L, io_pclose); /* create environment for 'popen' */ - lua_setfenv(L, -2); /* set fenv for 'popen' */ - lua_pop(L, 1); /* pop 'popen' */ +// lua_getfield(L, -1, "popen"); +// newfenv(L, io_pclose); /* create environment for 'popen' */ +// lua_setfenv(L, -2); /* set fenv for 'popen' */ +// lua_pop(L, 1); /* pop 'popen' */ return 1; } diff --git a/Library/lua/lua/loslib.c b/Library/lua/lua/loslib.c index da06a572..5d507dd6 100644 --- a/Library/lua/lua/loslib.c +++ b/Library/lua/lua/loslib.c @@ -202,14 +202,15 @@ static int os_difftime (lua_State *L) { static int os_setlocale (lua_State *L) { - static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, - LC_NUMERIC, LC_TIME}; - static const char *const catnames[] = {"all", "collate", "ctype", "monetary", - "numeric", "time", NULL}; - const char *l = luaL_optstring(L, 1, NULL); - int op = luaL_checkoption(L, 2, "all", catnames); - lua_pushstring(L, setlocale(cat[op], l)); - return 1; +// static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, +// LC_NUMERIC, LC_TIME}; +// static const char *const catnames[] = {"all", "collate", "ctype", "monetary", +// "numeric", "time", NULL}; +// const char *l = luaL_optstring(L, 1, NULL); +// int op = luaL_checkoption(L, 2, "all", catnames); +// lua_pushstring(L, setlocale(cat[op], l)); +// return 1; + return 0; } @@ -222,7 +223,7 @@ static const luaL_Reg syslib[] = { {"date", os_date}, {"difftime", os_difftime}, {"execute", os_execute}, - {"exit", os_exit}, +// {"exit", os_exit}, {"getenv", os_getenv}, {"remove", os_remove}, {"rename", os_rename}, diff --git a/Library/lua/lua/luaconf.h b/Library/lua/lua/luaconf.h index b8155fdf..5ad00b92 100644 --- a/Library/lua/lua/luaconf.h +++ b/Library/lua/lua/luaconf.h @@ -702,7 +702,7 @@ union luai_Cast { double l_d; long l_l; }; #endif #if defined(LUA_WIN) -#define LUA_DL_DLL +//#define LUA_DL_DLL #endif