I'm trying to setup a sandbox with support for only a limited number of functions. Prior to Lua 5.2, this could be accomplished by the setfenv function. In 5.2 and above, as this function is not available, I guess you have to do this differently. There are some examples to do this from Lua itself Sandboxing in Lua 5.2. Any sample code to do it from C with a simple sandbox that supports, for instance only the print function?
1
votes
1 Answers
0
votes
See luaB_loadfile and load_aux for how to set _ENV from C. The key point is to set the sandbox as the first upvalue of the Lua function when it is loaded, before it is run.