// lua_tinker.h // // LuaTinker - Simple and light C++ wrapper for Lua. // // Copyright (c) 2005-2007 Kwon-il Lee (zupet@hitel.net) // // please check Licence.txt file for licence and legal issues. #if !defined(_LUA_TINKER_H_) #define _LUA_TINKER_H_ #include #include namespace lua_tinker { // init LuaTinker void init(lua_State *L); void init_s64(lua_State *L); void init_u64(lua_State *L); // excution int dofile(lua_State *L, const char *filename, std::string* errmsg = NULL); int dostring(lua_State *L, const char* buff, std::string* errmsg = NULL); int dobuffer(lua_State *L, const char* buff, size_t sz, std::string* errmsg = NULL); // debug helpers void enum_stack(lua_State *L); int on_error(lua_State *L); void print_error(lua_State *L, const char* fmt, ...); // dynamic type extention struct lua_value { virtual void to_lua(lua_State *L) = 0; }; // type trait template struct class_name; struct table; template struct if_ {}; template struct if_ { typedef A type; }; template struct if_ { typedef B type; }; template struct is_ptr { static const bool value = false; }; template struct is_ptr { static const bool value = true; }; template struct is_ref { static const bool value = false; }; template struct is_ref { static const bool value = true; }; template struct remove_const { typedef A type; }; template struct remove_const { typedef A type; }; template struct base_type { typedef A type; }; template struct base_type { typedef A type; }; template struct base_type { typedef A type; }; template struct class_type { typedef typename remove_const::type>::type type; }; ///////////////////////////////// enum { no = 1, yes = 2 }; typedef char (& no_type )[no]; typedef char (& yes_type)[yes]; struct int_conv_type { int_conv_type(int); }; no_type int_conv_tester (...); yes_type int_conv_tester (int_conv_type); no_type vfnd_ptr_tester (const volatile char *); no_type vfnd_ptr_tester (const volatile short *); no_type vfnd_ptr_tester (const volatile int *); no_type vfnd_ptr_tester (const volatile long *); no_type vfnd_ptr_tester (const volatile double *); no_type vfnd_ptr_tester (const volatile float *); no_type vfnd_ptr_tester (const volatile bool *); yes_type vfnd_ptr_tester (const volatile void *); template T* add_ptr(T&); template struct bool_to_yesno { typedef no_type type; }; template <> struct bool_to_yesno { typedef yes_type type; }; template struct is_enum { static T arg; static const bool value = ( (sizeof(int_conv_tester(arg)) == sizeof(yes_type)) && (sizeof(vfnd_ptr_tester(add_ptr(arg))) == sizeof(yes_type)) ); }; ///////////////////////////////// // from lua template struct void2val { static T invoke(void* input){ return *(T*)input; } }; template struct void2ptr { static T* invoke(void* input){ return (T*)input; } }; template struct void2ref { static T& invoke(void* input){ return *(T*)input; } }; template struct void2type { static T invoke(void* ptr) { return if_::value ,void2ptr::type> ,if_::value ,void2ref::type> ,void2val::type> >::type >::type::invoke(ptr); } }; template struct user2type { static T invoke(lua_State *L, int index) { return void2type::invoke(lua_touserdata(L, index)); } }; template struct lua2enum { static T invoke(lua_State *L, int index) { return (T)(int)lua_tonumber(L, index); } }; template struct lua2object { static T invoke(lua_State *L, int index) { if(!lua_isuserdata(L,index)) { lua_pushstring(L, "no class at first argument. (forgot ':' expression ?)"); lua_error(L); } return void2type::invoke(user2type::invoke(L,index)->m_p); } }; template T lua2type(lua_State *L, int index) { return if_::value ,lua2enum ,lua2object >::type::invoke(L, index); } struct user { user(void* p) : m_p(p) {} virtual ~user() {} void* m_p; }; template struct val2user : user { val2user() : user(new T) {} template val2user(T1 t1) : user(new T(t1)) {} template val2user(T1 t1, T2 t2) : user(new T(t1, t2)) {} template val2user(T1 t1, T2 t2, T3 t3) : user(new T(t1, t2, t3)) {} ~val2user() { delete ((T*)m_p); } }; template struct ptr2user : user { ptr2user(T* t) : user((void*)t) {} }; template struct ref2user : user { ref2user(T& t) : user(&t) {} }; // to lua template struct val2lua { static void invoke(lua_State *L, T& input){ new(lua_newuserdata(L, sizeof(val2user))) val2user(input); } }; template struct ptr2lua { static void invoke(lua_State *L, T* input){ if(input) new(lua_newuserdata(L, sizeof(ptr2user))) ptr2user(input); else lua_pushnil(L); } }; template struct ref2lua { static void invoke(lua_State *L, T& input){ new(lua_newuserdata(L, sizeof(ref2user))) ref2user(input); } }; template struct enum2lua { static void invoke(lua_State *L, T val) { lua_pushnumber(L, (int)val); } }; template struct object2lua { static void invoke(lua_State *L, T val) { if_::value ,ptr2lua::type> ,if_::value ,ref2lua::type> ,val2lua::type> >::type >::type::invoke(L, val); meta_push(L, class_name::type>::name()); lua_setmetatable(L, -2); } }; template void type2lua(lua_State *L, T val) { if_::value ,enum2lua ,object2lua >::type::invoke(L, val); } // get value from cclosure template T upvalue_(lua_State *L) { return user2type::invoke(L, lua_upvalueindex(1)); } // read a value from lua stack template T read(lua_State *L, int index) { return lua2type(L, index); } template<> char* read(lua_State *L, int index); template<> const char* read(lua_State *L, int index); template<> char read(lua_State *L, int index); template<> unsigned char read(lua_State *L, int index); template<> short read(lua_State *L, int index); template<> unsigned short read(lua_State *L, int index); template<> long read(lua_State *L, int index); template<> unsigned long read(lua_State *L, int index); template<> int read(lua_State *L, int index); template<> unsigned int read(lua_State *L, int index); template<> float read(lua_State *L, int index); template<> double read(lua_State *L, int index); template<> bool read(lua_State *L, int index); template<> void read(lua_State *L, int index); template<> __int64 read(lua_State *L, int index); template<> unsigned __int64 read(lua_State *L, int index); template<> table read(lua_State *L, int index); // push a value to lua stack template void push(lua_State *L, T ret) { type2lua(L, ret); } template<> void push(lua_State *L, char ret); template<> void push(lua_State *L, unsigned char ret); template<> void push(lua_State *L, short ret); template<> void push(lua_State *L, unsigned short ret); template<> void push(lua_State *L, long ret); template<> void push(lua_State *L, unsigned long ret); template<> void push(lua_State *L, int ret); template<> void push(lua_State *L, unsigned int ret); template<> void push(lua_State *L, float ret); template<> void push(lua_State *L, double ret); template<> void push(lua_State *L, char* ret); template<> void push(lua_State *L, const char* ret); template<> void push(lua_State *L, bool ret); template<> void push(lua_State *L, lua_value* ret); template<> void push(lua_State *L, __int64 ret); template<> void push(lua_State *L, unsigned __int64 ret); template<> void push(lua_State *L, table ret); // pop a value from lua stack template T pop(lua_State *L) { T t = read(L, -1); lua_pop(L, 1); return t; } template<> void pop(lua_State *L); template<> table pop(lua_State *L); // functor // ÇöÀç´Â ÀÎÀÚ ÃÖ´ë 20 °³ÀÎ ÇÔ¼ö±îÁö¸¸ °¡´ÉÇÑ °Í¿¡ À¯ÀÇ (2011-08-18) - verygoodd21 // 20°³ template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17),read(L,18),read(L,19),read(L,20))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17),read(L,18),read(L,19),read(L,20)); return 0; } }; // 19°³ template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17),read(L,18),read(L,19))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17),read(L,18),read(L,19)); return 0; } }; // 18°³ template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17),read(L,18))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17),read(L,18)); return 0; } }; // 17°³ template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17)); return 0; } }; // 16°³ template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13),read(L,14),read(L,15),read(L,16))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13),read(L,14),read(L,15),read(L,16)); return 0; } }; // 15°³ template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13),read(L,14),read(L,15))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13),read(L,14),read(L,15)); return 0; } }; // 14°³ template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13),read(L,14))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13),read(L,14)); return 0; } }; // 13°³ template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12),read(L,13)); return 0; } }; // 12°³ template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11),read(L,12)); return 0; } }; // 11°³ template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10) ,read(L,11)); return 0; } }; // 10°³ template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10)); return 0; } }; // 9°³ template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9)); return 0; } }; // 8°³ template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8)); return 0; } }; template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7)); return 0; } }; template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5),read(L,6)); return 0; } }; template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4),read(L,5)); return 0; } }; template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3),read(L,4)); return 0; } }; template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2),read(L,3))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2),read(L,3)); return 0; } }; template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1),read(L,2))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1),read(L,2)); return 0; } }; template struct functor { template static int invoke(lua_State *L) { push(L,upvalue_(L)(read(L,1))); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(read(L,1)); return 0; } }; template<> struct functor<> { template static int invoke(lua_State *L) { push(L,upvalue_(L)()); return 1; } template<> static int invoke(lua_State *L) { upvalue_(L)(); return 0; } }; // push_functor template void push_functor(lua_State *L, RVal (*func)()) { lua_pushcclosure(L, functor<>::invoke, 1); } template void push_functor(lua_State *L, RVal (*func)(T1)) { lua_pushcclosure(L, functor::invoke, 1); } template void push_functor(lua_State *L, RVal (*func)(T1,T2)) { lua_pushcclosure(L, functor::invoke, 1); } template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3)) { lua_pushcclosure(L, functor::invoke, 1); } template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4)) { lua_pushcclosure(L, functor::invoke, 1); } template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5)) { lua_pushcclosure(L, functor::invoke, 1); } template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5,T6)) { lua_pushcclosure(L, functor::invoke, 1); } template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5,T6,T7)) { lua_pushcclosure(L, functor::invoke, 1); } // 8°³ template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5,T6,T7,T8)) { lua_pushcclosure(L, functor::invoke, 1); } // 9°³ template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9)) { lua_pushcclosure(L, functor::invoke, 1); } // 10°³ template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10)) { lua_pushcclosure(L, functor::invoke, 1); } // 11°³ template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11)) { lua_pushcclosure(L, functor::invoke, 1); } // 12°³ template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12)) { lua_pushcclosure(L, functor::invoke, 1); } // 13°³ template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13)) { lua_pushcclosure(L, functor::invoke, 1); } // 14°³ template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14)) { lua_pushcclosure(L, functor::invoke, 1); } // 15°³ template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15)) { lua_pushcclosure(L, functor::invoke, 1); } // 16°³ template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16)) { lua_pushcclosure(L, functor::invoke, 1); } // 17°³ template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17)) { lua_pushcclosure(L, functor::invoke, 1); } // 18°³ template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18)) { lua_pushcclosure(L, functor::invoke, 1); } // 19°³ template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19)) { lua_pushcclosure(L, functor::invoke, 1); } // 20°³ template void push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20)) { lua_pushcclosure(L, functor::invoke, 1); } // member variable struct var_base { virtual void get(lua_State *L) = 0; virtual void set(lua_State *L) = 0; }; template struct mem_var : var_base { V T::*_var; mem_var(V T::*val) : _var(val) {} void get(lua_State *L) { push(L, read(L,1)->*(_var)); } void set(lua_State *L) { read(L,1)->*(_var) = read(L, 3); } }; // member function // 20°³ template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17),read(L,18),read(L,18),read(L,20),read(L,21))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17),read(L,18),read(L,18),read(L,20),read(L,21)); return 0; } }; // 19°³ template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17),read(L,18),read(L,19),read(L,20))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17),read(L,18),read(L,19),read(L,20)); return 0; } }; // 18°³ template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17),read(L,18),read(L,19))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17),read(L,18),read(L,19)); return 0; } }; // 17°³ template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17),read(L,18))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17),read(L,18)); return 0; } }; // 16°³ template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14),read(L,15),read(L,16),read(L,17)); return 0; } }; // 15°³ template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14),read(L,15),read(L,16))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14),read(L,15),read(L,16)); return 0; } }; // 14°³ template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14),read(L,15))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14),read(L,15)); return 0; } }; // 13°³ template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13),read(L,14)); return 0; } }; // 12°³ template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12),read(L,13)); return 0; } }; // 11°³ template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11) ,read(L,12)); return 0; } }; // 10°³ template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10),read(L,11)); return 0; } }; // 9°³ template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9),read(L,10)); return 0; } }; // 8°³ template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8),read(L,9)); return 0; } }; template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8)));; return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7),read(L,8)); return 0; } }; template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7)));; return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6),read(L,7)); return 0; } }; template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6)));; return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5),read(L,6)); return 0; } }; template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4),read(L,5)); return 0; } }; template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3),read(L,4)); return 0; } }; template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2),read(L,3))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2),read(L,3)); return 0; } }; template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))(read(L,2))); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(read(L,2)); return 0; } }; template struct mem_functor { template static int invoke(lua_State *L) { push(L,(read(L,1)->*upvalue_(L))()); return 1; } template<> static int invoke(lua_State *L) { (read(L,1)->*upvalue_(L))(); return 0; } }; // push_functor template void push_functor(lua_State *L, RVal (T::*func)()) { lua_pushcclosure(L, mem_functor::invoke, 1); } template void push_functor(lua_State *L, RVal (T::*func)() const) { lua_pushcclosure(L, mem_functor::invoke, 1); } template void push_functor(lua_State *L, RVal (T::*func)(T1)) { lua_pushcclosure(L, mem_functor::invoke, 1); } template void push_functor(lua_State *L, RVal (T::*func)(T1) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } template void push_functor(lua_State *L, RVal (T::*func)(T1,T2)) { lua_pushcclosure(L, mem_functor::invoke, 1); } template void push_functor(lua_State *L, RVal (T::*func)(T1,T2) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3)) { lua_pushcclosure(L, mem_functor::invoke, 1); } template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4)) { lua_pushcclosure(L, mem_functor::invoke, 1); } template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5)) { lua_pushcclosure(L, mem_functor::invoke, 1); } template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5,T6) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5,T6,T7) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } // 8°³ template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5,T6,T7,T8) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } // 9°³ template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } // 10°³ template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } // 11°³ template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } // 12°³ template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } // 13°³ template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } // 14°³ template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } // 15°³ template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } // 16°³ template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } // 17°³ template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } // 18°³ template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } // 19°³ template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } // 20°³ template void push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20) const) { lua_pushcclosure(L, mem_functor::invoke, 1); } // constructor template struct constructor {}; template struct constructor { template static void invoke(lua_State *L) { new(lua_newuserdata(L, sizeof(val2user))) val2user(read(L,2),read(L,3),read(L,4)); } }; template struct constructor { template static void invoke(lua_State *L) { new(lua_newuserdata(L, sizeof(val2user))) val2user(read(L,2),read(L,3)); } }; template struct constructor { template static void invoke(lua_State *L) { new(lua_newuserdata(L, sizeof(val2user))) val2user(read(L,2)); } }; template<> struct constructor { template static void invoke(lua_State *L) { new(lua_newuserdata(L, sizeof(val2user))) val2user(); } }; template struct creator { template static int invoke(lua_State *L) { CONSTRUCTOR::invoke(L); meta_push(L, class_name::type>::name()); lua_setmetatable(L, -2); return 1; } }; // destroyer template int destroyer(lua_State *L) { ((user*)lua_touserdata(L, 1))->~user(); return 0; } // global function template void def(lua_State* L, const char* name, F func) { lua_pushstring(L, name); lua_pushlightuserdata(L, func); push_functor(L, func); lua_settable(L, LUA_GLOBALSINDEX); } // global variable template void set(lua_State* L, const char* name, T object) { lua_pushstring(L, name); push(L, object); lua_settable(L, LUA_GLOBALSINDEX); } template T get(lua_State* L, const char* name) { lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); return pop(L); } template void decl(lua_State* L, const char* name, T object) { set(L, name, object); } // call template RVal call(lua_State* L, const char* name) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { if(lua_pcall(L, 0, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } template RVal call(lua_State* L, const char* name, T1 arg) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg); if(lua_pcall(L, 1, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); if(lua_pcall(L, 2, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); if(lua_pcall(L, 3, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 4°³, template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); if(lua_pcall(L, 4, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 5°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); if(lua_pcall(L, 5, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 6°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); push(L, arg6); if(lua_pcall(L, 6, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 7°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); push(L, arg6); push(L, arg7); if(lua_pcall(L, 7, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 8°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); push(L, arg6); push(L, arg7); push(L, arg8); if(lua_pcall(L, 8, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 9°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); push(L, arg6); push(L, arg7); push(L, arg8); push(L, arg9); if(lua_pcall(L, 9, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 10°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); push(L, arg6); push(L, arg7); push(L, arg8); push(L, arg9); push(L, arg10); if(lua_pcall(L, 10, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 11°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10 , T11 arg11) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); push(L, arg6); push(L, arg7); push(L, arg8); push(L, arg9); push(L, arg10); push(L, arg11); if(lua_pcall(L, 11, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 12°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10 , T11 arg11, T11 arg12) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); push(L, arg6); push(L, arg7); push(L, arg8); push(L, arg9); push(L, arg10); push(L, arg11); push(L, arg12); if(lua_pcall(L, 12, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 13°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10 , T11 arg11, T11 arg12, T11 arg13) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); push(L, arg6); push(L, arg7); push(L, arg8); push(L, arg9); push(L, arg10); push(L, arg11); push(L, arg12); push(L, arg13); if(lua_pcall(L, 13, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 14°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10 , T11 arg11, T11 arg12, T11 arg13, T11 arg14) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); push(L, arg6); push(L, arg7); push(L, arg8); push(L, arg9); push(L, arg10); push(L, arg11); push(L, arg12); push(L, arg13); push(L, arg14); if(lua_pcall(L, 14, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 15°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10 , T11 arg11, T11 arg12, T11 arg13, T11 arg14, T11 arg15) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); push(L, arg6); push(L, arg7); push(L, arg8); push(L, arg9); push(L, arg10); push(L, arg11); push(L, arg12); push(L, arg13); push(L, arg14); push(L, arg15); if(lua_pcall(L, 15, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 16°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10 , T11 arg11, T11 arg12, T11 arg13, T11 arg14, T11 arg15, T11 arg16) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); push(L, arg6); push(L, arg7); push(L, arg8); push(L, arg9); push(L, arg10); push(L, arg11); push(L, arg12); push(L, arg13); push(L, arg14); push(L, arg15); push(L, arg16); if(lua_pcall(L, 16, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 17°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10 , T11 arg11, T11 arg12, T11 arg13, T11 arg14, T11 arg15, T11 arg16, T11 arg17) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); push(L, arg6); push(L, arg7); push(L, arg8); push(L, arg9); push(L, arg10); push(L, arg11); push(L, arg12); push(L, arg13); push(L, arg14); push(L, arg15); push(L, arg16); push(L, arg17); if(lua_pcall(L, 17, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 18°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10 , T11 arg11, T11 arg12, T11 arg13, T11 arg14, T11 arg15, T11 arg16, T11 arg17, T11 arg18) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); push(L, arg6); push(L, arg7); push(L, arg8); push(L, arg9); push(L, arg10); push(L, arg11); push(L, arg12); push(L, arg13); push(L, arg14); push(L, arg15); push(L, arg16); push(L, arg17); push(L, arg18); if(lua_pcall(L, 18, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 19°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10 , T11 arg11, T11 arg12, T11 arg13, T11 arg14, T11 arg15, T11 arg16, T11 arg17, T11 arg18, T11 arg19) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); push(L, arg6); push(L, arg7); push(L, arg8); push(L, arg9); push(L, arg10); push(L, arg11); push(L, arg12); push(L, arg13); push(L, arg14); push(L, arg15); push(L, arg16); push(L, arg17); push(L, arg18); push(L, arg19); if(lua_pcall(L, 19, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // ÆÄ¶ó¸ÞŸ 20°³ template RVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10 , T11 arg11, T11 arg12, T11 arg13, T11 arg14, T11 arg15, T11 arg16, T11 arg17, T11 arg18, T11 arg19, T11 arg20) { lua_pushcclosure(L, on_error, 0); int errfunc = lua_gettop(L); lua_pushstring(L, name); lua_gettable(L, LUA_GLOBALSINDEX); if(lua_isfunction(L,-1)) { push(L, arg1); push(L, arg2); push(L, arg3); push(L, arg4); push(L, arg5); push(L, arg6); push(L, arg7); push(L, arg8); push(L, arg9); push(L, arg10); push(L, arg11); push(L, arg12); push(L, arg13); push(L, arg14); push(L, arg15); push(L, arg16); push(L, arg17); push(L, arg18); push(L, arg19); push(L, arg20); if(lua_pcall(L, 20, 1, errfunc) != 0) { lua_pop(L, 1); } } else { print_error(L, "lua_tinker::call() attempt to call global `%s' (not a function)", name); } lua_remove(L, -2); return pop(L); } // class helper int meta_get(lua_State *L); int meta_set(lua_State *L); void meta_push(lua_State *L, const char* name); // class init template void class_add(lua_State* L, const char* name) { class_name::name(name); lua_pushstring(L, name); lua_newtable(L); lua_pushstring(L, "__name"); lua_pushstring(L, name); lua_rawset(L, -3); lua_pushstring(L, "__index"); lua_pushcclosure(L, meta_get, 0); lua_rawset(L, -3); lua_pushstring(L, "__newindex"); lua_pushcclosure(L, meta_set, 0); lua_rawset(L, -3); lua_pushstring(L, "__gc"); lua_pushcclosure(L, destroyer, 0); lua_rawset(L, -3); lua_settable(L, LUA_GLOBALSINDEX); } // Tinker Class Inheritence template void class_inh(lua_State* L) { meta_push(L, class_name::name()); if(lua_istable(L, -1)) { lua_pushstring(L, "__parent"); meta_push(L, class_name

::name()); lua_rawset(L, -3); } lua_pop(L, 1); } // Tinker Class Constructor template void class_con(lua_State* L, CONSTRUCTOR) { meta_push(L, class_name::name()); if(lua_istable(L, -1)) { lua_newtable(L); lua_pushstring(L, "__call"); lua_pushcclosure(L, creator::invoke, 0); lua_rawset(L, -3); lua_setmetatable(L, -2); } lua_pop(L, 1); } // Tinker Class Functions template void class_def(lua_State* L, const char* name, F func) { meta_push(L, class_name::name()); if(lua_istable(L, -1)) { lua_pushstring(L, name); new(lua_newuserdata(L,sizeof(F))) F(func); push_functor(L, func); lua_rawset(L, -3); } lua_pop(L, 1); } // Tinker Class Variables template void class_mem(lua_State* L, const char* name, VAR BASE::*val) { meta_push(L, class_name::name()); if(lua_istable(L, -1)) { lua_pushstring(L, name); new(lua_newuserdata(L,sizeof(mem_var))) mem_var(val); lua_rawset(L, -3); } lua_pop(L, 1); } template struct class_name { // global name static const char* name(const char* name = NULL) { static char temp[256] = ""; if(name) strcpy_s(temp, sizeof(temp), name); return temp; } }; // Table Object on Stack struct table_obj { table_obj(lua_State* L, int index); ~table_obj(); void inc_ref(); void dec_ref(); bool validate(); template void set(const char* name, T object) { if(validate()) { lua_pushstring(m_L, name); push(m_L, object); lua_settable(m_L, m_index); } } template T get(const char* name) { if(validate()) { lua_pushstring(m_L, name); lua_gettable(m_L, m_index); } else { lua_pushnil(m_L); } return pop(m_L); } template void set( int idx, T object) { if(validate()) { lua_pushnumber(m_L, idx); push(m_L, object); lua_settable(m_L, m_index); } } template T get( int idx ) { if(validate()) { lua_pushnumber(m_L, idx ); lua_gettable(m_L, m_index); } else { lua_pushnil(m_L); } return pop(m_L); } lua_State* m_L; int m_index; const void* m_pointer; int m_ref; }; // Table Object Holder struct table { table(lua_State* L); table(lua_State* L, int index); table(lua_State* L, const char* name); table(const table& input); ~table(); template void set(const char* name, T object) { m_obj->set(name, object); } template T get(const char* name) { return m_obj->get(name); } template void set(int idx, T object) { m_obj->set(idx, object); } template T get(int idx) { return m_obj->get(idx); } int getSize() { // ½ºÅÿ¡ ÃÖ»óÀ§ Å×À̺íÀÌ ÀÖ´Ù´Â °¡Á¤ ÇÏ¿¡. lua_gettop() ÇÔ¼ö »ç¿ë //int iResSetTableIndex = lua_gettop( m_obj->m_L ); lua_pushnil( m_obj->m_L ); int nCnt = 0; // Ä«¿îÆ® ¸¸Å­ ·çÇÁ¸¦ µ·´Ù~ //while( lua_next( m_obj->m_L, iResSetTableIndex ) ) while( lua_next( m_obj->m_L, m_obj->m_index ) ) { nCnt++; lua_pop( m_obj->m_L, 1 ); } return nCnt; } table_obj* m_obj; }; } // namespace lua_tinker #endif //_LUA_TINKER_H_