Jump to content
  • Advertisement
Sign in to follow this  
JHL

Saving threads for later use in lua 5.0

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

I'm working on a level scripting for my engine, the way I'm working it is to define a table of functions in a script file then the engine traverses this table runing each function the reasons for this ia a) each function can disable its self by setting its own table entry to nil and b) each function can be a coroutine the coroutine part is where I'm having trouble each function is run in its own thread and if that function 'waits' then I need to save that thread but whats the best way to save an arbitrary number of threads?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
I'm working on a level scripting for my engine, the way I'm working it is to define a table of functions in a script file then the engine traverses this table runing each function the reasons for this ia a) each function can disable its self by setting its own table entry to nil and b) each function can be a coroutine


If you do it like this, you may want to have the engine remove the functions, depending on their return values. This way you can add the same function multiple times in the table, or you can have multiple coroutines that use the same function.

Quote:
the coroutine part is where I'm having trouble each function is run in its own thread and if that function 'waits' then I need to save that thread but whats the best way to save an arbitrary number of threads?


The coroutine itself _saves_ it's own thread. That's what coroutines do, they're objects that save a point in the execution of a function and allow you to resume that execution from that exact point. So you add the coroutine to the table, and have the engine call it, and then if the coroutine signals it finished it's computation remove it from the table.

table.insert and table.remove are all you need.


Quote:
If I recall correctly, Sneftel was working on something like this called Pluto.


Sneftel's project saves any Lua data to a file (including coroutines and closures and functions).

Share this post


Link to post
Share on other sites
Darn you guys.... I'm too late to plug my own project! [lol]

Anyway, yeah, check out Pluto to see if it's what you want. I'm assuming that by "save" you literally mean saving the game-state, to restore later. If you need something else, try describing it more clearly.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Darn you guys.... I'm too late to plug my own project! [lol]


Surely it says more if other people are plugging it for you [wink]

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!