Jump to content

"Environment"


Anderl

Recommended Posts

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 by Guest
Link to comment
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...