The interface for my game engine is built using a markup language and Lua, similar to HTML and javascript. As such, visual elements will have handlers for UI events such as a mouse move or click, and each time a handler is to be run, the engine will check if it is compiled yet and if not will compile it via luaL_loadstring
. Handers can be shared either by element duplication or assignment (this.onclick = that.onclick
).
How do I set the environment of a chunk of lua code before running it? The idea is to make element- and event-specific data available to the chunk, and also to link to the environment of the parent UI element. Lua 5.2 changes removed lua_setfenv
, so I am not sure how to accomplish this. The function lua_load
allows specifying an environment, but seems to only be used for loading code and not running it.