So I began implementing Lua into my 2D game engine and realized that it becomes increasingly difficult to run a script every update and a script every render while carrying over globals and not re-loading the script every time. What I mean by that is, I either have to load the script on EVERY update cycle and EVERY render cycle, OR I don't carry globals over by creating separate lua_State s. Any ideas, or am I just missing something HUGE with lua?
Lua issues: script loading
I develop to expand the universe.
"Live long and code strong!" - Delta_Echo (dream.in.code)
By "loading a script", do you mean sending a pile of text to the lua VM and asking it to execute it?
or am I just missing something HUGE with lua?
Imagine if in C, you decided to run an exe file every single Update/Render, rather than just calling a function.
You can do that in Lua - load the script once (just like we run an exe file once), and then call your Lua functions (from C) every time you want to update/render.
. 22 Racing Series .
call your Lua functions (from C) every time you want to update/render.
I'd add one note about performance.
PIL book shows simple example using lua_getglobal(). It's quite costly due to lua string construction from passed C string.
It's few times cheaper to store required function in registry, and later retrieving that function by integer id, obtained during function registration.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement