Getting and setting values in a remote LUA environment?

Started by
3 comments, last by jdarling 18 years, 1 month ago
In my engine I'm using LUA for scripting, and I've run into a bit of a problem. What I have currently is a LUA instance for the Game, Each Level, and Each sprite type (not each sprite). Then Tables are used to track the sprite instances and setup the proper values for method calls. This all works fine and dandy until I have one sprite that needs to communicate back to another sprite, the game level, or the game script. Is their an easy way to use variables across LUA instances? Thanks, - Jeremy
Advertisement
Dont know if there is any easy way to communicate between lua states (I doubt there is..), but maybee you should consider just using one lua state for everything in your game?
----------Thale Cres
Quote:Original post by chot
Dont know if there is any easy way to communicate between lua states (I doubt there is..), but maybee you should consider just using one lua state for everything in your game?


I thought about doing that, but before I went through all the trouble I wanted to see if there was another way.

- Jeremy
You need to copy the data out of one of your lua_State:s and into the other, using C++ or whatever language you use.

Use deep-copy - you can't share Lua-objects between lua_State:s.

In my game I use a single lua_State for all gameplay. I use other lua_State:s for reading preferences and other files, though.


HTH


/Marcus
While its not ideal, I did find a semi solution:
I have a Message Stack per Lua instance that I can Push, Pop, Poke and Peek messages to and from. The stacks can manage tables, methods and variables. So simply pushing to a remote stack and then processing that stack works fairly well. Course now I have a bit more overhead, but its nothing noticeable :).

This topic is closed to new replies.

Advertisement