Anderl Posted September 22, 2012 Share Posted September 22, 2012 (edited) Hey, I was doing some script that'll load Lua files and it's using loadstring but later I'll need to unload the code. I'd like to know if there is any way to save event handlers, timers, elements and everything that is stored in a Lua VM in a table using wrappers, but saving them by file. What I mean is, if is there a way to store the added handlers, timers, the created elements and everything that is loaded by loadstring by files when using wrappers. Here's example: The file to be loaded: function init() addEventHandler('blabla', root, trolol) end function trolol() --some gay code here end A part of the code of the loader: return _G[pSettings.supportedFormats[toCSTR(value.path):type()].fn](value.param or pSettings.supportedFormats[toCSTR(value.path):type()].defParams) -- this is where the loadstring is called And the wrappers: local sandBox = {} sandBox.events = {} _addEventHandler = addEventHandler function addEventHandler(...) sandBox.events[HERES_FILE] = {...} return _addEventHandler(...) end HERES_FILE should be read and should point to the file of the added handler. Is there any way to do this except putting file name and saving on table? It's not good this way because if I change file name or location I'll have to change everything. Also, for those of you which like to say things to increase post count, just don't comment please. Thank you. Edited September 23, 2012 by Guest Link to comment
arezu Posted September 22, 2012 Share Posted September 22, 2012 Do you mean if you can somehow get which "file" called the function? Link to comment
Anderl Posted September 22, 2012 Author Share Posted September 22, 2012 Do you mean if you can somehow get which "file" called the function? Like that but there's other way: create an environment and then unload the code from that environment. I'm just trying to do something with setfenv, but it's first time I mess with these type of functions. Any help? EDIT: I still could not do something like I need, it doesn't seem to work the way I thought it would be. Anyone could give a hand? Link to comment
Anderl Posted September 24, 2012 Author Share Posted September 24, 2012 Ok guys, with some qaisjp help and his example I was able to do something ( like his example ). It still needs wrappers, but it's much easier than what I was trying to do. Thanks for not helping, people Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now