OK, I've been driving myself crazy trying to figure out how to pass a pointer (from objects that I have created on the C++ side)
to functions in the Lua script. I know that everyone here will probably tell me to use luaBind or one of the other tools but I'd
prefer to figure this out on my own without using luaBind or similar.
A simple example might be the following:
//
// C++ class
//
class cGameObject
{
protected:
ULONG m_ObjectID;
public:
cGameObject() : m_ObjectID(0)
{
}
~cGameObject()
{
}
};
so, in game code, I might have a factory or some other mechanism that creates game objects, but here I just new the pointer:
...
cGameObject* pGO = new cGameObject();
now, I think that I have figured out how to create userdata that Lua will know about, like so:
cGameObject** ptr = (cGameObject**)lua_boxpointer(luaVM, pGO);
so lets say that I have a Lua script that will perform some operation on the cGameObject, in this example, set the object id:
function GameObject:SetObjectID()
self.m_ObjectID = NewObjectID() // NewObjectID() is an exposed function from C++
end
so, with all those things in place I now need to know how to be able to call the Lua function SetObjectID() from my C++ created object.
Any help is appreciated!