After that, I was toying with what I could do, and how. My initial attempt to expose objects to Lua was to use a getter function, so I could do something like [font="Lucida Console"]app = yckx.GetApp()[/font] in Lua. But it was a dirty hack and felt kludgy. I disliked writing it, much less using it. After some more Google-fu I found this mailing list thread, which solved the problem much more elegantly.
So, yay! I'm making what feels like real progress. But finding these two bits of information really tells me one thing: it's going to take a while to discover the ins-and-outs of SWIG.
I've just implemented my own solution for lua/c++ bindings based on top of Lunar.h, which I found extremely easy to use.
In my case, I've modified the Lunar template slightly to derive from and construct for my class factory template, so all my factory-ready classes get lua bindings for free.. I can bind at runtime, too.
Here's a snippet I use to expose singleton pointers to lua, so I can then call the c++ class methods from lua eg "MyClassName:MyMethod()" (this assumes that the methods have been exposed too of course)
What I found interesting is that we can just express some new methods of such a class in lua (eg "func MyClassName:NewMethod(args)" and they are instantly callable from C++ with no extra work required
[code]
void Declare_Class_LuaGlobal(lua_State* L,char* name)
{
// Create a Gobal Variable "Name = this object"
lua_settop(L, 0);
int A = Lunar<T>::push(L, this);
lua_pushlstring(L,name,lstrlenA(name));
lua_pushvalue(L, A);
lua_settable(L, LUA_GLOBALSINDEX);
}
[/code]