From: John L. <jr...@us...> - 2007-06-12 05:03:21
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv22549/wxLua/modules/wxlua/src Modified Files: Makefile wxlbind.cpp Log Message: Add ability to do profiling in GCC using Makefiles Add InitBinding function to wxLuaBinding to presort items Test code for sorted wxLuaMethods, doesn't seem to be any faster though. Index: Makefile =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/Makefile,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Makefile 23 May 2007 20:17:24 -0000 1.12 --- Makefile 12 Jun 2007 05:03:17 -0000 1.13 *************** *** 36,40 **** CXX = $(WXCXX) ! APPEXTRADEFS = -I$(WXLUA_DIR) -I$(WXLUA_DIR)/modules -I$(WXLUA_DIR)/modules/lua/include -I$(WXPREFIX)/contrib/include -DLUACALL= TARGET_LIBNAME = lib$(WXBASENAME)_wxlua-$(WXRELEASE) --- 36,42 ---- CXX = $(WXCXX) ! GCC_PROFILE = #-pg ! APPEXTRADEFS = $(GCC_PROFILE) -I$(WXLUA_DIR) -I$(WXLUA_DIR)/modules -I$(WXLUA_DIR)/modules/lua/include -I$(WXPREFIX)/contrib/include -DLUACALL= ! APPEXTRALIBS = $(GCC_PROFILE) TARGET_LIBNAME = lib$(WXBASENAME)_wxlua-$(WXRELEASE) *************** *** 78,82 **** $(TARGET_LIB_SHARED): $(OBJECTS) ! $(CXX) -shared -o $@ $(OBJECTS) cd $(TARGET_LIBDIR) \ && $(RM) $(TARGET_LIB_LINK1) $(TARGET_LIB_LINK2) \ --- 80,84 ---- $(TARGET_LIB_SHARED): $(OBJECTS) ! $(CXX) -shared -o $@ $(OBJECTS) $(APPEXTRALIBS) cd $(TARGET_LIBDIR) \ && $(RM) $(TARGET_LIB_LINK1) $(TARGET_LIB_LINK2) \ Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.70 retrieving revision 1.71 diff -C2 -d -r1.70 -r1.71 *** wxlbind.cpp 12 Jun 2007 00:08:42 -0000 1.70 --- wxlbind.cpp 12 Jun 2007 05:03:17 -0000 1.71 *************** *** 245,249 **** wxLuaBindClass *wxlClass = (wxLuaBindClass *)lua_touserdata(L, lua_upvalueindex(1)); - //bool tracked = false; long key = -1; --- 245,248 ---- *************** *** 254,265 **** wxCHECK_MSG(key != 0, 0, wxT("NULL user data in wxluabind_garbageCollect")); - //tracked = wxlState.RemoveTrackedObject((void*)key, true); wxlState.RemoveDerivedMethod((void*)key); } - //wxPrintf(wxT("wxluabind_garbageCollect - '%s' tag %d lua %d key %ld tracked %d return value %d\n"), - // lua2wx(wxlClass ? wxlClass->name : "").c_str(), wxlClass ? *wxlClass->class_tag : 0, (int)L, key, (int)tracked, retVal); - return 0; } --- 253,260 ---- *************** *** 270,276 **** // 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 the create a wxLua function object ! // onto the lua stack, setting its tag so that the function tag of the object ! // will be called to invoke the function. // ---------------------------------------------------------------------------- --- 265,271 ---- // 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 it. // ---------------------------------------------------------------------------- *************** *** 297,315 **** const char *name = NULL; - // debugging code for the table function, see print statement below - //int init_isuserdata = lua_isuserdata(L, 1); - //int init_islightuserdata = lua_islightuserdata(L, 1); - //int init_ttag = wxlState.ttag(1); - //int init_class_tag = wxlClass ? *wxlClass->class_tag : -1; - if ((wxlClass != NULL) && wxlua_iswxuserdata(L, 1) && (wxlState.ttag(1) == *wxlClass->class_tag)) { void *pObject = wxlState.ttouserdata(1); ! name = lua_tostring(L, 2); // make a copy of the string ! callbase = name[0] == '_'; if (callbase) ! name++; // skip past "_"FunctionName else { --- 292,304 ---- const char *name = NULL; if ((wxlClass != NULL) && wxlua_iswxuserdata(L, 1) && (wxlState.ttag(1) == *wxlClass->class_tag)) { void *pObject = wxlState.ttouserdata(1); ! name = lua_tostring(L, 2); // name of the __index method called in lua ! callbase = (name[0] == '_'); if (callbase) ! name++; // skip past "_"[FunctionName] else { *************** *** 318,322 **** { found = true; ! result = 1; } } --- 307,311 ---- { found = true; ! result = 1; // the function for lua to call } } *************** *** 331,335 **** found = true; lua_remove(L, 2); // remove the name of the function ! result = (*wxlMethod->funcs[0].func)(L); } else --- 320,324 ---- found = true; lua_remove(L, 2); // remove the name of the function ! result = (*wxlMethod->funcs[0].func)(L); // always run 0th func, is main func or overload func } else *************** *** 337,342 **** found = true; result = 1; ! wxLuaFunction *pFunction = new wxLuaFunction(wxlMethod, wxlClass, pObject); ! wxlState.tpushusertag(pFunction, wxlState.GetwxLuaFunctionTag()); } } --- 326,331 ---- found = true; result = 1; ! wxLuaFunction *wxlFunc = new wxLuaFunction(wxlMethod, wxlClass, pObject); ! wxlState.tpushusertag(wxlFunc, wxlState.GetwxLuaFunctionTag()); } } *************** *** 354,358 **** if ((wxlMethod != NULL) && WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_METHOD)) ! //wxlMethod->funcs && (wxlMethod->funcs->minargs == 0) && //(wxlMethod->funcs->maxargs == 0)) { --- 343,347 ---- if ((wxlMethod != NULL) && WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_METHOD)) ! //wxlMethod->funcs && (wxlMethod->funcs->minargs == 0) && // let it error out //(wxlMethod->funcs->maxargs == 0)) { *************** *** 368,375 **** } - //if (lua2wx(name).Find(wxT("OnBeginDocument")) != -1) - // wxPrintf(wxT("wxluabind_getTableFunc func '%s' wxlClass %d '%s', userdata %d, lightuserdata %d, ttag %d, class_tag %d lua_State %d wxLuaStateRefData %d call base %d\n"), - // lua2wx(name).c_str(), (long)wxlClass, wxlClass ? lua2wx(wxlClass->name).c_str() : wxT(""), init_isuserdata, init_islightuserdata, init_ttag, init_class_tag, (long)L, (long)wxlState.GetRefData(), (int)wxlState.GetCallBaseClassFunction()); - if (!found) wxlState.terror(wxString::Format(_("wxLua: Attempt to call an invalid method '%s'."), lua2wx(name).c_str())); --- 357,360 ---- *************** *** 383,387 **** // Called by LUA to find the method that corresponds to a given method name. // The class to lookup is in an upvalue. (settable tag method). - // todo: Handling of properties // ---------------------------------------------------------------------------- --- 368,371 ---- *************** *** 395,400 **** bool found = false; - //wxPrintf(wxT("wxluabind_setTableFunc '%s'\n"), lua2wx(name).c_str()); - if ((wxlClass != NULL) && wxlua_iswxuserdata(L, 1) && (wxlState.ttag(1) == *wxlClass->class_tag)) { --- 379,382 ---- *************** *** 417,424 **** memcpy(str+3, name, len+1); // include terminating NULL - //wxPrintf(wxT("'%s' %d\n"), lua2wx(str).c_str(), lua_gettop(L)); - //wxLuaCheckStack stk(L, wxT("wxluabind_setTableFunc")); - //stk.DumpStack(); - wxlMethod = wxLuaBinding::GetClassMethod(wxlClass, str); if ((wxlMethod != NULL) && WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_METHOD)) --- 399,402 ---- *************** *** 441,450 **** } static int wxluabind_checkremovetable = 0; int wxluabind_removetableforcall(lua_State* L, bool only_check) { ! //void* p = (void *)lua_tocfunction(L, lua_upvalueindex(1)); ! void* p = (void *)lua_touserdata(L, lua_upvalueindex(1)); if (!only_check && (p == &wxluabind_checkremovetable)) lua_remove(L, 1); --- 419,431 ---- } + // 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(1)); // lightuserdata if (!only_check && (p == &wxluabind_checkremovetable)) lua_remove(L, 1); *************** *** 454,470 **** // ---------------------------------------------------------------------------- ! // Function to compare to events by eventType // ---------------------------------------------------------------------------- ! int wxLuaEventListCompareFn(const void *p1, const void *p2) { ! return (*((const wxLuaBindEvent *) p1)->eventType) - (*((const wxLuaBindEvent *) p2)->eventType); } ! // ---------------------------------------------------------------------------- ! // Function to compare the class tag of two classes ! // ---------------------------------------------------------------------------- ! int wxLuaClassListCompareByTag(const void *p1, const void *p2) { ! return (*((const wxLuaBindClass *) p1)->class_tag) - (*((const wxLuaBindClass *) p2)->class_tag); } --- 435,498 ---- // ---------------------------------------------------------------------------- ! // Functions to compare binding structs using qsort and bsearch // ---------------------------------------------------------------------------- ! ! // Function to compare to wxLuaBindEvents by eventType ! int wxLuaBindEventArrayCompareFn(const void *p1, const void *p2) { ! return (*((const wxLuaBindEvent*)p1)->eventType) - (*((const wxLuaBindEvent*)p2)->eventType); ! } ! // Function to compare to wxLuaBindDefines by name ! int wxLuaBindDefineArrayCompareFn(const void *p1, const void *p2) ! { ! return strcmp(((const wxLuaBindDefine*)p1)->name, ((const wxLuaBindDefine*)p2)->name); ! } ! // Function to compare to wxLuaBindStrings by name ! int wxLuaBindStringArrayCompareFn(const void *p1, const void *p2) ! { ! return strcmp(((const wxLuaBindString*)p1)->name, ((const wxLuaBindString*)p2)->name); } + // Function to compare to wxLuaBindObjects by name + int wxLuaBindObjectArrayCompareFn(const void *p1, const void *p2) + { + return strcmp(((const wxLuaBindObject*)p1)->name, ((const wxLuaBindObject*)p2)->name); + } + // Function to compare to wxLuaBindMethods by name + int wxLuaBindMethodArrayCompareFnInit(const void *p1, const void *p2) + { + int v = strcmp(((const wxLuaBindMethod*)p1)->name, ((const wxLuaBindMethod*)p2)->name); + if (v == 0) + v = ((const wxLuaBindMethod*)p1)->type - ((const wxLuaBindMethod*)p2)->type; ! return v; ! } ! int wxLuaBindMethodArrayCompareFnGet(const void *p1, const void *p2) { ! int v = strcmp(((const wxLuaBindMethod*)p1)->name, ((const wxLuaBindMethod*)p2)->name); ! if (v == 0) ! { ! // get methods are either WXLUAMETHOD_METHOD or WXLUAMETHOD_GETPROP ! // and they can't both have the same names so either type will work ! int t1 = 0xFF & ((const wxLuaBindMethod*)p1)->type; ! int t2 = 0xFF & ((const wxLuaBindMethod*)p2)->type; ! int t12 = (t1 & t2); ! if ((t12 == WXLUAMETHOD_METHOD) || (t12 == WXLUAMETHOD_GETPROP) || ! (t12 == WXLUAMETHOD_METHOD|WXLUAMETHOD_GETPROP)) ! return 0; ! ! v = t1 - t2; ! } ! ! return v; ! } ! // Function to compare the wxLuaBindClasses by name ! int wxLuaBindClassArrayCompareFn(const void *p1, const void *p2) ! { ! return strcmp(((const wxLuaBindClass*)p1)->name, ((const wxLuaBindClass*)p2)->name); ! } ! // Function to compare the wxLuaBindClasses by class_tag ! int wxLuaBindClassArrayCompareByTag(const void *p1, const void *p2) ! { ! return (*((const wxLuaBindClass*)p1)->class_tag) - (*((const wxLuaBindClass*)p2)->class_tag); } *************** *** 480,483 **** --- 508,512 ---- m_classCount(0), m_classArray(NULL), m_defineCount(0), m_defineArray(NULL), + m_stringCount(0), m_stringArray(NULL), m_eventCount(0), m_eventArray(NULL), m_objectCount(0), m_objectArray(NULL), *************** *** 490,493 **** --- 519,550 ---- } + void wxLuaBinding::InitBinding() + { + // Sort all the bindings by something useful + if (m_classArray && (m_classCount > 0)) + { + qsort(m_classArray, m_classCount, sizeof(wxLuaBindClass), wxLuaBindClassArrayCompareFn); + + wxLuaBindClass* wxlClass = m_classArray; + for (size_t i = 0; i < m_classCount; ++i, ++wxlClass) + { + qsort(wxlClass->methods, wxlClass->methods_n, sizeof(wxLuaBindMethod), wxLuaBindMethodArrayCompareFnInit); + } + } + + if (m_defineArray && (m_defineCount > 0)) + qsort(m_defineArray, m_defineCount, sizeof(wxLuaBindDefine), wxLuaBindDefineArrayCompareFn); + + if (m_stringArray && (m_stringCount > 0)) + qsort(m_stringArray, m_stringCount, sizeof(wxLuaBindString), wxLuaBindStringArrayCompareFn); + + // sort by event type for fastest lookup + if (m_eventArray && (m_eventCount > 0)) + qsort(m_eventArray, m_eventCount, sizeof(wxLuaBindEvent), wxLuaBindEventArrayCompareFn); + + if (m_objectArray && (m_objectCount > 0)) + qsort(m_objectArray, m_objectCount, sizeof(wxLuaBindObject), wxLuaBindObjectArrayCompareFn); + } + void wxLuaBinding::RegisterBinding(const wxLuaState& wxlState, bool registerTypes) { *************** *** 499,506 **** --- 556,565 ---- // create a global table for the namespace if it doesn't already exist + // Note: we have to do it a second time to set the table RegisterFunctions created lua_getglobal(L, wx2lua(m_nameSpace)); if (!lua_istable(L, -1)) { + // The first time this namespace is used we need to create it lua_pop(L, 1); // pop the nil value *************** *** 510,523 **** } else ! lua_pop(L, 1); ! lua_pop(L, 1); } ! void wxLuaBinding::UnRegisterBinding(lua_State* L) { ! lua_pushstring(L, wx2lua(m_nameSpace)); ! lua_pushnil(L); ! lua_rawset(L, LUA_GLOBALSINDEX); } --- 569,583 ---- } else ! lua_pop(L, 1); // pop the already created namespace table ! lua_pop(L, 1); // pop the table created by RegisterFunctions } ! void wxLuaBinding::UnRegisterBinding(const wxLuaState& wxlState_) { ! wxLuaState wxlState(wxlState_); // unconst the state ! wxlState.lua_PushString(m_nameSpace); ! wxlState.lua_PushNil(); ! wxlState.lua_RawSet(LUA_GLOBALSINDEX); } *************** *** 525,529 **** { wxCHECK_MSG(wxlState_.Ok(), 0, wxT("Invalid wxLuaState")); ! wxLuaState wxlState(wxlState_); if (!registerTypes && !m_bindings_registered) --- 585,589 ---- { wxCHECK_MSG(wxlState_.Ok(), 0, wxT("Invalid wxLuaState")); ! wxLuaState wxlState(wxlState_); // unconst the state if (!registerTypes && !m_bindings_registered) *************** *** 599,603 **** lua_rawset(L, -3); - m_bindings_registered = true; --- 659,662 ---- *************** *** 630,634 **** for (size_t i_class = 0; i_class < m_classCount; ++i_class, ++wxlClass) { - // Create a new tag if registering types, else use tag already set if (registerTypes) --- 689,692 ---- *************** *** 641,645 **** // store a lookup table for the class tags to wxLuaBindClass structs ! wxlua_tget(L, *wxlClass->class_tag); lua_pushstring(L, "wxLuaBindClass"); lua_pushlightuserdata(L, (void *)wxlClass); --- 699,703 ---- // store a lookup table for the class tags to wxLuaBindClass structs ! wxlua_tget(L, iTag); lua_pushstring(L, "wxLuaBindClass"); lua_pushlightuserdata(L, (void *)wxlClass); *************** *** 650,654 **** wxlua_pushstring_wxLuaClasses(L); lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the classes table) - lua_pushstring(L, wxlClass->name); lua_pushlightuserdata(L, (void *)wxlClass); --- 708,711 ---- *************** *** 662,667 **** } - int i_method, method_count = wxlClass->methods_n; - // install the table for the class lua_pushstring(L, wxlClass->name); --- 719,722 ---- *************** *** 676,686 **** } // Install the static functions for the classname table ! for (int i_static_method = 0; i_static_method < method_count; ++i_static_method) { ! if (WXLUA_HASBIT(wxlClass->methods[i_static_method].type, WXLUAMETHOD_STATIC)) { ! lua_pushstring(L, wxlClass->methods[i_static_method].name); ! lua_pushcfunction(L, wxlClass->methods[i_static_method].funcs[0].func); lua_rawset(L, -3); } --- 731,744 ---- } + int method_count = wxlClass->methods_n; + // Install the static functions for the classname table ! wxLuaBindMethod *wxlMethod = wxlClass->methods; ! for (int i_static_method = 0; i_static_method < method_count; ++i_static_method, ++wxlMethod) { ! if (WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_STATIC) && wxlMethod->funcs_n) { ! lua_pushstring(L, wxlMethod->name); ! lua_pushcfunction(L, wxlMethod->funcs[0].func); lua_rawset(L, -3); } *************** *** 689,699 **** // Install public functions like constructors or global functions ! wxLuaBindMethod *wxlMethod = wxlClass->methods; ! for (i_method = 0; i_method < method_count; ++i_method, ++wxlMethod) { ! if (WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_CONSTRUCTOR | WXLUAMETHOD_CFUNCTION)) { #if 1 // C++ class constructors are tables and use the __call metatable to make them "functions" // push name of nested table and create the table or use existing lua_pushstring(L, wxlMethod->name); if (strcmp(wxlMethod->name, wxlClass->name) != 0) --- 747,759 ---- // Install public functions like constructors or global functions ! wxlMethod = wxlClass->methods; ! for (int i_method = 0; i_method < method_count; ++i_method, ++wxlMethod) { ! if (WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_CONSTRUCTOR | WXLUAMETHOD_CFUNCTION) && wxlMethod->funcs_n) { #if 1 // C++ class constructors are tables and use the __call metatable to make them "functions" // push name of nested table and create the table or use existing + // we do it this way since we can have multiple constructors (renamed) + // that are of the same class and so they share the same tag. lua_pushstring(L, wxlMethod->name); if (strcmp(wxlMethod->name, wxlClass->name) != 0) *************** *** 795,801 **** // register all the builtin functions, global C style functions ! for (size_t i_func = 0; i_func < m_functionCount; ++i_func) { - wxLuaBindMethod *wxlMethod = m_functionArray + i_func; lua_pushstring(L, wxlMethod->name); lua_pushcfunction(L, wxlMethod->funcs[0].func); --- 855,861 ---- // register all the builtin functions, global C style functions ! wxLuaBindMethod* wxlMethod = m_functionArray; ! for (size_t i_func = 0; i_func < m_functionCount; ++i_func, ++wxlMethod) { lua_pushstring(L, wxlMethod->name); lua_pushcfunction(L, wxlMethod->funcs[0].func); *************** *** 803,842 **** } - // for backward compatibility - removed, lua has bool now - //lua_pushliteral(L, "FALSE"); - //lua_pushboolean(L, false); - //lua_rawset(L, tableOffset); - //lua_pushliteral(L, "TRUE"); - //lua_pushboolean(L, true); - //lua_rawset(L, tableOffset); - // install the numerical definitions ! for (size_t i_define = 0; i_define < m_defineCount; ++i_define) { ! wxLuaBindDefine *pDefine = m_defineArray + i_define; ! lua_pushstring(L, pDefine->name); ! lua_pushnumber(L, pDefine->value); lua_rawset(L, tableOffset); } // install the strings ! for (size_t i_string = 0; i_string < m_stringCount; ++i_string) { ! wxLuaBindString *pString = m_stringArray + i_string; ! lua_pushstring(L, pString->name); ! lua_pushstring(L, wx2lua(pString->value)); lua_rawset(L, tableOffset); } // install the objects and pointers ! for (size_t i_object = 0; i_object < m_objectCount; ++i_object) { ! wxLuaBindObject *pObject = m_objectArray + i_object; ! lua_pushstring(L, pObject->name); ! if (pObject->objPtr != 0) ! wxlState.tpushusertag(pObject->objPtr, *pObject->class_tag); else ! wxlState.tpushusertag(*pObject->pObjPtr, *pObject->class_tag); lua_rawset(L, tableOffset); --- 863,894 ---- } // install the numerical definitions ! wxLuaBindDefine* wxlDefine = m_defineArray; ! for (size_t i_define = 0; i_define < m_defineCount; ++i_define, ++wxlDefine) { ! lua_pushstring(L, wxlDefine->name); ! lua_pushnumber(L, wxlDefine->value); lua_rawset(L, tableOffset); } // install the strings ! wxLuaBindString *wxlString = m_stringArray; ! for (size_t i_string = 0; i_string < m_stringCount; ++i_string, ++wxlString) { ! lua_pushstring(L, wxlString->name); ! lua_pushstring(L, wx2lua(wxlString->value)); lua_rawset(L, tableOffset); } // install the objects and pointers ! wxLuaBindObject *wxlObject = m_objectArray; ! for (size_t i_object = 0; i_object < m_objectCount; ++i_object, ++wxlObject) { ! lua_pushstring(L, wxlObject->name); ! if (wxlObject->objPtr != 0) ! wxlState.tpushusertag(wxlObject->objPtr, *wxlObject->class_tag); else ! wxlState.tpushusertag(*wxlObject->pObjPtr, *wxlObject->class_tag); lua_rawset(L, tableOffset); *************** *** 844,857 **** // register all the wxevent types ! for (size_t i_event = 0; i_event < m_eventCount; ++i_event) { ! wxLuaBindEvent *pEvent = m_eventArray + i_event; ! lua_pushstring(L, pEvent->name); ! lua_pushnumber(L, *pEvent->eventType); lua_rawset(L, tableOffset); } - - // sort the event list into order for faster lookup. - qsort(m_eventArray, m_eventCount, sizeof(wxLuaBindEvent), wxLuaEventListCompareFn); } --- 896,906 ---- // register all the wxevent types ! wxLuaBindEvent *wxlEvent = m_eventArray; ! for (size_t i_event = 0; i_event < m_eventCount; ++i_event, ++wxlEvent) { ! lua_pushstring(L, wxlEvent->name); ! lua_pushnumber(L, *wxlEvent->eventType); lua_rawset(L, tableOffset); } } *************** *** 877,881 **** const wxLuaBindEvent* wxLuaBinding::GetEvent(wxEventType eventType_) const { ! const int eventType = eventType_; wxLuaBindEvent eventItem = { "", &eventType }; --- 926,931 ---- const wxLuaBindEvent* wxLuaBinding::GetEvent(wxEventType eventType_) const { ! // we've sorted this, see InitBinding() ! const wxEventType eventType = eventType_; wxLuaBindEvent eventItem = { "", &eventType }; *************** *** 884,888 **** m_eventCount, sizeof(wxLuaBindEvent), ! wxLuaEventListCompareFn); return pLuaEvent; } --- 934,938 ---- m_eventCount, sizeof(wxLuaBindEvent), ! wxLuaBindEventArrayCompareFn); return pLuaEvent; } *************** *** 895,901 **** ! const wxLuaBindClass* wxLuaBinding::GetLuaClass(int class_tag) const { ! wxLuaBindClass classItem; classItem.class_tag = &class_tag; --- 945,952 ---- ! const wxLuaBindClass* wxLuaBinding::GetLuaClass(int class_tag_) const { ! int class_tag = class_tag_; ! wxLuaBindClass classItem = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; classItem.class_tag = &class_tag; *************** *** 906,910 **** m_classCount, sizeof(wxLuaBindClass), ! wxLuaClassListCompareByTag); return wxlClass; // maybe NULL if class_tag not found --- 957,961 ---- m_classCount, sizeof(wxLuaBindClass), ! wxLuaBindClassArrayCompareByTag); return wxlClass; // maybe NULL if class_tag not found *************** *** 961,970 **** { wxCHECK_MSG(wxlClass, NULL, wxT("Invalid wxLuaBindClass to find method from.")); int i_method, method_count = wxlClass->methods_n; // find a method in the class, recurse through classes from which this class is derived. ! for (i_method = 0; i_method < method_count; ++i_method) { - wxLuaBindMethod *wxlMethod = wxlClass->methods + i_method; if (WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_METHOD | WXLUAMETHOD_GETPROP) && (strcmp(wxlMethod->name, methodName) == 0)) --- 1012,1036 ---- { wxCHECK_MSG(wxlClass, NULL, wxT("Invalid wxLuaBindClass to find method from.")); + /* + wxLuaBindMethod methodItem = { 0, WXLUAMETHOD_METHOD, 0, 0, 0 }; + methodItem.name = methodName; + + // this relies on LUA allocating tags in ascending order of definition + // if LUA stops doing this, then the search may break. + wxLuaBindMethod *wxlMethod = (wxLuaBindMethod *)bsearch(&methodItem, + wxlClass->methods, + wxlClass->methods_n, + sizeof(wxLuaBindMethod), + wxLuaBindMethodArrayCompareFnGet); + //wxPrintf(wxT("wxlMethod %d\n"), wxlMethod); + */ + + wxLuaBindMethod *wxlMethod = wxlClass->methods; int i_method, method_count = wxlClass->methods_n; + // find a method in the class, recurse through classes from which this class is derived. ! for (i_method = 0; i_method < method_count; ++i_method, ++wxlMethod) { if (WXLUA_HASBIT(wxlMethod->type, WXLUAMETHOD_METHOD | WXLUAMETHOD_GETPROP) && (strcmp(wxlMethod->name, methodName) == 0)) *************** *** 995,999 **** } } - return wxlMethod; } --- 1061,1064 ---- *************** *** 1001,1007 **** if (search_baseclasses && wxlClass->baseclass) ! return GetClassMethod(wxlClass->baseclass, methodName); ! return NULL; } --- 1066,1072 ---- if (search_baseclasses && wxlClass->baseclass) ! wxlMethod = GetClassMethod(wxlClass->baseclass, methodName, search_baseclasses); ! return wxlMethod; } |