Multiple Lua VM's?

Miscellaneous Forums/General Discussion/Multiple Lua VM's?

I originally planned to have just one Lua VM for my entire project, but I've been trying to write an AI framework this past few days and I've decided that a separate VM for AI will actually work better. This way I can dynamically run all the AI scripts for all the agents in the game, then when the game ends or you load a previous game, I can just kill the VM and start over again without having to reinitialize everything else. Just the AI.

So I spent a couple of days rewriting my scriptengine so that it supports multiple VM's, and that's all good. But now I'm having problems if I define the same function in both VM's. If I don't define the function in both VM's, then I get an error when I try to use it, so that's right. Evidently the right VM is being used. But if I define the function in both, some completely unrelated scripts in the other VM are not being run at all. This makes absolutely no sense to me as you can probably imagine.

So I'm just posting to see if there are any problems inherent with multiple VM's which I might not have considered? The only thing which has really crossed my mind so far is that the stack might be getting trashed somehow, but I can't see how one VM could possibly have any effect on the stack of another.

Shouldn't be a problem doing this, there are enough commercial examples that actually use multiple VMs to split things logically and seperate the stacks etc and reduce the potential for bugs this way. (and reduce the possibility from where they come when they are present)

Yeah, that's what I thought. Well I've realised now that the script that's refusing to run is throwing an error which does not exist. Furthermore, it's a script being run from disk, but it's erroring without a line number, which means it's the error from calling a function, not a script from disk. So evidently I'm trashing the stack somewhere. I sense this won't be fun to debug.

yeah especially with BMs debugging capabilities teamed up with this one ...
good luck thought, I'm sure you will succeed :)