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 had considered this but could not use statics and wanted to avoid
searching for that state done by the map. My C++ class is hidden behind
COM-like interface.

AB

>
> 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.
>
> --