I'm currently learning how to use the LUA C API and while I've had success binding functions between C/C++ and LUA, I have a few questions:
-
Is it a good idea to load multiple scripts into a single lua_State? Is there a way to close specific chunks? If a script is no longer in use how can I clear it from the lua_State while retaining everything else?
-
What is the best way use scripts that may use the same name for functions/global variables? If I load all of them the newer definitions override the older ones.
After reading online I think I need to separate each loaded chunk into different environments. The way I envision this working is each time a chunk is loaded I assign it a unique environment name, when I need to work with it it I just use that name to fetch the environment from the LUA_REGISTRYINDEX and perform the operation. So far I haven't figured out how to do this. There are examples online but they use LUA 5.1.
Aucun commentaire:
Enregistrer un commentaire