From: John L. <jr...@us...> - 2007-12-20 02:27:04
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv8597/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlstate.cpp wxlua.cpp wxlua_bind.cpp Log Message: - Removed wxluabind_removetableforcall(L) used in the bindings to determine if the function was called from the tables used for class constructors. It makes more sense to call an intermediatary function to remove the table before calling the real function. - Removed the wxLuaFunction class since we no longer need it. It was a userdata with a __call metatable to call the real function we want. We now push the actual function or an overload function helper with the wxLuaBindMethod struct as an upvalue to give better error messages. The new way should be faster since it doesn't generate as much garbage. - Added wxlua_argerror(L, stack_idx, type_str) to give a far more informative message from the bindings when the wrong type is an arg to a function. - Renamed WXLUAARG_XXX to WXLUA_TXXX to match LUA_TXXX. * Do not create a separate overload function in the bindings since we can just as easily check for multiple functions using the wxLuaBindMethod and call the generic overload function or just the single function. Index: wxlua.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlua.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** wxlua.cpp 13 Dec 2007 00:47:52 -0000 1.8 --- wxlua.cpp 20 Dec 2007 02:26:58 -0000 1.9 *************** *** 34,38 **** static wxLuaArgTag s_wxluatagArray_wxLua_wxLuaState_delete[] = { &s_wxluatag_wxLuaState, NULL }; ! static wxLuaBindCFunc s_wxluafunc_wxLua_wxLuaState_delete[1] = {{ wxLua_wxluabind_delete, WXLUAMETHOD_METHOD|WXLUAMETHOD_DELETE, 1, 1, s_wxluatagArray_wxLua_wxLuaState_delete }}; --- 34,38 ---- static wxLuaArgTag s_wxluatagArray_wxLua_wxLuaState_delete[] = { &s_wxluatag_wxLuaState, NULL }; ! static wxLuaBindCFunc s_wxluafunc_wxLua_wxLuaState_delete[1] = {{ wxlua_userdata_delete, WXLUAMETHOD_METHOD|WXLUAMETHOD_DELETE, 1, 1, s_wxluatagArray_wxLua_wxLuaState_delete }}; *************** *** 104,108 **** static wxLuaArgTag s_wxluatagArray_wxLua_wxLuaObject_delete[] = { &s_wxluatag_wxLuaObject, NULL }; ! static wxLuaBindCFunc s_wxluafunc_wxLua_wxLuaObject_delete[1] = {{ wxLua_wxluabind_delete, WXLUAMETHOD_METHOD|WXLUAMETHOD_DELETE, 1, 1, s_wxluatagArray_wxLua_wxLuaObject_delete }}; static int LUACALL wxLua_wxLuaObject_constructor(lua_State *L); --- 104,108 ---- static wxLuaArgTag s_wxluatagArray_wxLua_wxLuaObject_delete[] = { &s_wxluatag_wxLuaObject, NULL }; ! static wxLuaBindCFunc s_wxluafunc_wxLua_wxLuaObject_delete[1] = {{ wxlua_userdata_delete, WXLUAMETHOD_METHOD|WXLUAMETHOD_DELETE, 1, 1, s_wxluatagArray_wxLua_wxLuaObject_delete }}; static int LUACALL wxLua_wxLuaObject_constructor(lua_State *L); *************** *** 112,116 **** static int LUACALL wxLua_wxLuaObject_constructor(lua_State *L) { - wxluabind_removetableforcall(L); wxLuaState wxlState(L); --- 112,115 ---- Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.154 retrieving revision 1.155 diff -C2 -d -r1.154 -r1.155 *** wxlstate.cpp 19 Dec 2007 06:16:36 -0000 1.154 --- wxlstate.cpp 20 Dec 2007 02:26:58 -0000 1.155 *************** *** 227,231 **** } ! int start_arg = wxluabind_removetableforcall(L, true) ? 2 : 1; wxString argMsg = wxlua_getLuaArgsMsg(L, start_arg, lua_gettop(L)); --- 227,231 ---- } ! int start_arg = 1; wxString argMsg = wxlua_getLuaArgsMsg(L, start_arg, lua_gettop(L)); *************** *** 235,240 **** { // guarantee that this is a wxLuaBindMethod of ours so we don't crash const wxLuaBindClass* wxlClass = wxLuaBinding::GetBindClass(wxlMethod, NULL); ! if (wxlClass != NULL) { wxArrayString a = wxlua_getBindMethodArgsMsg(L, wxlMethod); --- 235,248 ---- { // guarantee that this is a wxLuaBindMethod of ours so we don't crash + + // check if this methid is part of a class const wxLuaBindClass* wxlClass = wxLuaBinding::GetBindClass(wxlMethod, NULL); ! ! // if not, check if it's a global C style function ! wxLuaBinding* binding = NULL; ! if (wxlClass == NULL) ! binding = wxLuaBinding::GetFunctionBinding(wxlMethod, NULL); ! ! if ((wxlClass != NULL) || (binding != NULL)) { wxArrayString a = wxlua_getBindMethodArgsMsg(L, wxlMethod); *************** *** 482,486 **** wxString LUACALL wxluaT_gettagname(lua_State* L, int wxl_tag) { ! // This is a predefined WXLUAARG_XXX type if (wxl_tag <= 0) return wxlua_getwxluatypename(wxl_tag); --- 490,494 ---- wxString LUACALL wxluaT_gettagname(lua_State* L, int wxl_tag) { ! // This is a predefined WXLUA_TXXX type if (wxl_tag <= 0) return wxlua_getwxluatypename(wxl_tag); *************** *** 488,493 **** if (wxl_tag == g_wxluatag_NULL) return wxT("NULL"); - if (wxl_tag == g_wxluatag_wxLuaFunction) - return wxT("wxLuaFunction"); const wxLuaBindClass* wxlClass = wxluaT_getclass(L, wxl_tag); --- 496,499 ---- *************** *** 514,519 **** if ((g_wxluatag_NULL == stack_tag) || // FIXME, how to check when NULL is valid or not? ! (g_wxluatag_wxLuaFunction == stack_tag) || ! ((wxl_tag == WXLUAARG_String) && (wxlua_isderivedclass(L, stack_tag, g_wxluatag_wxString) >= 0)) || (wxlua_isderivedclass(L, stack_tag, wxl_tag) >= 0)) return true; --- 520,524 ---- if ((g_wxluatag_NULL == stack_tag) || // FIXME, how to check when NULL is valid or not? ! ((wxl_tag == WXLUA_TSTRING) && (wxlua_isderivedclass(L, stack_tag, g_wxluatag_wxString) >= 0)) || (wxlua_isderivedclass(L, stack_tag, wxl_tag) >= 0)) return true; *************** *** 529,538 **** int stack_tag = wxluaT_gettag(L, stack_idx); ! if (g_wxluatag_wxLuaFunction == stack_tag) ! { ! wxLuaFunction *pFunction = (wxLuaFunction *)wxlua_touserdata(L, stack_idx, false); ! return pFunction->GetObject(); ! } ! else if (g_wxluatag_NULL == stack_tag) return NULL; else if (wxlua_isderivedclass(L, stack_tag, wxl_tag) >= 0) --- 534,538 ---- int stack_tag = wxluaT_gettag(L, stack_idx); ! if (g_wxluatag_NULL == stack_tag) return NULL; else if (wxlua_isderivedclass(L, stack_tag, wxl_tag) >= 0) *************** *** 553,562 **** // When il2 gets gc it will delete il even though il may still be valid and used by the notebook. ! // we don't track the wxLuaFunctions for speed ! if (wxl_tag != g_wxluatag_wxLuaFunction) ! { ! if (wxluaO_istrackedweakobject(L, (void*)obj_ptr, wxl_tag, true)) ! return true; ! } // Wrap the void* pointer in a newuserdata --- 553,558 ---- // When il2 gets gc it will delete il even though il may still be valid and used by the notebook. ! if (wxluaO_istrackedweakobject(L, (void*)obj_ptr, wxl_tag, true)) ! return true; // Wrap the void* pointer in a newuserdata *************** *** 911,925 **** // ---------------------------------------------------------------------------- ! void LUACALL wxluaW_addtrackedwindow(lua_State *L, wxObject* obj) { ! if (!obj) return; // allow NULL w/o error // don't track these "windows" since they're supposed to be attached // and their parents are not properly set so we can't tell if // their parents are tracked. ! if (wxDynamicCast(obj, wxMenuBar) != NULL) return; ! if (wxDynamicCast(obj, wxToolBar) != NULL) return; ! wxWindow* win = wxDynamicCast(obj, wxWindow); // only need to track parent window, it deletes children for us --- 907,921 ---- // ---------------------------------------------------------------------------- ! void LUACALL wxluaW_addtrackedwindow(lua_State *L, wxObject* wxobj) { ! if (!wxobj) return; // allow NULL w/o error // don't track these "windows" since they're supposed to be attached // and their parents are not properly set so we can't tell if // their parents are tracked. ! if (wxDynamicCast(wxobj, wxMenuBar) != NULL) return; ! if (wxDynamicCast(wxobj, wxToolBar) != NULL) return; ! wxWindow* win = wxDynamicCast(wxobj, wxWindow); // only need to track parent window, it deletes children for us *************** *** 1047,1071 **** } ! int LUACALL wxlua_iswxluatype(int luatype, int wxluaarg_tag, lua_State* L /* = NULL */) { int ret = -1; // unknown wxlua arg type ! switch (wxluaarg_tag) { ! case WXLUAARG_None : ret = (luatype == LUA_TNONE) ? 1 : 0; break; ! case WXLUAARG_Nil : ret = (luatype == LUA_TNIL) ? 1 : 0; break; ! case WXLUAARG_Boolean : // LUA_TNIL: nil == false // LUA_TNUMBER: 0 == false as in C ret = ((luatype == LUA_TBOOLEAN) || (luatype == LUA_TNUMBER) || (luatype == LUA_TNIL)) ? 1 : 0; break; ! case WXLUAARG_LightUserData : ret = (luatype == LUA_TLIGHTUSERDATA) ? 1 : 0; break; ! case WXLUAARG_Number : // LUA_TNIL: evaluates to 0, too easy to have a typo // LUA_TSTRING: will be 0 unless really a number "2" --- 1043,1067 ---- } ! int LUACALL wxlua_iswxluatype(int luatype, int wxlarg_tag, lua_State* L /* = NULL */) { int ret = -1; // unknown wxlua arg type ! switch (wxlarg_tag) { ! case WXLUA_TNONE : ret = (luatype == LUA_TNONE) ? 1 : 0; break; ! case WXLUA_TNIL : ret = (luatype == LUA_TNIL) ? 1 : 0; break; ! case WXLUA_TBOOLEAN : // LUA_TNIL: nil == false // LUA_TNUMBER: 0 == false as in C ret = ((luatype == LUA_TBOOLEAN) || (luatype == LUA_TNUMBER) || (luatype == LUA_TNIL)) ? 1 : 0; break; ! case WXLUA_TLIGHTUSERDATA: ret = (luatype == LUA_TLIGHTUSERDATA) ? 1 : 0; break; ! case WXLUA_TNUMBER : // LUA_TNIL: evaluates to 0, too easy to have a typo // LUA_TSTRING: will be 0 unless really a number "2" *************** *** 1073,1098 **** ret = ((luatype == LUA_TNUMBER) || (luatype == LUA_TBOOLEAN)) ? 1 : 0; break; ! case WXLUAARG_String : // LUA_TNIL: too easy to have a variable typo, use (str or "") // LUA_TNUMBER: can convert easily, always works, but breaks overload bindings ret = (luatype == LUA_TSTRING) ? 1 : 0; break; ! case WXLUAARG_Table : ret = (luatype == LUA_TTABLE) ? 1 : 0; break; ! case WXLUAARG_Function : ret = (luatype == LUA_TFUNCTION) ? 1 : 0; break; ! case WXLUAARG_UserData : ret = (luatype == LUA_TUSERDATA) ? 1 : 0; break; ! case WXLUAARG_Thread : ret = (luatype == LUA_TTHREAD) ? 1 : 0; break; ! case WXLUAARG_Integer : // LUA_TNIL: evaluates to 0 so wx.ENUM_typo = 0 ret = (luatype == LUA_TNUMBER) ? 1 : 0; break; ! case WXLUAARG_CFunction : ret = (luatype == LUA_TFUNCTION) ? 1 : 0; break; --- 1069,1094 ---- ret = ((luatype == LUA_TNUMBER) || (luatype == LUA_TBOOLEAN)) ? 1 : 0; break; ! case WXLUA_TSTRING : // LUA_TNIL: too easy to have a variable typo, use (str or "") // LUA_TNUMBER: can convert easily, always works, but breaks overload bindings ret = (luatype == LUA_TSTRING) ? 1 : 0; break; ! case WXLUA_TTABLE : ret = (luatype == LUA_TTABLE) ? 1 : 0; break; ! case WXLUA_TFUNCTION : ret = (luatype == LUA_TFUNCTION) ? 1 : 0; break; ! case WXLUA_TUSERDATA : ret = (luatype == LUA_TUSERDATA) ? 1 : 0; break; ! case WXLUA_TTHREAD : ret = (luatype == LUA_TTHREAD) ? 1 : 0; break; ! case WXLUA_TINTEGER : // LUA_TNIL: evaluates to 0 so wx.ENUM_typo = 0 ret = (luatype == LUA_TNUMBER) ? 1 : 0; break; ! case WXLUA_TCFUNCTION : ret = (luatype == LUA_TFUNCTION) ? 1 : 0; break; *************** *** 1102,1106 **** if ((ret < 0) && L &&(luatype == LUA_TTABLE)) { ! const wxLuaBindClass* wxlClass = wxluaT_getclass(L, wxluaarg_tag); if (wxlua_isderivedclass(wxlClass, wxluaT_getclass(L, "wxArrayString")) >= 0) --- 1098,1102 ---- if ((ret < 0) && L &&(luatype == LUA_TTABLE)) { ! const wxLuaBindClass* wxlClass = wxluaT_getclass(L, wxlarg_tag); if (wxlua_isderivedclass(wxlClass, wxluaT_getclass(L, "wxArrayString")) >= 0) *************** *** 1115,1119 **** } ! wxString wxlua_getwxluatypename(int wxluaarg_tag) { // try to use wxString's ref counting and return this existing copy --- 1111,1115 ---- } ! wxString wxlua_getwxluatypename(int wxlarg_tag, lua_State* L) { // try to use wxString's ref counting and return this existing copy *************** *** 1133,1151 **** }; ! switch (wxluaarg_tag) { ! case WXLUAARG_None : return s[0]; ! case WXLUAARG_Nil : return s[1]; ! case WXLUAARG_Boolean : return s[2]; ! case WXLUAARG_LightUserData : return s[3]; ! case WXLUAARG_Number : return s[4]; ! case WXLUAARG_String : return s[5]; ! case WXLUAARG_Table : return s[6]; ! case WXLUAARG_Function : return s[7]; ! case WXLUAARG_UserData : return s[8]; ! case WXLUAARG_Thread : return s[9]; ! case WXLUAARG_Integer : return s[10]; ! case WXLUAARG_CFunction : return s[11]; } --- 1129,1150 ---- }; ! if ((L != NULL) && (wxlarg_tag > 0)) ! return wxluaT_gettagname(L, wxlarg_tag); ! ! switch (wxlarg_tag) { ! case WXLUA_TNONE : return s[0]; ! case WXLUA_TNIL : return s[1]; ! case WXLUA_TBOOLEAN : return s[2]; ! case WXLUA_TLIGHTUSERDATA : return s[3]; ! case WXLUA_TNUMBER : return s[4]; ! case WXLUA_TSTRING : return s[5]; ! case WXLUA_TTABLE : return s[6]; ! case WXLUA_TFUNCTION : return s[7]; ! case WXLUA_TUSERDATA : return s[8]; ! case WXLUA_TTHREAD : return s[9]; ! case WXLUA_TINTEGER : return s[10]; ! case WXLUA_TCFUNCTION : return s[11]; } *************** *** 1155,1193 **** int wxlua_getwxluatype(int luatype) { switch (luatype) { ! case LUA_TNONE : return WXLUAARG_None; ! case LUA_TNIL : return WXLUAARG_Nil; ! case LUA_TBOOLEAN : return WXLUAARG_Boolean; ! case LUA_TLIGHTUSERDATA : return WXLUAARG_LightUserData; ! case LUA_TNUMBER : return WXLUAARG_Number; ! case LUA_TSTRING : return WXLUAARG_String; ! case LUA_TTABLE : return WXLUAARG_Table; ! case LUA_TFUNCTION : return WXLUAARG_Function; ! case LUA_TUSERDATA : return WXLUAARG_UserData; ! case LUA_TTHREAD : return WXLUAARG_Thread; ! //case LUA_T??? : return WXLUAARG_Integer; ! //case LUA_T??? : return WXLUAARG_CFunction; } ! return -1; } ! int wxlua_getluatype(int wxluaarg_tag) { ! switch (wxluaarg_tag) { ! case WXLUAARG_None : return LUA_TNONE; ! case WXLUAARG_Nil : return LUA_TNIL; ! case WXLUAARG_Boolean : return LUA_TBOOLEAN; ! case WXLUAARG_LightUserData : return LUA_TLIGHTUSERDATA; ! case WXLUAARG_Number : return LUA_TNUMBER; ! case WXLUAARG_String : return LUA_TSTRING; ! case WXLUAARG_Table : return LUA_TTABLE; ! case WXLUAARG_Function : return LUA_TFUNCTION; ! case WXLUAARG_UserData : return LUA_TUSERDATA; ! case WXLUAARG_Thread : return LUA_TTHREAD; ! case WXLUAARG_Integer : return LUA_TNUMBER; ! case WXLUAARG_CFunction : return LUA_TFUNCTION; } --- 1154,1197 ---- int wxlua_getwxluatype(int luatype) { + //int wxltype = LUAT_TO_WXLUAT(luatype); + //if ((wxltype > WXLUA_T_MAX) || (wxltype < WXLUA_T_MIN)) + // return WXLUA_TUNKNOWN; + //return wxltype; + switch (luatype) { ! case LUA_TNONE : return WXLUA_TNONE; ! case LUA_TNIL : return WXLUA_TNIL; ! case LUA_TBOOLEAN : return WXLUA_TBOOLEAN; ! case LUA_TLIGHTUSERDATA : return WXLUA_TLIGHTUSERDATA; ! case LUA_TNUMBER : return WXLUA_TNUMBER; ! case LUA_TSTRING : return WXLUA_TSTRING; ! case LUA_TTABLE : return WXLUA_TTABLE; ! case LUA_TFUNCTION : return WXLUA_TFUNCTION; ! case LUA_TUSERDATA : return WXLUA_TUSERDATA; ! case LUA_TTHREAD : return WXLUA_TTHREAD; ! //case LUA_T??? : return WXLUA_TINTEGER; ! //case LUA_T??? : return WXLUA_TCFUNCTION; } ! return WXLUA_TUNKNOWN; } ! int wxlua_getluatype(int wxlarg) { ! switch (wxlarg) { ! case WXLUA_TNONE : return LUA_TNONE; ! case WXLUA_TNIL : return LUA_TNIL; ! case WXLUA_TBOOLEAN : return LUA_TBOOLEAN; ! case WXLUA_TLIGHTUSERDATA : return LUA_TLIGHTUSERDATA; ! case WXLUA_TNUMBER : return LUA_TNUMBER; ! case WXLUA_TSTRING : return LUA_TSTRING; ! case WXLUA_TTABLE : return LUA_TTABLE; ! case WXLUA_TFUNCTION : return LUA_TFUNCTION; ! case WXLUA_TUSERDATA : return LUA_TUSERDATA; ! case WXLUA_TTHREAD : return LUA_TTHREAD; ! case WXLUA_TINTEGER : return LUA_TNUMBER; ! case WXLUA_TCFUNCTION : return LUA_TFUNCTION; } *************** *** 1202,1206 **** bool wxlua_iswxstringtype(lua_State* L, int stack_idx) { ! if (wxlua_iswxluatype(lua_type(L, stack_idx), WXLUAARG_String) == 1) return true; else if (wxlua_iswxuserdata(L, stack_idx)) --- 1206,1210 ---- bool wxlua_iswxstringtype(lua_State* L, int stack_idx) { ! if (wxlua_iswxluatype(lua_type(L, stack_idx), WXLUA_TSTRING) == 1) return true; else if (wxlua_iswxuserdata(L, stack_idx)) *************** *** 1245,1249 **** int l_type = lua_type(L, stack_idx); ! if (!wxlua_iswxluatype(l_type, WXLUAARG_Boolean)) wxlua_argerror(L, stack_idx, wxT("a 'boolean'")); --- 1249,1253 ---- int l_type = lua_type(L, stack_idx); ! if (!wxlua_iswxluatype(l_type, WXLUA_TBOOLEAN)) wxlua_argerror(L, stack_idx, wxT("a 'boolean'")); *************** *** 1261,1265 **** int l_type = lua_type(L, stack_idx); ! if (!wxlua_iswxluatype(l_type, WXLUAARG_Integer)) wxlua_argerror(L, stack_idx, wxT("an 'integer'")); --- 1265,1269 ---- int l_type = lua_type(L, stack_idx); ! if (!wxlua_iswxluatype(l_type, WXLUA_TINTEGER)) wxlua_argerror(L, stack_idx, wxT("an 'integer'")); *************** *** 1280,1284 **** int l_type = lua_type(L, stack_idx); ! if (!wxlua_iswxluatype(l_type, WXLUAARG_Number)) wxlua_argerror(L, stack_idx, wxT("a 'number'")); --- 1284,1288 ---- int l_type = lua_type(L, stack_idx); ! if (!wxlua_iswxluatype(l_type, WXLUA_TNUMBER)) wxlua_argerror(L, stack_idx, wxT("a 'number'")); *************** *** 2688,2702 **** lua_State* L = M_WXLSTATEDATA->m_lua_State; - // Create a metatable for our C function wrapper wxLuaFunction - g_wxluatag_wxLuaFunction = wxluaT_NewTag(); - lua_pushstring(L, "__gc"); - lua_pushcfunction(L, wxlua__gc_wxLuaFunction); - lua_rawset(L, -3); // t["method_name"] = closure of func - - lua_pushstring(L, "__call"); - lua_pushcfunction(L, wxlua__call_wxLuaFunction); - lua_rawset(L, -3); // t["method_name"] = closure of func - lua_pop(L, 1); // remove the new table from wxluaT_NewTag() - // Finally - set the global tags from the bindings we've just installed --- 2692,2695 ---- Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.108 retrieving revision 1.109 diff -C2 -d -r1.108 -r1.109 *** wxlbind.cpp 19 Dec 2007 06:16:36 -0000 1.108 --- wxlbind.cpp 20 Dec 2007 02:26:58 -0000 1.109 *************** *** 28,45 **** wxLuaBindDefine s_wxluadefineArray_None[1] = {{0, 0}}; ! int s_wxluaarg_None = WXLUAARG_None; ! int s_wxluaarg_Nil = WXLUAARG_Nil; ! int s_wxluaarg_Boolean = WXLUAARG_Boolean; ! int s_wxluaarg_LightUserData = WXLUAARG_LightUserData; // raw data ! int s_wxluaarg_Number = WXLUAARG_Number; ! int s_wxluaarg_String = WXLUAARG_String; ! int s_wxluaarg_Table = WXLUAARG_Table; ! int s_wxluaarg_Function = WXLUAARG_Function; ! int s_wxluaarg_UserData = WXLUAARG_UserData; // raw data ! int s_wxluaarg_Thread = WXLUAARG_Thread; ! int s_wxluaarg_Integer = WXLUAARG_Integer; ! int s_wxluaarg_CFunction = WXLUAARG_CFunction; - int g_wxluatag_wxLuaFunction = WXLUA_NOTAG; int g_wxluatag_NULL = WXLUA_NOTAG; int g_wxluatag_wxEvent = WXLUA_NOTAG; --- 28,44 ---- wxLuaBindDefine s_wxluadefineArray_None[1] = {{0, 0}}; ! int s_wxluaarg_None = WXLUA_TNONE; ! int s_wxluaarg_Nil = WXLUA_TNIL; ! int s_wxluaarg_Boolean = WXLUA_TBOOLEAN; ! int s_wxluaarg_LightUserData = WXLUA_TLIGHTUSERDATA; // raw data ! int s_wxluaarg_Number = WXLUA_TNUMBER; ! int s_wxluaarg_String = WXLUA_TSTRING; ! int s_wxluaarg_Table = WXLUA_TTABLE; ! int s_wxluaarg_Function = WXLUA_TFUNCTION; ! int s_wxluaarg_UserData = WXLUA_TUSERDATA; // raw data ! int s_wxluaarg_Thread = WXLUA_TTHREAD; ! int s_wxluaarg_Integer = WXLUA_TINTEGER; ! int s_wxluaarg_CFunction = WXLUA_TCFUNCTION; int g_wxluatag_NULL = WXLUA_NOTAG; int g_wxluatag_wxEvent = WXLUA_NOTAG; *************** *** 50,105 **** int g_wxluatag_wxArrayInt = WXLUA_NOTAG; - //----------------------------------------------------------------------------- - // wxLuaFunction - //----------------------------------------------------------------------------- - - int wxLuaFunction::CallMethod(lua_State *L) - { - // remove this line to restore calling methods using the dot notation - // otherwise the colon notation *must* be used. - lua_remove(L, 1); // remove the wxLuaFunction userdata from the stack - - if (m_wxlMethod->basemethod) - return wxlua_CallOverloadedFunction(L, m_wxlMethod); - - return (*m_wxlMethod->funcs[0].func)(L); - } - - int LUACALL wxlua__gc_wxLuaFunction(lua_State *L) - { - // Sanity check, but this is only attached to a wxLuaFunction, so it has to be ok. - //if (wxlua_iswxuserdata(L, 1) && (wxluaT_gettag(L, 1) == g_wxluatag_wxLuaFunction)) - { - wxLuaFunction *wxlFunction = (wxLuaFunction *)wxlua_touserdata(L, 1, true); - if (wxlFunction != NULL) - delete wxlFunction; - } - return 0; - } - - int LUACALL wxlua__call_wxLuaFunction(lua_State *L) - { - // Sanity check, but this is only attached to a wxLuaFunction, so it has to be ok. - //if (wxlua_iswxuserdata(L, 1) && (wxluaT_gettag(L, 1) == g_wxluatag_wxLuaFunction)) - { - wxLuaFunction *f = (wxLuaFunction *)wxlua_touserdata(L, 1, false); - return f->CallMethod(L); - } - return 0; - } - // ---------------------------------------------------------------------------- // Central function to call for overloaded functions // ---------------------------------------------------------------------------- ! ! static int LUACALL wxlua_CallOverloadedFunction(lua_State* L) { wxLuaBindMethod* wxlMethod = (wxLuaBindMethod *)lua_touserdata(L, lua_upvalueindex(1)); // lightuserdata wxCHECK_MSG(wxlMethod, 0, wxT("Invalid wxLuaBindMethod")); ! return wxlua_CallOverloadedFunction(L, wxlMethod); } ! int LUACALL wxlua_CallOverloadedFunction(lua_State* L, struct wxLuaBindMethod* wxlMethod) { int i, arg; --- 49,68 ---- int g_wxluatag_wxArrayInt = WXLUA_NOTAG; // ---------------------------------------------------------------------------- // Central function to call for overloaded functions // ---------------------------------------------------------------------------- ! int LUACALL wxlua_callOverloadedFunction(lua_State* L) { wxLuaBindMethod* wxlMethod = (wxLuaBindMethod *)lua_touserdata(L, lua_upvalueindex(1)); // lightuserdata wxCHECK_MSG(wxlMethod, 0, wxT("Invalid wxLuaBindMethod")); ! ! if ((wxlMethod->funcs_n > 1) || (wxlMethod->basemethod)) ! return wxlua_callOverloadedFunction(L, wxlMethod); ! else ! return (*wxlMethod->funcs[0].func)(L); } ! int LUACALL wxlua_callOverloadedFunction(lua_State* L, struct wxLuaBindMethod* wxlMethod) { int i, arg; *************** *** 109,119 **** int arg_lua_start = 1; - // don't remove the table, but do skip past it when counting args - if (wxluabind_removetableforcall(L, true)) - { - arg_lua_count--; - arg_lua_start++; - } - // only look at the methods that could possibly work and traverse base classes wxArrayPtrVoid funcArray; --- 72,75 ---- *************** *** 125,135 **** for (i = 0; i < method->funcs_n; ++i, ++bindFunc) { ! if (!WXLUA_HASBIT(bindFunc->type, WXLUAMETHOD_OVERLOAD) && ! (arg_lua_count >= bindFunc->minargs) && (arg_lua_count <= bindFunc->maxargs)) { funcArray.Add(bindFunc); } - } --- 81,89 ---- for (i = 0; i < method->funcs_n; ++i, ++bindFunc) { ! if ((arg_lua_count >= bindFunc->minargs) && (arg_lua_count <= bindFunc->maxargs)) { funcArray.Add(bindFunc); } } *************** *** 171,175 **** // unknown/invalid standard wxlua arg type, check binding tag ! if ((is_ok == -1) || ((is_ok == 0) && (tag == WXLUAARG_String))) { is_ok = (wxluaT_isuserdatatype(L, arg_lua, tag) || --- 125,129 ---- // unknown/invalid standard wxlua arg type, check binding tag ! if ((is_ok == -1) || ((is_ok == 0) && (tag == WXLUA_TSTRING))) { is_ok = (wxluaT_isuserdatatype(L, arg_lua, tag) || *************** *** 305,346 **** wxString funcStr = wxString::Format(wxT("%02d. %s%s("), i_func, className.c_str(), lua2wx(method->name).c_str()); ! // overloaded function has invalid tags ! if (WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_OVERLOAD)) ! { ! // However, we do print that there is an overload so that in CallOverloadedFunction ! // we can find what function we were closest too. ! funcStr += wxT(" ... ) - overloaded function"); ! } ! else { ! for (arg = 0; arg < funcs[i].maxargs; ++arg) ! { ! // optional args? ! if ((funcs[i].minargs < funcs[i].maxargs) && (arg == funcs[i].minargs)) ! funcStr += wxT("["); ! if (arg > 0) ! funcStr += wxT(", "); ! int tag = (int)*(funcs[i].argtags[arg]); ! funcStr += wxluaT_gettagname(L, tag); ! if ((arg == 0) && ! !WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_STATIC) && ! !WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_CONSTRUCTOR) && ! !WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_CFUNCTION)) ! funcStr += wxT("(self)"); ! } ! // close optional args ! if (funcs[i].minargs < funcs[i].maxargs) ! funcStr += wxT("]"); ! funcStr += wxT(")"); ! if (WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_STATIC)) ! funcStr += wxT(" - static"); ! } overloadMethodArray.Add(funcStr); --- 259,290 ---- wxString funcStr = wxString::Format(wxT("%02d. %s%s("), i_func, className.c_str(), lua2wx(method->name).c_str()); ! for (arg = 0; arg < funcs[i].maxargs; ++arg) { ! // optional args? ! if ((funcs[i].minargs < funcs[i].maxargs) && (arg == funcs[i].minargs)) ! funcStr += wxT("["); ! if (arg > 0) ! funcStr += wxT(", "); ! int tag = (int)*(funcs[i].argtags[arg]); ! funcStr += wxluaT_gettagname(L, tag); ! if ((arg == 0) && ! !WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_STATIC) && ! !WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_CONSTRUCTOR) && ! !WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_CFUNCTION)) ! funcStr += wxT("(self)"); ! } ! // close optional args ! if (funcs[i].minargs < funcs[i].maxargs) ! funcStr += wxT("]"); ! funcStr += wxT(")"); ! if (WXLUA_HASBIT(funcs[i].type, WXLUAMETHOD_STATIC)) ! funcStr += wxT(" - static"); overloadMethodArray.Add(funcStr); *************** *** 586,590 **** // ---------------------------------------------------------------------------- ! int LUACALL wxLua_wxluabind_delete(lua_State *L) { void* udata = lua_touserdata(L, 1); --- 530,534 ---- // ---------------------------------------------------------------------------- ! int LUACALL wxlua_userdata_delete(lua_State *L) { void* udata = lua_touserdata(L, 1); *************** *** 611,615 **** // ---------------------------------------------------------------------------- ! int LUACALL wxluabind__gc_wxLuaBindClass(lua_State *L) { wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); --- 555,559 ---- // ---------------------------------------------------------------------------- ! int LUACALL wxlua_wxLuaBindClass__gc(lua_State *L) { wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); *************** *** 630,639 **** // Called by LUA to find the method that corresponds to a given method name. // The class to lookup is in an upvalue. (gettable tag method). - // If the method is a function method push a wxLuaFunction object - // onto the Lua stack, setting its metatable so that when Lua calls __call - // the wxLuaFunction will run the actual method we set for it. // ---------------------------------------------------------------------------- ! int LUACALL wxluabind__index_wxLuaBindClass(lua_State *L) { // This function is called for the __index metable of the wxLua userdata --- 574,580 ---- // Called by LUA to find the method that corresponds to a given method name. // The class to lookup is in an upvalue. (gettable tag method). // ---------------------------------------------------------------------------- ! int LUACALL wxlua_wxLuaBindClass__index(lua_State *L) { // This function is called for the __index metable of the wxLua userdata *************** *** 717,733 **** result = 1; - #if 1 lua_pushlightuserdata(L, wxlMethod); ! // experimental function calls w/o using the wxLuaFunction ! if (wxlMethod->basemethod) ! lua_pushcclosure(L, wxlua_CallOverloadedFunction, 1); else lua_pushcclosure(L, wxlMethod->funcs[0].func, 1); - #else - wxLuaFunction *wxlFunc = new wxLuaFunction(wxlMethod, obj_ptr); - // Don't track the wxLuaFunction for speed - wxluaT_pushusertag(L, wxlFunc, g_wxluatag_wxLuaFunction, false); - #endif } } --- 658,667 ---- result = 1; lua_pushlightuserdata(L, wxlMethod); ! if ((wxlMethod->funcs_n > 1) || (wxlMethod->basemethod)) ! lua_pushcclosure(L, wxlua_callOverloadedFunction, 1); else lua_pushcclosure(L, wxlMethod->funcs[0].func, 1); } } *************** *** 776,780 **** // ---------------------------------------------------------------------------- ! int LUACALL wxluabind__newindex_wxLuaBindClass(lua_State *L) { wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); --- 710,714 ---- // ---------------------------------------------------------------------------- ! int LUACALL wxlua_wxLuaBindClass__newindex(lua_State *L) { wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); *************** *** 831,835 **** // ---------------------------------------------------------------------------- ! int LUACALL wxluabind__tostring_wxLuaBindClass(lua_State *L) { wxLuaState wxlState(L); --- 765,769 ---- // ---------------------------------------------------------------------------- ! int LUACALL wxlua_wxLuaBindClass__tostring(lua_State *L) { wxLuaState wxlState(L); *************** *** 857,874 **** // ---------------------------------------------------------------------------- ! // Use the pointer to this int as a special tag to know that __call has been ! // made on a table and that we want to remove the table for the bindings to ! // work. This is because Lua always pushes the table on the stack if '.' or ':' ! // is used for the __call metamethod. // ---------------------------------------------------------------------------- - static int wxluabind_checkremovetable = 0; ! int wxluabind_removetableforcall(lua_State* L, bool only_check) { ! void* p = (void *)lua_touserdata(L, lua_upvalueindex(2)); // lightuserdata ! if (!only_check && (p == &wxluabind_checkremovetable)) ! lua_remove(L, 1); ! return p == &wxluabind_checkremovetable; } --- 791,802 ---- // ---------------------------------------------------------------------------- ! // // ---------------------------------------------------------------------------- ! int LUACALL wxlua_wxLuaBindMethod_table__call(lua_State *L) { ! lua_remove(L, 1); // remove the table ! return wxlua_callOverloadedFunction(L); } *************** *** 1072,1079 **** static const luaL_reg s_funcTable[] = { ! {"__gc", wxluabind__gc_wxLuaBindClass }, ! {"__index", wxluabind__index_wxLuaBindClass }, ! {"__newindex", wxluabind__newindex_wxLuaBindClass }, ! {"__tostring", wxluabind__tostring_wxLuaBindClass } }; static const size_t s_funcCount = sizeof(s_funcTable)/sizeof(s_funcTable[0]); --- 1000,1007 ---- static const luaL_reg s_funcTable[] = { ! {"__gc", wxlua_wxLuaBindClass__gc }, ! {"__index", wxlua_wxLuaBindClass__index }, ! {"__newindex", wxlua_wxLuaBindClass__newindex }, ! {"__tostring", wxlua_wxLuaBindClass__tostring } }; static const size_t s_funcCount = sizeof(s_funcTable)/sizeof(s_funcTable[0]); *************** *** 1177,1182 **** lua_pushlstring(L, "new", 3); lua_pushlightuserdata(L, wxlMethod); ! lua_pushcclosure(L, wxlMethod->funcs[0].func, 1); ! lua_rawset(L, -3); // same as lua_setfield(L, -2, "key") // Create the metatable for this table --- 1105,1110 ---- lua_pushlstring(L, "new", 3); lua_pushlightuserdata(L, wxlMethod); ! lua_pushcclosure(L, wxlua_callOverloadedFunction, 1); ! lua_rawset(L, -3); // Create the metatable for this table *************** *** 1185,1190 **** lua_pushlstring(L, "__call", 6); lua_pushlightuserdata(L, wxlMethod); ! lua_pushlightuserdata(L, &wxluabind_checkremovetable); // push tag to recognize table call ! lua_pushcclosure(L, wxlMethod->funcs[0].func, 2); // push func with tag as upvalue lua_rawset(L, -3); --- 1113,1117 ---- lua_pushlstring(L, "__call", 6); lua_pushlightuserdata(L, wxlMethod); ! lua_pushcclosure(L, wxlua_wxLuaBindMethod_table__call, 1); lua_rawset(L, -3); *************** *** 1480,1483 **** --- 1407,1435 ---- } + // static + wxLuaBinding* wxLuaBinding::GetFunctionBinding(const wxLuaBindMethod* method, const wxLuaBindingList* bindingList_) + { + const wxLuaBindingList* bindingList = bindingList_ ? bindingList_ : &sm_bindingList; + wxLuaBindingList::compatibility_iterator node = bindingList->GetFirst(); + + while (node) + { + wxLuaBinding* binding = node->GetData(); + size_t n, count = binding->GetFunctionCount(); + wxLuaBindMethod* m = binding->GetFunctionArray(); + + for (n = 0; n < count; ++n, ++m) + { + if (m == method) + return binding; + } + + node = node->GetNext(); + } + + return NULL; + } + + // -------------------------------------------------------------------------- *************** *** 1541,1553 **** for (i_method = 0; i_method < method_count; ++i_method, ++wxlMethod) { ! if (isLuaSetProp) ! { ! if (WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_SETPROP) && (strcmp(wxlMethod->name, propName) == 0)) ! return wxlMethod; ! } ! else { ! if (WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_GETPROP) && (strcmp(wxlMethod->name, propName) == 0)) ! return wxlMethod; } } --- 1493,1501 ---- for (i_method = 0; i_method < method_count; ++i_method, ++wxlMethod) { ! if (((isLuaSetProp && WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_SETPROP)) || ! (!isLuaSetProp && WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_GETPROP))) && ! (strcmp(wxlMethod->name, propName) == 0)) { ! return wxlMethod; } } Index: wxlua_bind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlua_bind.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** wxlua_bind.cpp 15 Dec 2007 16:56:41 -0000 1.17 --- wxlua_bind.cpp 20 Dec 2007 02:26:58 -0000 1.18 *************** *** 59,73 **** { "LUA_TTHREAD", LUA_TTHREAD }, { "LUA_TUSERDATA", LUA_TUSERDATA }, - { "WXLUAARG_Boolean", WXLUAARG_Boolean }, - { "WXLUAARG_Function", WXLUAARG_Function }, - { "WXLUAARG_Integer", WXLUAARG_Integer }, - { "WXLUAARG_LightUserData", WXLUAARG_LightUserData }, - { "WXLUAARG_Nil", WXLUAARG_Nil }, - { "WXLUAARG_None", WXLUAARG_None }, - { "WXLUAARG_Number", WXLUAARG_Number }, - { "WXLUAARG_String", WXLUAARG_String }, - { "WXLUAARG_Table", WXLUAARG_Table }, - { "WXLUAARG_Thread", WXLUAARG_Thread }, - { "WXLUAARG_UserData", WXLUAARG_UserData }, { "WXLUAMETHOD_CFUNCTION", WXLUAMETHOD_CFUNCTION }, { "WXLUAMETHOD_CONSTRUCTOR", WXLUAMETHOD_CONSTRUCTOR }, --- 59,62 ---- *************** *** 75,82 **** { "WXLUAMETHOD_GETPROP", WXLUAMETHOD_GETPROP }, { "WXLUAMETHOD_METHOD", WXLUAMETHOD_METHOD }, - { "WXLUAMETHOD_OVERLOAD", WXLUAMETHOD_OVERLOAD }, { "WXLUAMETHOD_OVERLOAD_BASE", WXLUAMETHOD_OVERLOAD_BASE }, { "WXLUAMETHOD_SETPROP", WXLUAMETHOD_SETPROP }, { "WXLUAMETHOD_STATIC", WXLUAMETHOD_STATIC }, { "wxLUAOBJECT_ARRAYINT", wxLUAOBJECT_ARRAYINT }, { "wxLUAOBJECT_BOOL", wxLUAOBJECT_BOOL }, --- 64,82 ---- { "WXLUAMETHOD_GETPROP", WXLUAMETHOD_GETPROP }, { "WXLUAMETHOD_METHOD", WXLUAMETHOD_METHOD }, { "WXLUAMETHOD_OVERLOAD_BASE", WXLUAMETHOD_OVERLOAD_BASE }, { "WXLUAMETHOD_SETPROP", WXLUAMETHOD_SETPROP }, { "WXLUAMETHOD_STATIC", WXLUAMETHOD_STATIC }, + { "WXLUA_TBOOLEAN", WXLUA_TBOOLEAN }, + { "WXLUA_TCFUNCTION", WXLUA_TCFUNCTION }, + { "WXLUA_TFUNCTION", WXLUA_TFUNCTION }, + { "WXLUA_TINTEGER", WXLUA_TINTEGER }, + { "WXLUA_TLIGHTUSERDATA", WXLUA_TLIGHTUSERDATA }, + { "WXLUA_TNIL", WXLUA_TNIL }, + { "WXLUA_TNONE", WXLUA_TNONE }, + { "WXLUA_TNUMBER", WXLUA_TNUMBER }, + { "WXLUA_TSTRING", WXLUA_TSTRING }, + { "WXLUA_TTABLE", WXLUA_TTABLE }, + { "WXLUA_TTHREAD", WXLUA_TTHREAD }, + { "WXLUA_TUSERDATA", WXLUA_TUSERDATA }, { "wxLUAOBJECT_ARRAYINT", wxLUAOBJECT_ARRAYINT }, { "wxLUAOBJECT_BOOL", wxLUAOBJECT_BOOL }, |