Andrew> setfenv doesn't exist in 5.2+; in current versions you use the
Andrew> environment parameter to load() instead.
I tried the "sandbox enviroment" method you propopsed. After some googling, I tried the following code (with call to "PushSandboxEnvironmentTable" inserted between the "luaL_loadbuffer" and the "lua_pcall" to set a local environment with only function "print" available.
But at execution with this code, lua is complaining that "print" does not exist.
Any idea of what is wrong with this approach ?
Regards,
Brice
static void PushSandboxEnvironmentTableEntry(lua_State* L , char* key , char* value) {
lua_pushstring(L, key);
lua_pushstring(L, value);
lua_settable(L, -3);
}
static int PushSandboxEnvironmentTable(lua_State* L)
{
lua_newtable(L);
PushSandboxEnvironmentTableEntry(L, "print", "print");
lua_setupvalue(L, -2, 1);
return LUA_OK;
}