69 typedef struct { T *pT; } userdataType;
85 int (T::*
function) (lua_State *);
237 static void Register(lua_State * L,
const char *namespac =
"") {
239 if (strcmp(namespac,
"") != 0) {
240 lua_getglobal(L, namespac);
242 lua_setfield(L, -2, T::className);
246 lua_setglobal(L, T::className);
249 luaL_newmetatable(L, T::className);
250 int metatable = lua_gettop(L);
252 lua_pushstring(L,
"__gc");
254 lua_settable(L, metatable);
256 lua_pushstring(L,
"__index");
258 lua_settable(L, metatable);
260 lua_pushstring(L,
"__setindex");
262 lua_settable(L, metatable);
278 int newtable = lua_gettop(L);
280 lua_pushnumber(L, 0);
282 T **a = (T **) lua_newuserdata(L,
sizeof(T *));
288 int userdata = lua_gettop(L);
290 luaL_getmetatable(L, T::className);
292 lua_setmetatable(L, userdata);
294 lua_settable(L, newtable);
296 luaL_getmetatable(L, T::className);
297 lua_setmetatable(L, newtable);
299 luaL_getmetatable(L, T::className);
301 for (
int i = 0; T::Properties[i].name; i++) {
302 lua_pushstring(L, T::Properties[i].name);
303 lua_pushnumber(L, i);
309 for (
int i = 0; T::Functions[i].name; i++) {
310 lua_pushstring(L, T::Functions[i].name);
311 lua_pushnumber(L, i);
313 lua_settable(L, newtable);
332 int newtable = lua_gettop(L);
334 lua_pushnumber(L, 0);
336 T **a = (T **) lua_newuserdata(L,
sizeof(T *));
337 T *obj =
new T(L,
false);
338 obj->isExisting =
false;
341 int userdata = lua_gettop(L);
343 luaL_getmetatable(L, T::className);
345 lua_setmetatable(L, userdata);
347 lua_settable(L, newtable);
349 luaL_getmetatable(L, T::className);
350 lua_setmetatable(L, newtable);
352 luaL_getmetatable(L, T::className);
354 for (
int i = 0; T::Properties[i].name; i++) {
356 lua_pushstring(L, T::Properties[i].name);
357 lua_pushnumber(L, i);
363 for (
int i = 0; T::Functions[i].name; i++) {
364 lua_pushstring(L, T::Functions[i].name);
365 lua_pushnumber(L, i);
367 lua_settable(L, newtable);
388 int newtable = lua_gettop(L);
390 lua_pushnumber(L, 0);
392 T **a = (T **) lua_newuserdata(L,
sizeof(T *));
393 T *obj = existingobj;
394 obj->isExisting =
true;
397 int userdata = lua_gettop(L);
400 luaL_getmetatable(L, T::className);
402 lua_setmetatable(L, userdata);
404 lua_settable(L, newtable);
406 luaL_getmetatable(L, T::className);
407 lua_setmetatable(L, newtable);
409 luaL_getmetatable(L, T::className);
411 for (
int i = 0; T::Properties[i].name; i++) {
412 lua_pushstring(L, T::Properties[i].name);
413 lua_pushnumber(L, i);
419 for (
int i = 0; T::Functions[i].name; i++) {
420 lua_pushstring(L, T::Functions[i].name);
421 lua_pushnumber(L, i);
423 lua_settable(L, newtable);
439 lua_getmetatable(L, 1);
444 if (lua_isnumber(L, -1)) {
446 int _index = lua_tonumber(L, -1);
448 lua_pushnumber(L, 0);
452 static_cast < T ** >(lua_touserdata(L, -1));
458 int result = ((*obj)->*(T::Properties[_index].getter)) (L);
478 lua_getmetatable(L, 1);
483 if (lua_isnil(L, -1)) {
492 int _index = lua_tonumber(L, -1);
494 lua_pushnumber(L, 0);
498 static_cast < T ** >(lua_touserdata(L, -1));
504 return ((*obj)->*(T::Properties[_index].setter)) (L);
518 int i = (int) lua_tonumber(L, lua_upvalueindex(1));
520 lua_pushnumber(L, 0);
523 T **obj = static_cast < T ** >(lua_touserdata(L, -1));
527 return ((*obj)->*(T::Functions[i].function)) (L);
539 static_cast < T ** >(luaL_checkudata(L, -1, T::className));
541 if (!(*obj)->isExisting && !(*obj)->isPrecious)
543 cout <<
"Cleaning up a " << T::className <<
"." << endl;
603 #define DECLARE_SCRIPT_CLASS(ClassName) \
605 static const char className[]; \
606 static moLuna<ClassName>::PropertyType Properties[]; \
607 static moLuna<ClassName>::FunctionType Functions[];\
613 #define IMPLEMENT_SCRIPT_CLASS(ClassName) \
614 const char ClassName::className[] = #ClassName;
616 #define DEFINE_SCRIPT_CLASS_FUNCTIONS(ClassName) \
617 moLuna<ClassName>::FunctionType ClassName::Functions[] = {
619 #define SCRIPT_FUNCTION(ClassName, FunctionName) { #FunctionName, &ClassName::FunctionName }
621 #define END_SCRIPT_CLASS_FUNCTIONS };
624 #define DEFINE_SCRIPT_CLASS_PROPERTIES(ClassName) \
625 moLuna<ClassName>::PropertyType ClassName::Properties[] = {
627 #define SCRIPT_PROPERTY(ClassName, PropertyName, PropertyGetter, PropertySetter ) { #PropertyName, &ClassName::PropertyGetter, &ClassName::PropertySetter }
629 #define END_SCRIPT_CLASS_PROPERTIES };
631 #define REGISTER_CLASS(ClassName, LuaState) \
632 moLuna<ClassName>::Register(LuaState);
634 #define SCRIPT_CONSTRUCTOR_DECLARATION(ClassName) ClassName(lua_State* L);
635 #define SCRIPT_CONSTRUCTOR_IMPLEMENTATION(ClassName) ClassName::ClassName(lua_State* L)
637 #define SCRIPT_FUNCTION_DECLARATION(FunctionName) int FunctionName(lua_State* L);
638 #define SCRIPT_FUNCTION_IMPLEMENTATION(ClassName, FunctionName) int ClassName::FunctionName(lua_State* L)
int(T::* setter)(lua_State *)
static void Register(lua_State *L, const char *namespac="")
eso no esta en LunaFourCode
static int constructor(lua_State *L)
LunaFourCode.
static T * createFromExisting(lua_State *L, T *existingobj)
static int property_getter(lua_State *L)
static int gc_obj(lua_State *L)
static T * createNew(lua_State *L)
int(T::* getter)(lua_State *)
static int property_setter(lua_State *L)
static int function_dispatch(lua_State *L)