Archived

This topic is now archived and is closed to further replies.

Persistant Lua Scripts

This topic is 5305 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I''ve just started toying around with Lua recently. What I want to do is encapsulate a script file into a C++ class. That way I can store and execute scripts in an orderly manner. The problem that I ran into was that I have to call lua_load to load the file or buffer into the lua state. Basically I''m trying to figure out whether or not I have to reload the script every time I call it. Is there a way to load multiple scripts into a single lua state? Another thing, would it matter if I had multiple lua states? I know I can use concurrent functions to execute scripts simultaneously having a lua state in each script class would allow me to create scripts with various behaviors. Kory

Share this post


Link to post
Share on other sites
That''s what I''ve done in the class that I provide in this thread Thread. What I intend to do is have classes that are controlled by scripts to either inherit from that class or to contain any number of these classes.

What the class does is hold a script in a buffer. When it comes time to execute the script you simply hand the buffer to lua_dobuffer().

From what I can gather, and I haven''t been using Lua long, it is ok to have multiple lua_states.

Dave "Dak Lozar" Loeser

Share this post


Link to post
Share on other sites
as far as i understand it: yes

just make sure that your scripts contain functions, then load them and the functions (and the set variables) will be active until you lua_close() the state.
but keep in mind that they are only active in the state you loaded them but that seems to be a no-issue as you said you needed it for only one state...

Share this post


Link to post
Share on other sites