Advertisement

Lua issues: script loading

Started by July 03, 2014 12:19 AM
1 comment, last by vstrakh 10 years, 4 months ago

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?

I develop to expand the universe. "Live long and code strong!" - Delta_Echo (dream.in.code)


or am I just missing something HUGE with lua?
By "loading a script", do you mean sending a pile of text to the lua VM and asking it to execute it?

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.

Advertisement


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