Serializable VMs
Hello. I'm searching for a scripting language for my game. My use case is that the player writes scripts to control units in the game. For this reason, several VM must coexist at the same time. Also, because I want to implement a save/load mechanism, the complete state of a VM must be serializable to disk. Third, I must be able to control the VM entirely, so the user can't write looping or evil scripts. That would be sandboxing, if i'm not mistaken. I have real problems with the serializable requeriment. The only language I found that can do that is Small, but even there is a hack metioned in the forums. I think my use case is not that strage, so I wonder if I'm googling for the worng terms. Thanks in advance, :D Bruno
I think most people would look perhaps to use events/callbacks, coroutines, or threads instead of running multiple copies of the virtual machine. Also, it might be more common to store all game state in objects so that you're serialising those objects (supported by most scripting languages) rather than the VM state (supported by few, if what you say is true).
First of all, thank you for your response.
The problem of using events is that the player has to write her programs differently. A program like:
loop:
goto capital
pickup wood
goto town
unload wood
becomes harder. Note that if I were writing the scripts myself, there wouldn't be a problem with that aprouch.
Corountines/threads, IIUC, don't modify the problem sustantially. I still have to serialize VMs, just only one now.
Another solution I think would work is to find an implementation of scheme that permitted serialization of a continuation. I haven't explored this much, because I couldn't find a ready-made solution and everytinh about lisp is alien to me.
The problem of using events is that the player has to write her programs differently. A program like:
loop:
goto capital
pickup wood
goto town
unload wood
becomes harder. Note that if I were writing the scripts myself, there wouldn't be a problem with that aprouch.
Corountines/threads, IIUC, don't modify the problem sustantially. I still have to serialize VMs, just only one now.
Another solution I think would work is to find an implementation of scheme that permitted serialization of a continuation. I haven't explored this much, because I couldn't find a ready-made solution and everytinh about lisp is alien to me.
This definitely sounds like a "roll your own" application
daerid@gmail.com
I think Lua is capable of doing all that.
First of all you can serialize arbitrary parts of the VM using the library "pluto".
Scripts like the one you gave as an example are also possible using coroutines, as Lua implements stacked coroutines. Stacked means, that execution can not only be yielded from the coroutine itself but also from functions called from the coroutine.
So the scripter would be able to write something like this (Lua-like pseudocode):
To make this work you have to implement all methods that take longer than a frame like this (Lua-like pseudocode):
And each frame every coroutine has to be resumed, of course.
First of all you can serialize arbitrary parts of the VM using the library "pluto".
Scripts like the one you gave as an example are also possible using coroutines, as Lua implements stacked coroutines. Stacked means, that execution can not only be yielded from the coroutine itself but also from functions called from the coroutine.
So the scripter would be able to write something like this (Lua-like pseudocode):
while(true) Worker:Goto(capital) Worker:PickUp(wood) Worker:Goto(town) Worker:Unload()end
To make this work you have to implement all methods that take longer than a frame like this (Lua-like pseudocode):
function Worker:Goto(goal) while not self:Reached(goal) self.Pos.X += self.Speed * LastFrameTime self.Pos.Y += self.Speed * LastFrameTime coroutine.yield() endend
And each frame every coroutine has to be resumed, of course.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement