From: John L. <jr...@us...> - 2006-12-14 01:01:56
|
Update of /cvsroot/wxlua/wxLua/bindings In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv1560/wxLua/bindings Modified Files: genwxbind.lua Log Message: speed up genwxbind.lua add wxLuaBinding::GetBindingName as a unique name to know if it's added Rename *AddToTrackedMemory -> AddTrackedObject since it only tracks wxObjects Rename wxLuaState::AddTrackedEventHandler to AddTrackedCallback and only accept wxLuaCallbacks Rename wxLuaState::AddTrackedDestroyEventHandler to AddTrackedWinDestroyCallback and only accept wxLuaWinDestroyCallbacks Make type evaluation for the bindings more strict Index: genwxbind.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/genwxbind.lua,v retrieving revision 1.89 retrieving revision 1.90 diff -C2 -d -r1.89 -r1.90 *** genwxbind.lua 13 Dec 2006 06:57:48 -0000 1.89 --- genwxbind.lua 14 Dec 2006 01:01:22 -0000 1.90 *************** *** 24,28 **** -- --------------------------------------------------------------------------- ! WXLUA_BINDING_VERSION = 2 -- Used to verify that the bindings are updated -- see modules/wxlua/include/wxldefs.h --- 24,28 ---- -- --------------------------------------------------------------------------- ! WXLUA_BINDING_VERSION = 3 -- Used to verify that the bindings are updated -- see modules/wxlua/include/wxldefs.h *************** *** 61,64 **** --- 61,73 ---- overrideTableUsed = {} -- table set to true if override was used + -- helpers for SplitString to make it faster + + local string_sub = string.sub -- make local so no table lookup + local string_len = string.len + local string_byte = string.byte + + local char_BACKSLASH = string.byte("\\") + local char_DOUBLEQUOTE = string.byte("\"") + -- --------------------------------------------------------------------------- -- CheckRules - check the settings in the rules file for common errors *************** *** 149,153 **** -- --------------------------------------------------------------------------- function AllocDataType(name, deftype, is_number, abstract) ! local datatype = { DefType = deftype, -- number, enum, class, special (special handling) --- 158,162 ---- -- --------------------------------------------------------------------------- function AllocDataType(name, deftype, is_number, abstract) ! dataTypes[name] = { DefType = deftype, -- number, enum, class, special (special handling) *************** *** 159,164 **** Condition = nil, -- conditions for this data type, eg. wxLUA_USE_xxx } - - return datatype end --- 168,171 ---- *************** *** 168,236 **** function InitDataTypes() -- Standard C data types ! dataTypes["bool"] = AllocDataType("bool", "number", true) ! dataTypes["BOOL"] = AllocDataType("BOOL", "number", true) ! dataTypes["double"] = AllocDataType("double", "number", true) ! dataTypes["int"] = AllocDataType("int", "number", true) ! dataTypes["char"] = AllocDataType("char", "number", true) ! dataTypes["float"] = AllocDataType("float", "number", true) ! dataTypes["long"] = AllocDataType("long", "number", true) ! dataTypes["short"] = AllocDataType("short", "number", true) ! dataTypes["size_t"] = AllocDataType("size_t", "number", true) ! dataTypes["time_t"] = AllocDataType("time_t", "number", true) ! dataTypes["unsigned char"] = AllocDataType("unsigned char", "number", true) ! dataTypes["unsigned int"] = AllocDataType("unsigned int", "number", true) ! dataTypes["unsigned long"] = AllocDataType("unsigned long", "number", true) ! dataTypes["unsigned short"] = AllocDataType("unsigned short", "number", true) ! dataTypes["uchar"] = AllocDataType("uchar", "number", true) ! dataTypes["uint"] = AllocDataType("uint", "number", true) ! dataTypes["ulong"] = AllocDataType("ulong", "number", true) ! dataTypes["ushort"] = AllocDataType("ushort", "number", true) ! dataTypes["void"] = AllocDataType("void", "number", true) ! dataTypes["wchar_t"] = AllocDataType("wchar_t", "number", true) -- wxWidgets defined data types ! --dataTypes["wxArtClient"] = AllocDataType("wxString", "special", true) -- treat as wxString ! --dataTypes["wxArtID"] = AllocDataType("wxString", "special", true) ! dataTypes["wxByte"] = AllocDataType("wxByte", "number", true) ! dataTypes["wxChar"] = AllocDataType("wxChar", "number", true) ! dataTypes["wxWord"] = AllocDataType("wxWord", "number", true) ! dataTypes["wxInt8"] = AllocDataType("wxInt8", "number", true) ! dataTypes["wxUint8"] = AllocDataType("wxUint8", "number", true) ! dataTypes["wxInt16"] = AllocDataType("wxInt16", "number", true) ! dataTypes["wxUint16"] = AllocDataType("wxUint16", "number", true) ! dataTypes["wxInt32"] = AllocDataType("wxInt32", "number", true) ! dataTypes["wxUint32"] = AllocDataType("wxUint32", "number", true) ! dataTypes["wxInt64"] = AllocDataType("wxInt64", "number", true) ! dataTypes["wxUint64"] = AllocDataType("wxUint64", "number", true) ! dataTypes["wxFloat32"] = AllocDataType("wxFloat32", "number", true) ! dataTypes["wxFloat64"] = AllocDataType("wxFloat64", "number", true) ! dataTypes["wxDouble"] = AllocDataType("wxDouble", "number", true) ! dataTypes["wxCoord"] = AllocDataType("wxCoord", "number", true) ! dataTypes["wxTextCoord"] = AllocDataType("wxTextCoord", "number", true) ! dataTypes["wxMemorySize"] = AllocDataType("wxMemorySize", "number", true) ! dataTypes["WXTYPE"] = AllocDataType("WXTYPE", "number", true) ! dataTypes["wxWindowID"] = AllocDataType("wxWindowID", "number", true) ! dataTypes["wxEventType"] = AllocDataType("wxEventType", "number", true) ! dataTypes["wxFileOffset"] = AllocDataType("wxFileOffset", "number", true) ! --dataTypes["wxStructStat"] = AllocDataType("wxStructStat", "number", true) -- lua data types ! dataTypes["lua_State"] = AllocDataType("lua_State", "number", false) -- win32 data types ! dataTypes["HANDLE"] = AllocDataType("HANDLE", "number", false) ! dataTypes["DWORD64"] = AllocDataType("DWORD64", "number", true) ! dataTypes["DWORD"] = AllocDataType("DWORD", "number", true) ! dataTypes["PVOID"] = AllocDataType("PVOID", "number", true) ! dataTypes["LPCVOID"] = AllocDataType("LPCVOID", "number", true) ! dataTypes["LPVOID"] = AllocDataType("LPVOID", "number", true) ! dataTypes["LPDWORD"] = AllocDataType("LPDWORD", "number", true) -- "fake" data types that we handle in some more complicated way ! dataTypes["LuaFunction"] = AllocDataType("LuaFunction", "special", true) ! dataTypes["LuaTable"] = AllocDataType("LuaTable", "special", true) ! dataTypes["wxString"] = AllocDataType("wxString", "special", true) ! dataTypes["wxArrayString_FromLuaTable"] = AllocDataType("wxArrayString_FromLuaTable", "special", true) ! dataTypes["wxArrayInt_FromLuaTable"] = AllocDataType("wxArrayInt_FromLuaTable", "special", true) -- attributes that can precede a data type --- 175,243 ---- function InitDataTypes() -- Standard C data types ! AllocDataType("bool", "number", true) ! AllocDataType("BOOL", "number", true) ! AllocDataType("double", "number", true) ! AllocDataType("int", "number", true) ! AllocDataType("char", "number", true) ! AllocDataType("float", "number", true) ! AllocDataType("long", "number", true) ! AllocDataType("short", "number", true) ! AllocDataType("size_t", "number", true) ! AllocDataType("time_t", "number", true) ! AllocDataType("unsigned char", "number", true) ! AllocDataType("unsigned int", "number", true) ! AllocDataType("unsigned long", "number", true) ! AllocDataType("unsigned short", "number", true) ! AllocDataType("uchar", "number", true) ! AllocDataType("uint", "number", true) ! AllocDataType("ulong", "number", true) ! AllocDataType("ushort", "number", true) ! AllocDataType("void", "number", true) ! AllocDataType("wchar_t", "number", true) -- wxWidgets defined data types ! --AllocDataType("wxString", "special", true) -- treat as wxString ! --AllocDataType("wxString", "special", true) ! AllocDataType("wxByte", "number", true) ! AllocDataType("wxChar", "number", true) ! AllocDataType("wxWord", "number", true) ! AllocDataType("wxInt8", "number", true) ! AllocDataType("wxUint8", "number", true) ! AllocDataType("wxInt16", "number", true) ! AllocDataType("wxUint16", "number", true) ! AllocDataType("wxInt32", "number", true) ! AllocDataType("wxUint32", "number", true) ! AllocDataType("wxInt64", "number", true) ! AllocDataType("wxUint64", "number", true) ! AllocDataType("wxFloat32", "number", true) ! AllocDataType("wxFloat64", "number", true) ! AllocDataType("wxDouble", "number", true) ! AllocDataType("wxCoord", "number", true) ! AllocDataType("wxTextCoord", "number", true) ! AllocDataType("wxMemorySize", "number", true) ! AllocDataType("WXTYPE", "number", true) ! AllocDataType("wxWindowID", "number", true) ! AllocDataType("wxEventType", "number", true) ! AllocDataType("wxFileOffset", "number", true) ! --AllocDataType("wxStructStat", "number", true) -- lua data types ! AllocDataType("lua_State", "number", false) -- win32 data types ! AllocDataType("HANDLE", "number", false) ! AllocDataType("DWORD64", "number", true) ! AllocDataType("DWORD", "number", true) ! AllocDataType("PVOID", "number", true) ! AllocDataType("LPCVOID", "number", true) ! AllocDataType("LPVOID", "number", true) ! AllocDataType("LPDWORD", "number", true) -- "fake" data types that we handle in some more complicated way ! AllocDataType("LuaFunction", "special", true) ! AllocDataType("LuaTable", "special", true) ! AllocDataType("wxString", "special", true) ! AllocDataType("wxArrayString_FromLuaTable", "special", true) ! AllocDataType("wxArrayInt_FromLuaTable", "special", true) -- attributes that can precede a data type *************** *** 1151,1154 **** --- 1158,1169 ---- -- --------------------------------------------------------------------------- function SplitString(line, delimiter, keep, stringliterals, lineTable) + if not line then + if lineTable then + print("Error: line is nil in SplitString, "..LineTableErrString(lineTable)) + else + print("Error: line is nil in SplitString") -- let it fail on string.len + end + end + local item = {} local wordStart = -1 *************** *** 1157,1199 **** local escaped = false ! if not line then ! if lineTable then ! print("Error: line is nil in SplitString, "..LineTableErrString(lineTable)) ! else ! print("Error: line is nil in SplitString") -- let it fail on string.len end end local i = 1 ! local len = string.len(line) while i <= len do ! local val = string.sub(line, i) local delim = nil local keepDelim = false if stringliterals then if inStringLiteral then ! if string.sub(val, 1, 1) == "\\" then escaped = not escaped ! else ! if not escaped and (string.sub(val, 1, 1) == "\"") then ! inStringLiteral = false ! end ! escaped = false ! end ! else ! if string.sub(val, 1, 1) == "\"" then ! inStringLiteral = true end end end if not inStringLiteral then ! -- delimiter can be an table of strings ! local d = 0 ! while delimiter[d+1] do ! d = d + 1 ! if string.sub(val, 1, string.len(delimiter[d])) == delimiter[d] then ! delim = delimiter[d] break end --- 1172,1216 ---- local escaped = false ! -- create a list of the lengths of the delimiter strings ! local delimiter_len = {} ! local delimiter_count = #delimiter ! for n = 1, delimiter_count do ! delimiter_len[n] = string_len(delimiter[n]) ! end ! ! -- create a hash table of the keep strings ! local keep_table = {} ! if keep then ! local keep_count = #keep ! for n = 1, keep_count do ! keep_table[keep[n]] = true end end local i = 1 ! local len = string_len(line) while i <= len do ! local val = string_sub(line, i) local delim = nil local keepDelim = false if stringliterals then + local char = string_byte(val) if inStringLiteral then ! if char == char_BACKSLASH then escaped = not escaped ! elseif not escaped and (char == char_DOUBLEQUOTE) then ! inStringLiteral = false end + elseif char == char_DOUBLEQUOTE then + inStringLiteral = true end end if not inStringLiteral then ! -- delimiter can be a table of strings ! for n = 1, delimiter_count do ! if string_sub(val, 1, delimiter_len[n]) == delimiter[n] then ! delim = delimiter[n] break end *************** *** 1201,1213 **** -- keep delimiter in list ! if delim and keep then ! local d = 0 ! while keep[d+1] do ! d = d + 1 ! if delim == keep[d] then ! keepDelim = true ! break ! end ! end end end --- 1218,1223 ---- -- keep delimiter in list ! if delim and keep and keep_table[delim] then ! keepDelim = true end end *************** *** 1222,1226 **** else if wordStart ~= -1 then ! table.insert(item, string.sub(line, wordStart, wordEnd)) end if keepDelim then --- 1232,1236 ---- else if wordStart ~= -1 then ! table.insert(item, string_sub(line, wordStart, wordEnd)) end if keepDelim then *************** *** 1229,1238 **** wordStart = -1 ! i = i + string.len(delim) end end if (wordStart ~= -1) then ! table.insert(item, string.sub(line, wordStart)) end --- 1239,1248 ---- wordStart = -1 ! i = i + string_len(delim) end end if (wordStart ~= -1) then ! table.insert(item, string_sub(line, wordStart)) end *************** *** 1380,1383 **** --- 1390,1395 ---- local interfaceList = {} + local time1 = os.time() + -- read all interface files and build DataType Table local idx = 0 *************** *** 1398,1401 **** --- 1410,1417 ---- end + local time2 = os.time() + print("Timing: BuildDataTypeTable "..os.difftime(time2, time1).." seconds.") + time1 = time2 + local idx = 0 while interfaceFileDataList[idx+1] do *************** *** 1420,1423 **** --- 1436,1442 ---- end + local time2 = os.time() + print("Timing: ParseData "..os.difftime(time2, time1).." seconds.") + return interfaceList end *************** *** 1427,1430 **** --- 1446,1450 ---- -- --------------------------------------------------------------------------- function WriteWrapperFiles(interfaceList) + local time1 = os.time() -- generatelanguage binding, binding is stored in objectList *************** *** 1443,1446 **** --- 1463,1469 ---- end + local time2 = os.time() + --print("Timing: GenerateLuaLanguageBinding and GenerateBindingFileTable "..os.difftime(time2, time1).." seconds.") + local fileData = GenerateHookHeaderFileTable() WriteTableToFile(GetCPPHeaderFileName(hook_cpp_header_filename), fileData, false) *************** *** 1544,1549 **** local lineState = { ! ClassName = nil, ! Action = nil } --- 1567,1572 ---- local lineState = { ! ClassName = nil, ! Action = nil } *************** *** 1577,1618 **** end end ! elseif not in_block_comment then ! if not conditionOperators[tag] and (not FindOrCreateCondition(tag)) and (not ignore[tag]) then ! if lineState.Action == "classname" then ! if not dataTypes[tag] then ! dataTypes[tag] = AllocDataType(tag, "class", false) ! end ! lineState.ClassName = tag ! lineState.Action = "classcomma" ! elseif lineState.Action == "classcomma" then ! if tag ~= "," then ! print("WARNING : Expected comma (',') after class name : '"..lineState.ClassName.."' in "..LineTableErrString(lineTable)) ! end ! lineState.Action = "classbase" ! elseif lineState.Action == "classbase" then ! if not dataTypes[tag] then ! dataTypes[tag] = AllocDataType(tag, "class", false) ! end ! -- set class's BaseClass ! if not dataTypes[lineState.ClassName].BaseClass then ! dataTypes[lineState.ClassName].BaseClass = tag ! end ! lineState.Action = "classcomma" ! elseif lineState.Action == "structname" then ! if not dataTypes[tag] then ! dataTypes[tag] = AllocDataType(tag, "struct", false) ! end ! lineState.Action = nil ! elseif lineState.Action == "enumname" then ! if not dataTypes[tag] then ! dataTypes[tag] = AllocDataType(tag, "enum", true) ! end ! lineState.Action = nil end end end --- 1600,1642 ---- end end ! elseif (not in_block_comment) and lineState.Action and ! (not conditionOperators[tag]) and (not FindOrCreateCondition(tag)) and ! (not ignore[tag]) then ! if lineState.Action == "classname" then ! if not dataTypes[tag] then ! AllocDataType(tag, "class", false) ! end ! lineState.ClassName = tag ! lineState.Action = "classcomma" ! elseif lineState.Action == "classcomma" then ! if tag ~= "," then ! print("WARNING : Expected comma (',') after class name : '"..lineState.ClassName.."' in "..LineTableErrString(lineTable)) ! end ! lineState.Action = "classbase" ! elseif lineState.Action == "classbase" then ! if not dataTypes[tag] then ! AllocDataType(tag, "class", false) ! end ! -- set class's BaseClass ! if not dataTypes[lineState.ClassName].BaseClass then ! dataTypes[lineState.ClassName].BaseClass = tag ! end ! lineState.Action = "classcomma" ! elseif lineState.Action == "structname" then ! if not dataTypes[tag] then ! AllocDataType(tag, "struct", false) ! end ! lineState.Action = nil ! elseif lineState.Action == "enumname" then ! if not dataTypes[tag] then ! AllocDataType(tag, "enum", true) end + + lineState.Action = nil end end *************** *** 3611,3615 **** CommentBindingTable(codeList, " // add to tracked memory list\n") ! -- Un 'const' AddToTrackedMemoryList local returnCast = memberTypeWithAttrib if string.sub(returnCast, 1, 6) == "const " then --- 3635,3639 ---- CommentBindingTable(codeList, " // add to tracked memory list\n") ! -- Un 'const' AddTrackedObject local returnCast = memberTypeWithAttrib if string.sub(returnCast, 1, 6) == "const " then *************** *** 3617,3625 **** end ! table.insert(codeList, " wxLua_AddToTrackedMemoryList(wxlState, ("..returnCast..")returns);\n") elseif parseObject.HasClassInfo then CommentBindingTable(codeList, " // add to tracked window list\n") table.insert(codeList, " if (returns && returns->IsKindOf(CLASSINFO(wxWindow)))\n") ! table.insert(codeList, " wxlState.AddToTrackedWindowList((wxWindow*)returns);\n") end --- 3641,3649 ---- end ! table.insert(codeList, " wxLua_AddTrackedObject(wxlState, ("..returnCast..")returns);\n") elseif parseObject.HasClassInfo then CommentBindingTable(codeList, " // add to tracked window list\n") table.insert(codeList, " if (returns && returns->IsKindOf(CLASSINFO(wxWindow)))\n") ! table.insert(codeList, " wxlState.AddTrackedWindow((wxWindow*)returns);\n") end *************** *** 3684,3688 **** CommentBindingTable(codeList, " // add the new object to the tracked memory list\n") ! -- Un 'const' AddToTrackedMemoryList local returnCast = memberTypeWithAttrib if string.sub(returnCast, 1, 6) == "const " then --- 3708,3712 ---- CommentBindingTable(codeList, " // add the new object to the tracked memory list\n") ! -- Un 'const' AddTrackedObject local returnCast = memberTypeWithAttrib if string.sub(returnCast, 1, 6) == "const " then *************** *** 3690,3694 **** end ! table.insert(codeList, " wxLua_AddToTrackedMemoryList(wxlState, ("..returnCast..")returns);\n") elseif (not member.IsOperator) and (memberPtr == "&") and (memberType ~= "wxString") then table.insert(codeList, " returns = &"..functor..";\n") --- 3714,3718 ---- end ! table.insert(codeList, " wxLua_AddTrackedObject(wxlState, ("..returnCast..")returns);\n") elseif (not member.IsOperator) and (memberPtr == "&") and (memberType ~= "wxString") then table.insert(codeList, " returns = &"..functor..";\n") *************** *** 3855,3859 **** table.insert(codeList, " if (self != 0)\n") ! table.insert(codeList, " wxlState.RemoveTrackedMemory(self);\n") table.insert(codeList, " return 0;\n") table.insert(codeList, "}\n\n") --- 3879,3883 ---- table.insert(codeList, " if (self != 0)\n") ! table.insert(codeList, " wxlState.RemoveTrackedObject(self);\n") table.insert(codeList, " return 0;\n") table.insert(codeList, "}\n\n") *************** *** 3882,3886 **** table.insert(codeList, " if (self != 0)\n") ! table.insert(codeList, " if (wxlState.RemoveTrackedMemory(self))\n") table.insert(codeList, " { // if removed, reset the tag so that gc() is not called on this object.\n") table.insert(codeList, " lua_pushnil(L);\n") --- 3906,3910 ---- table.insert(codeList, " if (self != 0)\n") ! table.insert(codeList, " if (wxlState.RemoveTrackedObject(self))\n") table.insert(codeList, " { // if removed, reset the tag so that gc() is not called on this object.\n") table.insert(codeList, " lua_pushnil(L);\n") *************** *** 4212,4216 **** table.insert(fileData, ""..hook_cpp_binding_classname.."::"..hook_cpp_binding_classname.."() : wxLuaBinding()\n") table.insert(fileData, "{\n") ! table.insert(fileData, " m_nameSpace = wxT(\""..hook_lua_namespace.."\");\n") table.insert(fileData, " m_classList = "..hook_cpp_class_funcname.."(m_classCount);\n") table.insert(fileData, " m_defineList = "..hook_cpp_define_funcname.."(m_defineCount);\n") --- 4236,4241 ---- table.insert(fileData, ""..hook_cpp_binding_classname.."::"..hook_cpp_binding_classname.."() : wxLuaBinding()\n") table.insert(fileData, "{\n") ! table.insert(fileData, " m_bindingName = wxT(\""..hook_cpp_namespace.."\");\n") ! table.insert(fileData, " m_nameSpace = wxT(\""..hook_lua_namespace.."\");\n") table.insert(fileData, " m_classList = "..hook_cpp_class_funcname.."(m_classCount);\n") table.insert(fileData, " m_defineList = "..hook_cpp_define_funcname.."(m_defineCount);\n") *************** *** 4871,4874 **** --- 4896,4901 ---- function main() + local time1 = os.time() + -- load rules file if not rulesFilename then *************** *** 4919,4922 **** --- 4946,4950 ---- end + print("Timing: "..os.difftime(os.time(), time1).." seconds.") print("Done\n") end |