🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Persistant Lua Scripts

Started by
1 comment, last by kspansel 21 years ago
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
"The pioneers of a warless world are the youth who refuse military service" - Albert Einstein
Advertisement
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
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
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...
http://mitglied.lycos.de/lousyphreak/

This topic is closed to new replies.

Advertisement