Sign in to follow this  
jdarling

Getting and setting values in a remote LUA environment?

Recommended Posts

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 :).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this