lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, Jun 13, 2002 at 02:13:27AM -0700, Alex Bilyk wrote:
> Has anybody done this without making any changes to original LUA code? Not a
> big deal just wondering:)

If you're using the STL in your code, then you could add the following...

class cLuaState {
.....
public:
  static cLuaState* GetStateFromLuaState( lua_State *L );
private:
  static std::map< lua_State*, cLuaState* > myStateMap;
};

Then manage creating/deleting entries in myStateMap in your constructor and
desstructors, and write a body for GetStateFromLuaState such that you can
have something like:

int myLuaFunction( lua_State *L ) {
  cLuaState* myStatePtr = cLuaState::GetStateFromLuaState( L );
  .....
}

I know this is terse, but I've not played with the STL in a while, so I
can't easily rattle off the incantations for managing the map :)

D.

-- 
Daniel Silverstone                               http://www.digital-scurf.org/
Hostmaster, Webmaster, and Chief Code Wibbler          Digital-Scurf Unlimited
GPG Public key available from keyring.debian.org               KeyId: 20687895
You will be a winner today.  Pick a fight with a four-year-old.