lua-users home
lua-l archive

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


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