Jump to content
  • Advertisement
Sign in to follow this  
Jesse Dager

Lua issues: script loading

This topic is 1481 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

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?

Share this post


Link to post
Share on other sites
Advertisement


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.

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!