I could post a large number of details on how to facilitate visualization, and how to do inheritance, etc. - and this will require a change if you want to set more than one T (I think the most common solution is a simple transaction struct { std::auto_ptr<void>, int type } ). But this should be the starting point if you do not understand anything in the process.
Basically, firstly, we ask Lua to allocate some space (userdata) and then put T. into it. When CallSomeFuncOnT is called, we first ask if we have a table (many Lua classes are based on tables, because they support object orientation , meta tags, etc.) And they get userdata data, which we then convert to a pointer to our object, and then convert to a link. Remember that lua_touserdata gives you a void *, so you better be sure of the other end. Then we call somefunc and return. In Main, we simply register functions as global.
Now, in Lua, when you call CreateInstanceOfT, it effectively just calls the T constructor, transparent to the Lua user. Then we drop it into a table that is easier for Lua newbies to call SomeFunc, passing that table to it.
Puppy
source share