Jump to content

  • Log In with Google      Sign In   
  • Create Account

Lua issues: script loading


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 sethhope   Members   -  Reputation: 420

Like
0Likes
Like

Posted 02 July 2014 - 06:19 PM

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)

Sponsor:

#2 Hodgman   Moderators   -  Reputation: 30351

Like
1Likes
Like

Posted 02 July 2014 - 09:39 PM


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.



#3 vstrakh   Members   -  Reputation: 399

Like
1Likes
Like

Posted 03 July 2014 - 05:04 AM


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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS