How do I set, via the lua C API, the environment table for a chunk of lua code prior to running it?
snippet in lua

How do I set, via the lua C API, the environment table for a chunk of lua code prior to running it?

user2891

luaL_loadfile(L, "file.lua");       /* load and compile handler */
lua_getglobal(L, "my_environment"); /* push environment onto stack */
lua_setupvalue(L, -2, 1);           /* pop environment and assign to upvalue#1 */
/* any other setup needed */
lua_pcall(L, ...);                  /* call handler */