[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: How to register a pointer to an object as a global variable
- From: pixellent@...
- Date: Fri, 20 Dec 2002 13:21:04 -0500
I have my usual simple class:
namespace Mike
{
class baseObject
{
public:
baseObject();
virtual ~baseObject();
void SetAge(int age);
int GetAge();
int mAge;
};
}
I have the bindings created using ToLua. I create an instance of the object:
baseObject* bo = new baseObject();
bo->SetAge(10);
Now I want to set this variable as a global object available to all Lua scripts,
so I do:
lua_pushusertag(mLuaState, (void*)bo, LUA_ANYTAG);
lua_setglobal(mLuaState, "bo");
I want to access it in the script:
age = bo:GetAge()
Is this the right way to do this? I'm not having much success so far.
Many thanks
Mike