Saving threads for later use in lua 5.0

Started by
3 comments, last by evolutional 19 years, 7 months ago
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?
Advertisement
If I recall correctly, Sneftel was working on something like this called Pluto.
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).
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.
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]

This topic is closed to new replies.

Advertisement