I have the following lua script :
mydata={}
function update(val)
mydata["x"] = val
if (val == 10)
-- Call C-Api(1)
else
--Register callback with C when free or some event happens
register_callback(callme)
end
function callme()
end
Basically I would like to have two instances of this script running in my C program/process with out having to create a new LUA state per script. And I want to call the function update() with val = 10 from the one instance and call the function update() with val = 20 from another instance. From the second instance it registers a callback function and just waits to be called.
Basically the script file is kind of a RULE that i am trying to achieve. Several events on the system can trigger this rule or script file. I would like to process this rule as per the event that triggered it. There could be multiple events triggering this script to run at the same time. So I need to have multiple instances of this script running differentiated by the kind of event that triggered it.
To Summarize, I want each caller to have separate individual instance of mydata
I would like to achieve something like this. I read some where that we should be able to run multiple instances of a lua script with out having to create a new lua instance by loading a new environment before loading the script
But I am not able to find the exact details.
Could some body help ?
mydatato be shareable, then you want one instance. If you want to use the same global name but not be shared, create more than one Lua state. If you don't need it to be shareable, then just make it local. The actual problem you're trying to solve is very unclear.updatefunction multiple times that's a different question. If that is what you mean do you want themydatashared between callers (how do you define a caller)? Do you want individualmydatatables for each caller (again how do you define a caller)? Do your callers (whatever they are) need to share anything in the lua state? Because if not, and you want to thread the callers or anything then multiple lua states is what you want. You really need to clarify your question.