title: How to remove particular functions from os library without editing the Lua headers or the scripts
body: <p>I have done my homework and studied other responses on this topic but none address my particular issue.</p>
  
  <p>I want to remove the io library completely and the os only partially (let's say i want to keep os.clock() and others)</p>
  
  <p>How can I achieve this only from the C API. </p>
  
  <p>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.</p>
  
  <p>doing something like this:</p>
  
  <pre><code>lua_pushnil(state_pointer);
  lua_setglobal(state_pointer, "os.execute");
  </code></pre>
  
  <p>won't help much because in the script the user can call os = require('os') and get all the functions back</p>
  
  <p>I am not allowed to disable the require function so this makes things harder.</p>
  
  <p>Any ideas?</p>
  
  <p>PS:More of a curiosity: if I do something like</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>luaL_openlibs(L); (this loads all the libraries)
  </code></pre>
  
  <p>would os = require('os') or io = require('io') still work?</p>
  
  <hr>
  
  <p>@Nicol Bolas don't know if i'm doing something wrong but os = require('os') &amp; require('io') just brings everything back. </p>
  
  <p>my code:</p>
  
  <pre><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");
  </code></pre>
  
  <p>In my script i just do a</p>
  
  <pre><code>os = require('os')
  io = require('io')
  </code></pre>
  
  <p>after this os functions and io functions all work. os.exit still closes my app and io.write works as usual</p>