From: John L. <jr...@us...> - 2006-11-06 06:11:47
|
Update of /cvsroot/wxlua/wxLua/bindings In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv21901/wxLua/bindings Modified Files: genwxbind.lua Log Message: code cleanup add %wxchkver_x_y_z as replacement for %wxchkverxyz Index: genwxbind.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/genwxbind.lua,v retrieving revision 1.79 retrieving revision 1.80 diff -C2 -d -r1.79 -r1.80 *** genwxbind.lua 1 Nov 2006 23:44:46 -0000 1.79 --- genwxbind.lua 6 Nov 2006 06:11:42 -0000 1.80 *************** *** 33,37 **** typeDefs = {} -- all typedefs read from the interface files ! dataTypes = {} -- all datatypes; int, double, class names dataTypeAttribs = {} -- attributes for data types; unsigned, const functionAttribs = {} -- attributes for functions; static, virtual --- 33,37 ---- typeDefs = {} -- all typedefs read from the interface files ! dataTypes = {} -- all datatypes; int, double, class names, see AllocDataType dataTypeAttribs = {} -- attributes for data types; unsigned, const functionAttribs = {} -- attributes for functions; static, virtual *************** *** 71,77 **** --- 71,79 ---- end + ------------------------------------------------------------------------------- -- Replacement for pairs(table) that sorts them alphabetically, returns iterator -- Code from "Programming in Lua" by Roberto Ierusalimschy -- the input is a lua table and optional comp function (see table.sort) + ------------------------------------------------------------------------------- function pairs_sort(atable, comp_func) local a = {} *************** *** 87,90 **** --- 89,93 ---- end + ------------------------------------------------------------------------------- -- lua 5.1 doesn't have table.getn, but it's pretty useful, add it back -- table.getn only counts integer indexes starting from 1 *************** *** 93,96 **** --- 96,100 ---- -- so that we don't forget to increment it at the end. -- local i = 0; while atable[i+1] do i = i + 1; ... end + ------------------------------------------------------------------------------- if table.getn == nil then function table.getn(atable) *************** *** 103,110 **** end ! -- completely dump the contents of a table -- atable is the input table to dump the contents of -- prefix is a string prefix for debugging purposes -- tablelevel is tracker for recursive calls to DumpTable (do not use initially) function DumpTable(atable, prefix, tablelevel) if prefix == nil then prefix = "" end --- 107,116 ---- end ! ------------------------------------------------------------------------------- ! -- Completely dump the contents of a table -- atable is the input table to dump the contents of -- prefix is a string prefix for debugging purposes -- tablelevel is tracker for recursive calls to DumpTable (do not use initially) + ------------------------------------------------------------------------------- function DumpTable(atable, prefix, tablelevel) if prefix == nil then prefix = "" end *************** *** 124,128 **** --- 130,136 ---- end + ------------------------------------------------------------------------------- -- Make a deep copy of a table, including all sub tables + ------------------------------------------------------------------------------- function TableCopy(atable) local newtable = {} *************** *** 137,144 **** --- 145,156 ---- end + ------------------------------------------------------------------------------- -- A simple function to implement "cond ? A : B", eg "result = iff(cond, A, B)" + ------------------------------------------------------------------------------- function iff(cond, A, B) if cond then return A else return B end end + ------------------------------------------------------------------------------- -- allocate a data type description table (int, double, class...) + ------------------------------------------------------------------------------- function AllocDataType(name, deftype, intrinsic, abstract) local datatype = *************** *** 147,153 **** Name = name, BaseClass = nil, ! Intrinsic = intrinsic, Abstract = abstract, ! Condition = nil, } --- 159,165 ---- Name = name, BaseClass = nil, ! Intrinsic = intrinsic, -- is this data type intrinsicly a number? Abstract = abstract, ! Condition = nil, -- conditions for this data type, eg. wxLUA_USE_xxx } *************** *** 155,158 **** --- 167,173 ---- end + ------------------------------------------------------------------------------- + -- Initialize the data types with standard ones and wxWidget's types + ------------------------------------------------------------------------------- function InitDataTypes() -- Standard C data types *************** *** 218,224 **** dataTypes["LuaFunction"] = AllocDataType("LuaFunction", "wxtypedef", true) ! -- data type attributes that can precede a data type dataTypeAttribs["unsigned"] = true dataTypeAttribs["const"] = true functionAttribs["static"] = true functionAttribs["virtual"] = true --- 233,241 ---- dataTypes["LuaFunction"] = AllocDataType("LuaFunction", "wxtypedef", true) ! -- attributes that can precede a data type dataTypeAttribs["unsigned"] = true dataTypeAttribs["const"] = true + + -- attributes that can precede a function functionAttribs["static"] = true functionAttribs["virtual"] = true *************** *** 226,245 **** end ! -- Fill the input table with ! -- dataTypes["name"] = AllocDataType("name", "builtin", true) ! -- for including with other bindings that need the data types defined ! function GenerateDataTypesFileTable() ! local fileTable = {} ! ! for k, v in pairs_sort(dataTypes) do ! local intrinsic = "false" ! if v.Intrinsic then intrinsic = "true" end ! local s = "dataTypes[\""..k.."\"] = AllocDataType(\""..k.."\", \""..v.DefType.."\", "..intrinsic..")" ! table.insert(fileTable, s) ! end ! ! return fileTable ! end ! function IsDataTypeAbstract(datatype) if dataTypes[datatype] then --- 243,249 ---- end ! ------------------------------------------------------------------------------- ! -- NOT USED ! ------------------------------------------------------------------------------- function IsDataTypeAbstract(datatype) if dataTypes[datatype] then *************** *** 258,262 **** end ! -- get DataType from string function GetDataType(typedefinition) local typeData = SplitString(typedefinition, { " ", "&", "*" }) --- 262,268 ---- end ! ------------------------------------------------------------------------------- ! -- Get the dataTypes[typedefinition] from a string after removing delimiters ! ------------------------------------------------------------------------------- function GetDataType(typedefinition) local typeData = SplitString(typedefinition, { " ", "&", "*" }) *************** *** 273,281 **** end ! -- Decode Declaration function DecodeDecl(decl) ! local attrib = {} local type = nil ! local ptr = {} local cast = 0 --- 279,289 ---- end ! ------------------------------------------------------------------------------- ! -- Decode Declaration of a data type, see DecodeDataType ! ------------------------------------------------------------------------------- function DecodeDecl(decl) ! local attribs = {} local type = nil ! local ptrs = {} local cast = 0 *************** *** 285,288 **** --- 293,301 ---- while typeData[i+1] do i = i + 1 + + if cast < 0 then + print("Error in casting data type, mismatched () '"..decl.."'") + end + if typeData[i] == "(" then cast = cast + 1 *************** *** 291,297 **** elseif cast == 0 then if IsDataTypeAttrib(typeData[i]) then ! attrib[typeData[i]] = typeData[i] elseif (typeData[i] == "[]") or (typeData[i] == "*") or (typeData[i] == "&") then ! table.insert(ptr, typeData[i]) elseif dataTypes[typeData[i]] then type = typeData[i] --- 304,310 ---- elseif cast == 0 then if IsDataTypeAttrib(typeData[i]) then ! attribs[typeData[i]] = typeData[i] elseif (typeData[i] == "[]") or (typeData[i] == "*") or (typeData[i] == "&") then ! table.insert(ptrs, typeData[i]) elseif dataTypes[typeData[i]] then type = typeData[i] *************** *** 303,313 **** if not type then ! print("Cannot find type: "..decl) end ! return attrib, type, ptr end ! -- Decode DataType function DecodeDataType(decl) local attribs = {} --- 316,328 ---- if not type then ! print("Cannot find type: '"..decl.."'") end ! return attribs, type, ptrs end ! ------------------------------------------------------------------------------- ! -- Decode DataType, see TranslateDataType ! ------------------------------------------------------------------------------- function DecodeDataType(decl) local attribs = {} *************** *** 349,352 **** --- 364,370 ---- end + ------------------------------------------------------------------------------- + -- + ------------------------------------------------------------------------------- function TranslateDataType(param) local attribs = {} *************** *** 387,390 **** --- 405,411 ---- end + ------------------------------------------------------------------------------- + -- Get any conditions for this data type + ------------------------------------------------------------------------------- function GetDataTypeCondition(datatype) if dataTypes[datatype] then *************** *** 403,406 **** --- 424,430 ---- end + ------------------------------------------------------------------------------- + -- Is this data type intrinisic, eg is it basically a number + ------------------------------------------------------------------------------- function IsDataTypeIntrinsic(datatype) if dataTypes[datatype] then *************** *** 419,422 **** --- 443,449 ---- end + ------------------------------------------------------------------------------- + -- Is this data type an enum + ------------------------------------------------------------------------------- function IsDataTypeEnum(datatype) if dataTypes[datatype] and (dataTypes[datatype].DefType == "enum") then *************** *** 427,430 **** --- 454,460 ---- end + ------------------------------------------------------------------------------- + -- Is the input to this a data type? + ------------------------------------------------------------------------------- function IsDataType(datatype) if dataTypes[datatype] then *************** *** 433,436 **** --- 463,470 ---- if typeDefs[datatype] then + if not dataTypes[typeDefs[datatype]] then + print("Error - supposed datatype: '"..datatype.."' has typedef = '"..typeDefs[datatype].."' which is not a data type either") + end + return true end *************** *** 549,552 **** --- 583,611 ---- end + -- Find and return an already set condition or for a special set of conditions + -- create a new one and add it to the condition table, else return nil + function FindOrCreateCondition(condition) + local result = nil + + if conditions[condition] then + result = conditions[condition] + elseif string.find(condition, "%wxchkver", 1, 1) then + -- check for conditions like %wxchkver_1_2_3 = wxCHECK_VERSION(1,2,3) + local ver = { 0, 0, 0 } + local n = 1 + for v in string.gmatch(condition, "%d+") do + ver[n] = tonumber(v); n = n + 1 + end + result = string.format("wxCHECK_VERSION(%d,%d,%d)", ver[1], ver[2], ver[3]) + conditions[condition] = result -- cache result + elseif string.find(condition, "wxLUA_USE_", 1, 1) == 1 then + print("Warning unknown wxLUA_USE_XXX tag, maybe a missing condition? '"..condition.."'") + elseif string.find(condition, "wxUSE_", 1, 1) == 1 then + print("Warning unknown wxUSE_XXX tag, maybe a missing condition? '"..condition.."'") + end + + return result + end + -- build condition string using all conditions on condition stack function GetCondition(conditionStack) *************** *** 827,830 **** --- 886,890 ---- conditions["wxUSE_UXTHEME_AUTO"] = "wxUSE_UXTHEME_AUTO" conditions["wxUSE_VALIDATORS"] = "wxUSE_VALIDATORS" + conditions["wxUSE_WAVE"] = "wxUSE_WAVE" conditions["wxUSE_WCHAR_T"] = "wxUSE_WCHAR_T" conditions["wxUSE_WCSRTOMBS"] = "wxUSE_WCSRTOMBS" *************** *** 839,843 **** conditions["wxUSE_ZLIB"] = "wxUSE_ZLIB" ! -- wxLUA_USE_ conditions conditions["wxLUA_USE_FL"] = "wxLUA_USE_FL" conditions["wxLUA_USE_Geometry"] = "wxLUA_USE_Geometry" --- 899,903 ---- conditions["wxUSE_ZLIB"] = "wxUSE_ZLIB" ! -- wxLUA_USE_xxx conditions conditions["wxLUA_USE_FL"] = "wxLUA_USE_FL" conditions["wxLUA_USE_Geometry"] = "wxLUA_USE_Geometry" *************** *** 873,880 **** --- 933,942 ---- conditions["wxLUA_USE_wxDateSpan"] = "wxLUA_USE_wxDateSpan" conditions["wxLUA_USE_wxDateTime"] = "wxLUA_USE_wxDateTime" + conditions["wxLUA_USE_wxDateTimeHolidayAuthority"] = "wxLUA_USE_wxDateTimeHolidayAuthority" conditions["wxLUA_USE_wxDC"] = "wxLUA_USE_wxDC" conditions["wxLUA_USE_wxDialog"] = "wxLUA_USE_wxDialog" conditions["wxLUA_USE_wxDir"] = "wxLUA_USE_wxDir" conditions["wxLUA_USE_wxDirDialog"] = "wxLUA_USE_wxDirDialog" + conditions["wxLUA_USE_wxDisplay"] = "wxLUA_USE_wxDisplay" conditions["wxLUA_USE_wxDragDrop"] = "wxLUA_USE_wxDragDrop" conditions["wxLUA_USE_wxFile"] = "wxLUA_USE_wxFile" *************** *** 1473,1477 **** end elseif not parseState.IsBlockComment then ! if not conditionOperators[tag] and not conditions[tag] and not ignore[tag] then if lineState.Action == "classname" then if not dataTypes[tag] then --- 1535,1539 ---- end elseif not parseState.IsBlockComment then ! if not conditionOperators[tag] and not FindOrCreateCondition(tag) and not ignore[tag] then if lineState.Action == "classname" then if not dataTypes[tag] then *************** *** 1850,1854 **** end ! elseif conditions[tag] then if (lineState.DefType ~= "blockcondition") and not lineState.InLineConditionIf then lineState.InLineConditionIf = true --- 1912,1916 ---- end ! elseif FindOrCreateCondition(tag) then if (lineState.DefType ~= "blockcondition") and not lineState.InLineConditionIf then lineState.InLineConditionIf = true *************** *** 1867,1871 **** end ! lineState.Condition = lineState.Condition..conditions[tag] elseif not ignore[tag] then --- 1929,1933 ---- end ! lineState.Condition = lineState.Condition..FindOrCreateCondition(tag) elseif not ignore[tag] then *************** *** 4905,4911 **** local cache = loadfile(filename) cache() -- run loaded file ! print("loaded datatypes cache file: "..filename) else ! print("unable to load datatypes cache file: "..filename) end end --- 4967,4973 ---- local cache = loadfile(filename) cache() -- run loaded file ! print("Loaded datatypes cache file: "..filename) else ! print("Unable to load datatypes cache file: "..filename) end end *************** *** 4937,4944 **** end - --local fileTable = GenerateDataTypesFileTable() - --for i = 1, table.getn(fileTable) do print(fileTable[i]) end - --WriteTableToFile(interface.filename, fileData, false) - print("Done\n") end --- 4999,5002 ---- |