Skip to main content
GameDev.net gamedev.net
🔒 Locked

LUA: Have one VM reference data from another?

Started by Pickl3d Oct 7, 2008 at 9:04 AM 1 replies 1.2k views
Original Post
Pickl3d
Pickl3d
I'm having some fun with quite an old game that uses LUA to handle some of it's functionality and have managed to hook it (hack) and use utilise the data from from hook (by using a pointer to the VM, which works fine from the games thread..) However there is obviously problems running LUA from my "own Thread" (pointing to the existing VM in the game's thread). eg: Buggering up it's stack if it's currently processing LUA whilst my Thread hijacks the VM and does some processing during the other threads slice, ouch... So my question is: does anyone know if it's possible to somehow "reference" the other LUA VM (or indeed copy it's entire state) from my Thread without messing up it's stack while it's processing. Would be read only data anyway, i'm not modifying it so I can see where the spaceships are. I can insert a hook from "it's intended thread" which works ok, but then I slow down the game. So would be nice to use the VM from my Thread as the game does not have any critical sections / lock threading implemented (as it obviously didn't expect to be hijacked and it solely runs lua onframe event in one thread) :) Thanks for any suggestions, if it's possible.
dmail
dmail
To access the Lua state from two threads requires that you have control over the both and control the access to the state via a locking mechanism.
Quote:
Would be read only data anyway, i'm not modifying it so I can see where the spaceships are.
Yes but what if the other thread changes the data which you are trying to read, or even adjusts the state ie stack?
Before Phantom comes along and corrects you on the naming of "Lua"
Quote:
What's in a name?
"Lua" (pronounced LOO-ah) means "Moon" in Portuguese. As such, it is neither an acronym nor an abbreviation, but a noun. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!
Pickl3d
Pickl3d
Quote:

Yes but what if the other thread changes the data which you are trying to read, or even adjusts the state ie stack?
Before Phantom comes along and corrects you on the naming of "Lua"


Well exactly, that was my original question. I'm fully aware. Yet was wondering if perhaps there was a solution (outwith the having control over both (which I dont re: Hack)).

I guess i'll just stick to runnning it from the games thread (long jmp) and do it efficiently as possible.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.