I have done my homework and studied other responses on this topic but none address my particular issue.
I want to remove the io library completely and the os only partially (let's say i want to keep os.clock() and others)
How can I achieve this only from the C API.
Due to the nature of the project I am not allowed to modify the Lua headers and the scripts that will be sent to me. These are not under my control. The only thing I can modify is the interpreter.
doing something like this:
lua_pushnil(state_pointer);
lua_setglobal(state_pointer, "os.execute");
won't help much because in the script the user can call os = require('os') and get all the functions back
I am not allowed to disable the require function so this makes things harder.
Any ideas?
PS:More of a curiosity: if I do something like
luaopen_base(L);
luaopen_table(L);
luaopen_string(L);
luaopen_math(L);
luaopen_loadlib(L); (basically i'm loading every library by hand except os and io)
instead of
luaL_openlibs(L); (this loads all the libraries)
would os = require('os') or io = require('io') still work?
@Nicol Bolas don't know if i'm doing something wrong but os = require('os') & require('io') just brings everything back.
my code:
luaL_openlibs(LuaInstance); /* load the libs */
lua_pushnil(LuaInstance);
lua_setglobal(LuaInstance, "io");
lua_pushnil(LuaInstance);
lua_setglobal(LuaInstance, "os.execute");
lua_pushnil(LuaInstance);
lua_setglobal(LuaInstance, "os.rename");
lua_pushnil(LuaInstance);
lua_setglobal(LuaInstance, "os.remove");
lua_pushnil(LuaInstance);
lua_setglobal(LuaInstance, "os.exit");
In my script i just do a
os = require('os')
io = require('io')
after this os functions and io functions all work. os.exit still closes my app and io.write works as usual