This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Lua VM State Saving
Started by chiloxsan, 13 September 2012 - 05:04 AMPosted 13 September 2012 - 07:04 AM
I often find my self spending too much time programming a save state system for my turtle programs so they can pick up where they left off without errors. My idea is that when a chunk that contains a computer unloads, it saves an image of the Lua VM memory to disk where it can be loaded back in when the chunk loads again. That way programs can pick up exactly where they left off without problems.
Posted 13 September 2012 - 07:12 AM
Already in process! :)/>/>
Posted 13 September 2012 - 08:34 AM
wow, great plan there. you can do the same for exit and reload but I doubt that is very safe. would make things much easier if turtles resumed
Posted 13 September 2012 - 01:49 PM
Even after server restarts? Because recreating a complete Lua state from scratch seems to be a really complex task. At least Garry should know how this works :)/>/> .Already in process! :P/>/>
Posted 13 September 2012 - 03:00 PM
Even after server restarts? Because recreating a complete Lua state from scratch seems to be a really complex task. At least Garry should know how this works :)/>/> .Already in process! :P/>/>
Yep, even after server restarts - and it is no more complex than setting up an entire new Lua state. We will be delegating much of the work to the Pluto Lua binary.
Posted 13 September 2012 - 03:11 PM
will the computer/turtle be aware that the server closed and restarted?
Posted 13 September 2012 - 03:26 PM
will the computer/turtle be aware that the server closed and restarted?
No - but it won't need to know.
Posted 14 September 2012 - 08:29 AM
True, just wondering. it could possibly be used so I was curious. could you not just queue an event on the turtles?
Posted 15 September 2012 - 07:26 AM
You'd be crossing over the lines of the simulation. Objects within a proper simulation should not know that the simulation has been paused, nor should they need to.True, just wondering. it could possibly be used so I was curious. could you not just queue an event on the turtles?
Posted 15 September 2012 - 08:45 AM
You'd be crossing over the lines of the simulation. Objects within a proper simulation should not know that the simulation has been paused, nor should they need to.True, just wondering. it could possibly be used so I was curious. could you not just queue an event on the turtles?
you are right, it would just add an additional handle to use in programs if it is needed. but I understand, its all good :)/>/>
Posted 15 September 2012 - 08:39 PM
You could probably figure out that you have been paused using os.time(). If time changed too fast, you were paused.
Posted 15 September 2012 - 09:10 PM
There should be no reason that you'd need to know if you were unloaded, if the state gets resumed correctly.
Posted 15 September 2012 - 09:17 PM
Hrm. Just a thought, but what about active file handles?
Posted 15 September 2012 - 09:22 PM
There should be no reason that you'd need to know if you were unloaded, if the state gets resumed correctly.
True, but sometimes it can be useful to know that turle left unloaded chunks.
For example, currently we use this "feature" as safeguard. If there is an error in program and turtle randomly wanders off, it will stop as soon as it leaves loaded chunks. But with new version, it would keep going if you load chunks while searching for it.
Posted 15 September 2012 - 09:23 PM
Hrm. Just a thought, but what about active file handles?
Since we already abstract the filesystem accesses through our own objects, it will be trivial to remake the file handles.
Posted 15 September 2012 - 09:24 PM
There should be no reason that you'd need to know if you were unloaded, if the state gets resumed correctly.
True, but sometimes it can be useful to know that turle left unloaded chunks.
For example, currently we use this "feature" as safeguard. If there is an error in program and turtle randomly wanders off, it will stop as soon as it leaves loaded chunks. But with new version, it would keep going if you load chunks while searching for it.
But it won't ever leave loaded chunks - it isn't capable of moving into an unloaded chunk.
You should just make sure that your turtle doesn't move infinitely if you want to prevent that :)/>/>
Posted 16 September 2012 - 07:10 AM
my concern is that you could possibly fill up the servers memory by declaring tons of tables etc until it uses up all of the memory, the server crashes and normally if you reload it you are fine… not so if it automatically resumes where it left off with all of that data
Posted 16 September 2012 - 07:20 AM
my concern is that you could possibly fill up the servers memory by declaring tons of tables etc until it uses up all of the memory, the server crashes and normally if you reload it you are fine… not so if it automatically resumes where it left off with all of that data
Doesn't each ingame lua vm have a set memory allocation? If it doesn't it'll be a nice limitation to work with in a future version.
Posted 16 September 2012 - 07:56 AM
not as far as I can see, in SSP I accidentally made an empty while true loop and my entire PC almost froze up, you could just start that on a server and it would be incredibly hard to solve
Posted 16 September 2012 - 08:30 AM
not as far as I can see, in SSP I accidentally made an empty while true loop and my entire PC almost froze up, you could just start that on a server and it would be incredibly hard to solve
Since 1.4 even a while true do end loop is protected against. Besides that has nothing to do with memory.
Posted 16 September 2012 - 08:42 AM
Oh awesome :)/>/> I'm on 1.33 so I can't complain.
I gotta say you devs fix things before we know they are broken yet lol, good job there
I gotta say you devs fix things before we know they are broken yet lol, good job there
Posted 16 September 2012 - 12:51 PM
That's what good developers always do.