2
0

create_lua_library.py 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. import sys
  2. import CppHeaderParser
  3. import os
  4. import errno
  5. import re
  6. from zipfile import *
  7. import fnmatch
  8. import re
  9. def mkdir_p(path): # Same effect as mkdir -p, create dir and all necessary parent dirs
  10. try:
  11. os.makedirs(path)
  12. except OSError as e:
  13. if e.errno == errno.EEXIST: # Dir already exists; not really an error
  14. pass
  15. else: raise
  16. def template_returnPtrLookupArray(prefix, className, ptr):
  17. out = ""
  18. out += "%sfor i=1,count(%s) do\n" % (prefix, ptr)
  19. out += "%s\tlocal __c = _G[%s](\"__skip_ptr__\")\n" % (prefix, className)
  20. out += "%s\t__c.__ptr = %s[i]\n" % (prefix, ptr)
  21. out += "%s\t%s[i] = __c\n" % (prefix, ptr)
  22. out += "%send\n" % (prefix)
  23. out += "%sreturn %s\n" % (prefix,ptr)
  24. return out
  25. # Note we expect className to be a valid string
  26. def template_returnPtrLookup(prefix, className, ptr):
  27. out = ""
  28. out += "%slocal __c = _G[%s](\"__skip_ptr__\")\n" % (prefix, className)
  29. out += "%s__c.__ptr = %s\n" % (prefix, ptr)
  30. out += "%sreturn __c\n" % (prefix)
  31. return out
  32. def template_quote(str):
  33. return "\"%s\"" % str;
  34. def cleanDocs(docs):
  35. return docs.replace("/*", "").replace("*/", "").replace("*", "").replace("\n", "").replace("\r", "").replace("::", ".").replace("\t", "")
  36. def toLuaType(t):
  37. return t.replace("void", "nil").replace("int", "Integer").replace("bool", "Boolean")
  38. # FIXME: Some "unsigned int *" functions are still being generated on the polycode API?
  39. def typeFilter(ty):
  40. ty = ty.replace("Polycode::", "")
  41. ty = ty.replace("std::", "")
  42. ty = ty.replace("const", "")
  43. ty = ty.replace("inline", "")
  44. ty = ty.replace("static", "")
  45. ty = ty.replace("virtual", "")
  46. ty = ty.replace("&", "")
  47. ty = re.sub(r'^.*\sint\s*$', 'int', ty) # eg "unsigned int"
  48. ty = re.sub(r'^.*\slong\s*$', 'int', ty)
  49. ty = re.sub(r'^.*\sfloat\s*$', 'Number', ty)
  50. ty = re.sub(r'^.*\sdouble\s*$', 'Number', ty) # eg "long double"
  51. ty = ty.replace("unsigned", "int")
  52. ty = ty.replace("long", "int")
  53. ty = ty.replace("float", "Number")
  54. ty = ty.replace("double", "Number")
  55. ty = ty.replace(" ", "") # Not very safe!
  56. return ty
  57. def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, apiPath, apiClassPath, includePath, sourcePath, inheritInModuleFiles):
  58. wrappersHeaderOut = "" # Def: Global C++ *LUAWrappers.h
  59. cppRegisterOut = "" # Def: Global C++ *LUA.cpp
  60. cppLoaderOut = "" # Def: Global C++ *LUA.cpp
  61. luaDocOut = ""
  62. luaIndexOut = "" # Def: Global Lua everything-gets-required-from-this-file file
  63. # Header boilerplate for wrappersHeaderOut and cppRegisterOut
  64. cppRegisterOut += "#include \"%sLUA.h\"\n" % (prefix)
  65. cppRegisterOut += "#include \"%sLUAWrappers.h\"\n" % (prefix)
  66. cppRegisterOut += "#include \"PolyCoreServices.h\"\n\n"
  67. cppRegisterOut += "using namespace Polycode;\n\n"
  68. cppRegisterOut += "int luaopen_%s(lua_State *L) {\n" % (prefix)
  69. if prefix != "Polycode":
  70. cppRegisterOut += "CoreServices *inst = (CoreServices*) *((void**)lua_touserdata(L, 1));\n"
  71. cppRegisterOut += "CoreServices::setInstance(inst);\n"
  72. cppRegisterOut += "\tstatic const struct luaL_reg %sLib [] = {" % (libSmallName)
  73. wrappersHeaderOut += "#pragma once\n\n"
  74. wrappersHeaderOut += "extern \"C\" {\n\n"
  75. wrappersHeaderOut += "#include <stdio.h>\n"
  76. wrappersHeaderOut += "#include \"lua.h\"\n"
  77. wrappersHeaderOut += "#include \"lualib.h\"\n"
  78. wrappersHeaderOut += "#include \"lauxlib.h\"\n"
  79. wrappersHeaderOut += "} // extern \"C\" \n\n"
  80. luaDocOut += "<?xml version=\"1.0\" ?>\n"
  81. luaDocOut += "<docs>\n"
  82. luaDocOut += "<classes>\n"
  83. # Get list of headers to create bindings from
  84. inputPathIsDir = os.path.isdir(inputPath)
  85. if inputPathIsDir:
  86. files = os.listdir(inputPath)
  87. else:
  88. files = []
  89. with open(inputPath) as f:
  90. for line in f.readlines():
  91. files.append(line.strip()) # Strip whitespace, path/
  92. filteredFiles = []
  93. for fileName in files:
  94. if inputPathIsDir:
  95. fileName = "%s/%s" % (inputPath, fileName)
  96. head, tail = os.path.split(fileName)
  97. ignore = ["PolyGLSLProgram", "PolyGLSLShader", "PolyGLSLShaderModule", "PolyWinCore", "PolyCocoaCore", "PolyAGLCore", "PolySDLCore", "Poly_iPhone", "PolyGLES1Renderer", "PolyGLRenderer", "tinyxml", "tinystr", "OpenGLCubemap", "PolyiPhoneCore", "PolyGLES1Texture", "PolyGLTexture", "PolyGLVertexBuffer", "PolyThreaded", "PolyGLHeaders", "GLee", "PolyPeer", "PolySocket", "PolyClient", "PolyServer", "PolyServerWorld", "OSFILE", "OSFileEntry", "OSBasics", "PolyLogger"]
  98. if tail.split(".")[1] == "h" and tail.split(".")[0] not in ignore:
  99. filteredFiles.append(fileName)
  100. wrappersHeaderOut += "#include \"%s\"\n" % (tail)
  101. wrappersHeaderOut += "\nusing namespace std;\n\n"
  102. wrappersHeaderOut += "\nnamespace Polycode {\n\n"
  103. # list of classes that don't get the garbage collection in their meta table
  104. disable_gc = ["Entity", "ScreenEntity", "ScreenShape", "ScreenMesh", "ScreenLabel", "SceneLabel", "SceneMesh", "Screen", "Scene", "Texture", "Image", "Camera", "ScreenParticleEmitter", "SceneParticleEmitter", "Mesh", "Vertex", "Polygon", "Polycode::Polygon", "Material", "ScenePrimitive", "SceneLine", "SceneLight", "SceneSound", "ScreenImage", "SceneEntity"]
  105. # Special case: If we are building the Polycode library itself, inject the LuaEventHandler class.
  106. # Note: so that event callbacks can work, any object inheriting from EventHandler will secretly
  107. # be modified to actually inherit from LuaEventHandler instead.
  108. if prefix == "Polycode":
  109. wrappersHeaderOut += "class LuaEventHandler : public EventHandler {\n"
  110. wrappersHeaderOut += "public:\n"
  111. wrappersHeaderOut += " LuaEventHandler() : EventHandler() {}\n"
  112. wrappersHeaderOut += " void handleEvent(Event *e) {\n"
  113. wrappersHeaderOut += " lua_getfield(L, LUA_GLOBALSINDEX, \"EventHandler\" );\n"
  114. wrappersHeaderOut += " lua_getfield(L, -1, \"__handleEvent\");\n"
  115. wrappersHeaderOut += " lua_rawgeti( L, LUA_REGISTRYINDEX, wrapperIndex );\n"
  116. wrappersHeaderOut += " PolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));\n"
  117. wrappersHeaderOut += " *userdataPtr = (PolyBase*)e;\n"
  118. # wrappersHeaderOut += " lua_getfield (L, LUA_GLOBALSINDEX, \"__customError\");\n"
  119. # wrappersHeaderOut += " int errH = lua_gettop(L);\n"
  120. # wrappersHeaderOut += " lua_pcall(L, 2, 0, errH);\n"
  121. wrappersHeaderOut += " lua_pcall(L, 2, 0, 0);\n"
  122. wrappersHeaderOut += " }\n"
  123. wrappersHeaderOut += " int wrapperIndex;\n"
  124. wrappersHeaderOut += " lua_State *L;\n"
  125. wrappersHeaderOut += "};\n\n"
  126. # Iterate, process each input file
  127. for fileName in filteredFiles:
  128. # "Package owned" classes that ship with Polycode
  129. inheritInModule = ["PhysicsSceneEntity", "CollisionScene", "CollisionSceneEntity"]
  130. # A file or comma-separated list of files can be given to specify classes which are "package owned"
  131. # and should not be inherited out of Polycode/. The files should contain one class name per line,
  132. # and the class name may be prefixed with a path (which will be ignored).
  133. if inheritInModuleFiles:
  134. for moduleFileName in inheritInModuleFiles.split(","):
  135. with open(moduleFileName) as f:
  136. for line in f.readlines():
  137. inheritInModule.append(line.strip().split("/",1)[-1]) # Strip whitespace, path/
  138. print "Parsing %s" % fileName
  139. try: # One input file parse.
  140. f = open(fileName) # Def: Input file handle
  141. contents = f.read().replace("_PolyExport", "") # Def: Input file contents, strip out "_PolyExport"
  142. cppHeader = CppHeaderParser.CppHeader(contents, "string") # Def: Input file contents, parsed structure
  143. ignore_classes = ["PolycodeShaderModule", "Object", "Threaded", "OpenGLCubemap", "PolyBase"]
  144. # Iterate, check each class in this file.
  145. for ckey in cppHeader.classes:
  146. print ">> Parsing class %s" % ckey
  147. c = cppHeader.classes[ckey] # Def: The class structure
  148. luaClassBindingOut = "" # Def: The local lua file to generate for this class.
  149. inherits = False
  150. parentClass = ""
  151. if len(c["inherits"]) > 0: # Does this class have parents?
  152. if c["inherits"][0]["class"] not in ignore_classes:
  153. if c["inherits"][0]["class"] in inheritInModule: # Parent class is in this module
  154. luaClassBindingOut += "require \"%s/%s\"\n\n" % (prefix, c["inherits"][0]["class"])
  155. else: # Parent class is in Polycore
  156. luaClassBindingOut += "require \"Polycode/%s\"\n\n" % (c["inherits"][0]["class"])
  157. if (ckey == "ScreenParticleEmitter" or ckey == "SceneParticleEmitter"):
  158. luaClassBindingOut += "require \"Polycode/ParticleEmitter\"\n\n"
  159. luaClassBindingOut += "class \"%s\" (%s)\n\n" % (ckey, c["inherits"][0]["class"])
  160. parentClass = c["inherits"][0]["class"]
  161. inherits = True
  162. if inherits == False: # Class does not have parents
  163. luaClassBindingOut += "class \"%s\"\n\n" % ckey
  164. if ckey in ignore_classes:
  165. continue
  166. if len(c["methods"]["public"]) < 2: # Used to, this was a continue.
  167. print("Warning: Lua-binding class with less than two methods")
  168. continue # FIXME: Remove this, move any non-compileable classes into ignore_classes
  169. extendString = ""
  170. if len(c["inherits"]) > 0:
  171. if c["inherits"][0]["class"] != "PolyBase":
  172. extendString = " extends=\"%s\"" % (c["inherits"][0]["class"])
  173. luaDocOut += "\t<class name=\"%s\"%s>\n" % (ckey, extendString)
  174. if 'doxygen' in c:
  175. luaDocOut += "\t\t<desc><![CDATA[%s]]></desc>\n" % (cleanDocs(c['doxygen']))
  176. parsed_methods = [] # Def: List of discovered methods
  177. ignore_methods = ["readByte32", "readByte16", "getCustomEntitiesByType", "Core", "Renderer", "Shader", "Texture", "handleEvent", "secondaryHandler", "getSTLString"]
  178. luaClassBindingOut += "\n\n"
  179. luaDocOut += "\t\t<static_members>\n"
  180. classProperties = [] # Def: List of found property structures ("properties" meaning "data members")
  181. for pp in c["properties"]["public"]:
  182. pp["type"] = pp["type"].replace("Polycode::", "")
  183. pp["type"] = pp["type"].replace("std::", "")
  184. if pp["type"].find("POLYIGNORE") != -1:
  185. continue
  186. if pp["type"].find("static ") != -1: # If static. FIXME: Static doesn't work?
  187. if "defaltValue" in pp: # FIXME: defaltValue is misspelled.
  188. luaClassBindingOut += "%s.%s = %s\n" % (ckey, pp["name"], pp["defaltValue"])
  189. luaDocOut += "\t\t\t<static_member name=\"%s\" type=\"%s\" value=\"%s\">\n" % (pp["name"], toLuaType(typeFilter(pp["type"])), pp["defaltValue"])
  190. if 'doxygen' in pp:
  191. luaDocOut += "\t\t\t\t<desc><![CDATA[%s]]></desc>\n" % (cleanDocs(pp['doxygen']))
  192. luaDocOut += "\t\t\t</static_member>\n"
  193. else: # FIXME: Nonstatic method ? variable ?? found.
  194. #there are some bugs in the class parser that cause it to return junk
  195. if pp["type"].find("*") == -1 and pp["type"].find("vector") == -1 and pp["name"] != "setScale" and pp["name"] != "setPosition" and pp["name"] != "BUFFER_CACHE_PRECISION" and not pp["name"].isdigit():
  196. classProperties.append(pp)
  197. luaDocOut += "\t\t</static_members>\n"
  198. # Iterate over properties, creating getters
  199. pidx = 0 # Def: Count of properties processed so far
  200. # TODO: Remove or generalize ParticleEmitter special casing. These lines are marked with #SPEC
  201. luaDocOut += "\t\t<members>\n"
  202. numGetVars = 0
  203. if len(classProperties) > 0: # If there are properties, add index lookup to the metatable
  204. luaClassBindingOut += "function %s:__getvar(name)\n" % ckey
  205. # Iterate over property structures, creating if/else clauses for each.
  206. # TODO: Could a table be more appropriate for
  207. for pp in classProperties:
  208. if pp["name"] == "" or pp["array"] == 1:
  209. continue
  210. numGetVars = numGetVars + 1
  211. pp["type"] = typeFilter(pp["type"])
  212. if pidx == 0:
  213. luaClassBindingOut += "\tif name == \"%s\" then\n" % (pp["name"])
  214. else:
  215. luaClassBindingOut += "\telseif name == \"%s\" then\n" % (pp["name"])
  216. # Generate Lua side of binding:
  217. # If type is a primitive such as Number/String/int/bool
  218. if pp["type"] == "Number" or pp["type"] == "String" or pp["type"] == "int" or pp["type"] == "bool":
  219. luaClassBindingOut += "\t\treturn %s.%s_get_%s(self.__ptr)\n" % (libName, ckey, pp["name"])
  220. # If type is a particle emitter, specifically #SPEC
  221. elif (ckey == "ScreenParticleEmitter" or ckey == "SceneParticleEmitter") and pp["name"] == "emitter":
  222. luaClassBindingOut += "\t\tlocal ret = %s(\"__skip_ptr__\")\n" % (pp["type"])
  223. luaClassBindingOut += "\t\tret.__ptr = self.__ptr\n"
  224. luaClassBindingOut += "\t\treturn ret\n"
  225. # If type is a class
  226. else:
  227. luaClassBindingOut += "\t\tlocal retVal = %s.%s_get_%s(self.__ptr)\n" % (libName, ckey, pp["name"])
  228. luaClassBindingOut += template_returnPtrLookup("\t\t", template_quote(pp["type"]), "retVal")
  229. luaDocOut += "\t\t\t<member name=\"%s\" type=\"%s\">\n" % (pp["name"], toLuaType(typeFilter(pp["type"])))
  230. if 'doxygen' in pp:
  231. luaDocOut += "\t\t\t\t<desc><![CDATA[%s]]></desc>\n" % (cleanDocs(pp['doxygen']))
  232. luaDocOut += "\t\t\t</member>\n"
  233. # Generate C++ side of binding:
  234. if not ((ckey == "ScreenParticleEmitter" or ckey == "SceneParticleEmitter") and pp["name"] == "emitter"): #SPEC
  235. cppRegisterOut += "\t\t{\"%s_get_%s\", %s_%s_get_%s},\n" % (ckey, pp["name"], libName, ckey, pp["name"])
  236. wrappersHeaderOut += "static int %s_%s_get_%s(lua_State *L) {\n" % (libName, ckey, pp["name"])
  237. wrappersHeaderOut += "\tluaL_checktype(L, 1, LUA_TUSERDATA);\n"
  238. wrappersHeaderOut += "\t%s *inst = (%s*) *((PolyBase**)lua_touserdata(L, 1));\n" % (ckey, ckey)
  239. outfunc = "this_shouldnt_happen"
  240. retFunc = ""
  241. if pp["type"] == "Number":
  242. outfunc = "lua_pushnumber"
  243. if pp["type"] == "String":
  244. outfunc = "lua_pushstring"
  245. retFunc = ".c_str()"
  246. if pp["type"] == "int":
  247. outfunc = "lua_pushinteger"
  248. if pp["type"] == "bool":
  249. outfunc = "lua_pushboolean"
  250. if pp["type"] == "Number" or pp["type"] == "String" or pp["type"] == "int" or pp["type"] == "bool":
  251. wrappersHeaderOut += "\t%s(L, inst->%s%s);\n" % (outfunc, pp["name"], retFunc)
  252. else:
  253. wrappersHeaderOut += "\tPolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));\n"
  254. wrappersHeaderOut += "\t*userdataPtr = (PolyBase*)&inst->%s%s;\n" % (pp["name"], retFunc)
  255. wrappersHeaderOut += "\treturn 1;\n"
  256. wrappersHeaderOut += "}\n\n"
  257. # Success
  258. pidx = pidx + 1
  259. if numGetVars != 0:
  260. luaClassBindingOut += "\tend\n"
  261. if inherits:
  262. luaClassBindingOut += "\tif %s[\"__getvar\"] ~= nil then\n" % (parentClass)
  263. luaClassBindingOut += "\t\treturn %s.__getvar(self, name)\n" % (parentClass)
  264. luaClassBindingOut += "\tend\n"
  265. luaClassBindingOut += "end\n"
  266. luaDocOut += "\t\t</members>\n"
  267. luaClassBindingOut += "\n\n"
  268. # Iterate over properties again, creating setters
  269. pidx = 0 # Def: Count of
  270. if len(classProperties) > 0: # If there are properties, add index setter to the metatable
  271. luaClassBindingOut += "function %s:__setvar(name,value)\n" % ckey
  272. for pp in classProperties:
  273. if pp["name"] == "" or pp["array"] == 1:
  274. continue
  275. pp["type"] = typeFilter(pp["type"])
  276. # If type is a primitive: Create lua and C++ sides at the same time.
  277. if pp["type"] == "Number" or pp["type"] == "String" or pp["type"] == "int" or pp["type"] == "bool":
  278. if pidx == 0:
  279. luaClassBindingOut += "\tif name == \"%s\" then\n" % (pp["name"])
  280. else:
  281. luaClassBindingOut += "\telseif name == \"%s\" then\n" % (pp["name"])
  282. luaClassBindingOut += "\t\t%s.%s_set_%s(self.__ptr, value)\n" % (libName, ckey, pp["name"])
  283. luaClassBindingOut += "\t\treturn true\n"
  284. cppRegisterOut += "\t\t{\"%s_set_%s\", %s_%s_set_%s},\n" % (ckey, pp["name"], libName, ckey, pp["name"])
  285. wrappersHeaderOut += "static int %s_%s_set_%s(lua_State *L) {\n" % (libName, ckey, pp["name"])
  286. wrappersHeaderOut += "\tluaL_checktype(L, 1, LUA_TUSERDATA);\n"
  287. wrappersHeaderOut += "\t%s *inst = (%s*) *((PolyBase**)lua_touserdata(L, 1));\n" % (ckey, ckey)
  288. outfunc = "this_shouldnt_happen"
  289. if pp["type"] == "Number":
  290. outfunc = "lua_tonumber"
  291. if pp["type"] == "String":
  292. outfunc = "lua_tostring"
  293. if pp["type"] == "int":
  294. outfunc = "lua_tointeger"
  295. if pp["type"] == "bool":
  296. outfunc = "lua_toboolean"
  297. wrappersHeaderOut += "\t%s param = %s(L, 2);\n" % (pp["type"], outfunc)
  298. wrappersHeaderOut += "\tinst->%s = param;\n" % (pp["name"])
  299. wrappersHeaderOut += "\treturn 0;\n"
  300. wrappersHeaderOut += "}\n\n"
  301. pidx = pidx + 1 # Success
  302. # Notice: Setters for object types are not created.
  303. if pidx != 0:
  304. luaClassBindingOut += "\tend\n"
  305. if inherits:
  306. luaClassBindingOut += "\tif %s[\"__setvar\"] ~= nil then\n" % (parentClass)
  307. luaClassBindingOut += "\t\treturn %s.__setvar(self, name, value)\n" % (parentClass)
  308. luaClassBindingOut += "\telse\n"
  309. luaClassBindingOut += "\t\treturn false\n"
  310. luaClassBindingOut += "\tend\n"
  311. else:
  312. luaClassBindingOut += "\treturn false\n"
  313. luaClassBindingOut += "end\n"
  314. # Iterate over methods
  315. luaClassBindingOut += "\n\n"
  316. luaDocOut += "\t\t<methods>\n"
  317. for pm in c["methods"]["public"]:
  318. # Skip argument-overloaded methods and operators.
  319. # TODO: Instead of skipping arguemnt overloads, have special behavior.
  320. # TODO: Instead of skipping operators, add to metatable.
  321. if pm["name"] in parsed_methods or pm["name"].find("operator") > -1 or pm["rtnType"].find("POLYIGNORE") > -1 or pm["name"] in ignore_methods:
  322. continue
  323. # Skip destructors and methods which return templates.
  324. # TODO: Special-case certain kind of vector<>s?
  325. if pm["name"] == "~"+ckey or pm["name"] == "CoreServices":
  326. continue
  327. staticString = ""
  328. if pm["rtnType"].find("static ") != -1:
  329. staticString = " static=\"true\""
  330. if pm["rtnType"].find("std::vector") > -1:
  331. vectorReturnClass = pm["rtnType"].replace("std::vector<", "").replace(">","").replace(" ", "")
  332. luaDocOut += "\t\t\t<method name=\"%s\" return_array=\"true\" return_type=\"%s\"%s>\n" % (pm["name"], toLuaType(typeFilter(vectorReturnClass).replace("*", "")), staticString)
  333. else:
  334. luaDocOut += "\t\t\t<method name=\"%s\" return_type=\"%s\"%s>\n" % (pm["name"], toLuaType(typeFilter(pm["rtnType"].replace("*", ""))), staticString)
  335. docs = None
  336. if 'doxygen' in pm:
  337. if pm['doxygen'].find("@return") > -1:
  338. docs = cleanDocs(pm['doxygen']).split("@return")[0].split("@param")
  339. else:
  340. docs = cleanDocs(pm['doxygen']).split("@param")
  341. luaDocOut += "\t\t\t\t<desc><![CDATA[%s]]></desc>\n" % (docs[0])
  342. if len(pm["parameters"]) > 0:
  343. luaDocOut += "\t\t\t\t<params>\n"
  344. paramIndex = 0
  345. for param in pm["parameters"]:
  346. if "name" in param:
  347. if not param.has_key("type"):
  348. continue
  349. if param["type"] == "0":
  350. continue
  351. if param["type"].find("vector<") != -1:
  352. vectorClass = param["type"].replace("std::vector<", "").replace(">","").replace(" ", "")
  353. luaDocOut += "\t\t\t\t\t<param name=\"%s\" param_array=\"true\" type=\"%s\">\n" % (param["name"], toLuaType(vectorClass.replace("*","")))
  354. else:
  355. luaDocOut += "\t\t\t\t\t<param name=\"%s\" type=\"%s\">\n" % (param["name"], toLuaType(typeFilter(param["type"]).replace("*","")))
  356. if docs != None:
  357. if len(docs) > paramIndex+1:
  358. cdoc = docs[paramIndex+1].split()
  359. cdoc.pop(0)
  360. luaDocOut += "\t\t\t\t\t\t<desc><![CDATA[%s]]></desc>\n" % (" ".join(cdoc).replace("\n", ""))
  361. luaDocOut += "\t\t\t\t\t</param>\n"
  362. paramIndex = paramIndex + 1
  363. luaDocOut += "\t\t\t\t</params>\n"
  364. luaDocOut += "\t\t\t</method>\n"
  365. basicType = False
  366. voidRet = False
  367. vectorReturn = False
  368. vectorReturnClass = ""
  369. # Def: True if method takes a lua_State* as argument (i.e.: no preprocessing by us)
  370. rawMethod = len(pm["parameters"]) > 0 and pm["parameters"][0].get("type","").find("lua_State") > -1
  371. # Basic setup, C++ side: Add function to registry and start building wrapper function.
  372. if pm["name"] == ckey: # It's a constructor
  373. cppRegisterOut += "\t\t{\"%s\", %s_%s},\n" % (ckey, libName, ckey)
  374. wrappersHeaderOut += "static int %s_%s(lua_State *L) {\n" % (libName, ckey)
  375. idx = 1 # Def: Current stack depth (TODO: Figure out, is this correct?)
  376. else: # It's not a constructor
  377. cppRegisterOut += "\t\t{\"%s_%s\", %s_%s_%s},\n" % (ckey, pm["name"], libName, ckey, pm["name"])
  378. wrappersHeaderOut += "static int %s_%s_%s(lua_State *L) {\n" % (libName, ckey, pm["name"])
  379. # Skip static methods (TODO: Figure out, why is this being done here?). # FIXME
  380. if pm["rtnType"].find("static ") == -1:
  381. wrappersHeaderOut += "\tluaL_checktype(L, 1, LUA_TUSERDATA);\n"
  382. wrappersHeaderOut += "\t%s *inst = (%s*) *((PolyBase**)lua_touserdata(L, 1));\n" % (ckey, ckey)
  383. idx = 2
  384. else:
  385. idx = 1
  386. if rawMethod:
  387. wrappersHeaderOut += "\treturn inst->%s(L);\n" % (pm["name"])
  388. else:
  389. # Generate C++ side parameter pushing
  390. paramlist = []
  391. lparamlist = []
  392. for param in pm["parameters"]:
  393. if not param.has_key("type"):
  394. continue
  395. if param["type"] == "0":
  396. continue
  397. param["type"] = typeFilter(param["type"])
  398. param["name"] = param["name"].replace("end", "_end").replace("repeat", "_repeat")
  399. if"type" in param:
  400. luatype = "LUA_TUSERDATA"
  401. checkfunc = "lua_isuserdata"
  402. if param["type"].find("*") > -1:
  403. luafunc = "(%s) *((PolyBase**)lua_touserdata" % (param["type"].replace("Polygon", "Polycode::Polygon").replace("Rectangle", "Polycode::Rectangle"))
  404. elif param["type"].find("&") > -1:
  405. luafunc = "*(%s*) *((PolyBase**)lua_touserdata" % (param["type"].replace("const", "").replace("&", "").replace("Polygon", "Polycode::Polygon").replace("Rectangle", "Polycode::Rectangle"))
  406. else:
  407. luafunc = "*(%s*) *((PolyBase**)lua_touserdata" % (param["type"].replace("Polygon", "Polycode::Polygon").replace("Rectangle", "Polycode::Rectangle"))
  408. lend = ".__ptr"
  409. luafuncsuffix = ")"
  410. if param["type"] == "int" or param["type"] == "unsigned int" or param["type"] == "short":
  411. luafunc = "lua_tointeger"
  412. luatype = "LUA_TNUMBER"
  413. checkfunc = "lua_isnumber"
  414. luafuncsuffix = ""
  415. lend = ""
  416. if param["type"] == "bool":
  417. luafunc = "lua_toboolean"
  418. luatype = "LUA_TBOOLEAN"
  419. checkfunc = "lua_isboolean"
  420. luafuncsuffix = ""
  421. lend = ""
  422. if param["type"] == "Number" or param["type"] == "float" or param["type"] == "double":
  423. luatype = "LUA_TNUMBER"
  424. luafunc = "lua_tonumber"
  425. checkfunc = "lua_isnumber"
  426. luafuncsuffix = ""
  427. lend = ""
  428. if param["type"] == "String":
  429. luatype = "LUA_TSTRING"
  430. luafunc = "lua_tostring"
  431. checkfunc = "lua_isstring"
  432. luafuncsuffix = ""
  433. lend = ""
  434. param["type"] = param["type"].replace("Polygon", "Polycode::Polygon").replace("Rectangle", "Polycode::Rectangle")
  435. if "defaltValue" in param:
  436. if checkfunc != "lua_isuserdata" or (checkfunc == "lua_isuserdata" and param["defaltValue"] == "NULL"):
  437. #param["defaltValue"] = param["defaltValue"].replace(" 0f", ".0f")
  438. param["defaltValue"] = param["defaltValue"].replace(": :", "::")
  439. #param["defaltValue"] = param["defaltValue"].replace("0 ", "0.")
  440. param["defaltValue"] = re.sub(r'([0-9]+) ([0-9])+', r'\1.\2', param["defaltValue"])
  441. wrappersHeaderOut += "\t%s %s;\n" % (param["type"], param["name"])
  442. wrappersHeaderOut += "\tif(%s(L, %d)) {\n" % (checkfunc, idx)
  443. wrappersHeaderOut += "\t\t%s = %s(L, %d)%s;\n" % (param["name"], luafunc, idx, luafuncsuffix)
  444. wrappersHeaderOut += "\t} else {\n"
  445. wrappersHeaderOut += "\t\t%s = %s;\n" % (param["name"], param["defaltValue"])
  446. wrappersHeaderOut += "\t}\n"
  447. else:
  448. wrappersHeaderOut += "\tluaL_checktype(L, %d, %s);\n" % (idx, luatype);
  449. if param["type"] == "String":
  450. wrappersHeaderOut += "\t%s %s = String(%s(L, %d));\n" % (param["type"], param["name"], luafunc, idx)
  451. else:
  452. wrappersHeaderOut += "\t%s %s = %s(L, %d)%s;\n" % (param["type"], param["name"], luafunc, idx,luafuncsuffix)
  453. else:
  454. wrappersHeaderOut += "\tluaL_checktype(L, %d, %s);\n" % (idx, luatype);
  455. if param["type"] == "String":
  456. wrappersHeaderOut += "\t%s %s = String(%s(L, %d));\n" % (param["type"], param["name"], luafunc, idx)
  457. else:
  458. wrappersHeaderOut += "\t%s %s = %s(L, %d)%s;\n" % (param["type"], param["name"], luafunc, idx, luafuncsuffix)
  459. paramlist.append(param["name"])
  460. lparamlist.append(param["name"]+lend)
  461. idx = idx +1 # Param parse success-- mark the increased stack
  462. # Generate C++-side method call / generate return value
  463. if pm["name"] == ckey: # If constructor
  464. if ckey == "EventHandler": # See LuaEventHandler above
  465. wrappersHeaderOut += "\tLuaEventHandler *inst = new LuaEventHandler();\n"
  466. wrappersHeaderOut += "\tinst->wrapperIndex = luaL_ref(L, LUA_REGISTRYINDEX );\n"
  467. wrappersHeaderOut += "\tinst->L = L;\n"
  468. else:
  469. wrappersHeaderOut += "\t%s *inst = new %s(%s);\n" % (ckey, ckey, ", ".join(paramlist))
  470. wrappersHeaderOut += "\tPolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));\n"
  471. wrappersHeaderOut += "\t*userdataPtr = (PolyBase*)inst;\n"
  472. wrappersHeaderOut += "\tluaL_getmetatable(L, \"%s.%s\");\n" % (libName, ckey)
  473. wrappersHeaderOut += "\tlua_setmetatable(L, -2);\n"
  474. wrappersHeaderOut += "\treturn 1;\n"
  475. else: #If non-constructor
  476. if pm["rtnType"].find("static ") == -1: # If non-static
  477. call = "inst->%s(%s)" % (pm["name"], ", ".join(paramlist))
  478. else: # If static (FIXME: Why doesn't this work?)
  479. call = "%s::%s(%s)" % (ckey, pm["name"], ", ".join(paramlist))
  480. #check if returning a template
  481. if pm["rtnType"].find("<") > -1:
  482. #if returning a vector, convert to lua table
  483. if pm["rtnType"].find("std::vector") > -1:
  484. vectorReturnClass = pm["rtnType"].replace("std::vector<", "").replace(">","").replace(" ", "")
  485. if vectorReturnClass.find("&") == -1 and vectorReturnClass.find("*") > -1: #FIXME: return references to std::vectors and basic types
  486. vectorReturn = True
  487. wrappersHeaderOut += "\tstd::vector<%s> retVector = %s;\n" % (vectorReturnClass,call)
  488. wrappersHeaderOut += "\tlua_newtable(L);\n"
  489. wrappersHeaderOut += "\tfor(int i=0; i < retVector.size(); i++) {\n"
  490. wrappersHeaderOut += "\t\tPolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));\n"
  491. wrappersHeaderOut += "\t\t*userdataPtr = (PolyBase*)retVector[i];\n"
  492. wrappersHeaderOut += "\t\tlua_rawseti(L, -2, i+1);\n"
  493. wrappersHeaderOut += "\t}\n"
  494. wrappersHeaderOut += "\treturn 1;\n"
  495. # else If void-typed:
  496. elif pm["rtnType"] == "void" or pm["rtnType"] == "static void" or pm["rtnType"] == "virtual void" or pm["rtnType"] == "inline void":
  497. wrappersHeaderOut += "\t%s;\n" % (call)
  498. basicType = True
  499. voidRet = True
  500. vectorReturn = False
  501. wrappersHeaderOut += "\treturn 0;\n" # 0 arguments returned
  502. else: # If there is a return value:
  503. # What type is the return value? Default to pointer
  504. outfunc = "this_shouldnt_happen"
  505. retFunc = ""
  506. basicType = False
  507. vectorReturn = False
  508. if pm["rtnType"] == "Number" or pm["rtnType"] == "inline Number":
  509. outfunc = "lua_pushnumber"
  510. basicType = True
  511. if pm["rtnType"] == "String" or pm["rtnType"] == "static String": # TODO: Path for STL strings?
  512. outfunc = "lua_pushstring"
  513. basicType = True
  514. retFunc = ".c_str()"
  515. if pm["rtnType"] == "int" or pm["rtnType"] == "unsigned int" or pm["rtnType"] == "static int" or pm["rtnType"] == "size_t" or pm["rtnType"] == "static size_t" or pm["rtnType"] == "long" or pm["rtnType"] == "unsigned int" or pm["rtnType"] == "static long" or pm["rtnType"] == "short":
  516. outfunc = "lua_pushinteger"
  517. basicType = True
  518. if pm["rtnType"] == "bool" or pm["rtnType"] == "static bool" or pm["rtnType"] == "virtual bool":
  519. outfunc = "lua_pushboolean"
  520. basicType = True
  521. if pm["rtnType"].find("*") > -1: # Returned var is definitely a pointer.
  522. wrappersHeaderOut += "\tPolyBase *ptrRetVal = (PolyBase*)%s%s;\n" % (call, retFunc)
  523. wrappersHeaderOut += "\tif(ptrRetVal == NULL) {\n"
  524. wrappersHeaderOut += "\t\tlua_pushnil(L);\n"
  525. wrappersHeaderOut += "\t} else {\n"
  526. wrappersHeaderOut += "\t\tPolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));\n"
  527. wrappersHeaderOut += "\t\t*userdataPtr = ptrRetVal;\n"
  528. wrappersHeaderOut += "\t}\n"
  529. elif basicType == True: # Returned var has been flagged as a recognized primitive type
  530. wrappersHeaderOut += "\t%s(L, %s%s);\n" % (outfunc, call, retFunc)
  531. else: # Some static object is being returned. Convert it to a pointer, then return that.
  532. className = pm["rtnType"].replace("const", "").replace("&", "").replace("inline", "").replace("virtual", "").replace("static", "")
  533. if className == "Polygon": # Deal with potential windows.h conflict
  534. className = "Polycode::Polygon"
  535. if className == "Rectangle":
  536. className = "Polycode::Rectangle"
  537. if className == "Polycode : : Rectangle":
  538. className = "Polycode::Rectangle"
  539. wrappersHeaderOut += "\t%s *retInst = new %s();\n" % (className, className)
  540. wrappersHeaderOut += "\t*retInst = %s;\n" % (call)
  541. wrappersHeaderOut += "\tPolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));\n"
  542. wrappersHeaderOut += "\tluaL_getmetatable(L, \"%s.%s\");\n" % (libName, className)
  543. wrappersHeaderOut += "\tlua_setmetatable(L, -2);\n"
  544. wrappersHeaderOut += "\t*userdataPtr = (PolyBase*)retInst;\n"
  545. wrappersHeaderOut += "\treturn 1;\n"
  546. wrappersHeaderOut += "}\n\n" # Close out C++ generation
  547. # Now generate the Lua side method.
  548. if rawMethod:
  549. luaClassBindingOut += "function %s:%s(...)\n" % (ckey, pm["name"])
  550. luaClassBindingOut += "\treturn %s.%s_%s(self.__ptr, ...)\n" % (libName, ckey, pm["name"])
  551. luaClassBindingOut += "end\n"
  552. elif pm["name"] == ckey: # Constructors
  553. luaClassBindingOut += "function %s:%s(...)\n" % (ckey, ckey)
  554. luaClassBindingOut += "\tlocal arg = {...}\n"
  555. if inherits:
  556. luaClassBindingOut += "\tif type(arg[1]) == \"table\" and count(arg) == 1 then\n"
  557. luaClassBindingOut += "\t\tif \"\"..arg[1].__classname == \"%s\" then\n" % (c["inherits"][0]["class"])
  558. luaClassBindingOut += "\t\t\tself.__ptr = arg[1].__ptr\n"
  559. luaClassBindingOut += "\t\t\treturn\n"
  560. luaClassBindingOut += "\t\tend\n"
  561. luaClassBindingOut += "\tend\n"
  562. luaClassBindingOut += "\tfor k,v in pairs(arg) do\n"
  563. luaClassBindingOut += "\t\tif type(v) == \"table\" then\n"
  564. luaClassBindingOut += "\t\t\tif v.__ptr ~= nil then\n"
  565. luaClassBindingOut += "\t\t\t\targ[k] = v.__ptr\n"
  566. luaClassBindingOut += "\t\t\tend\n"
  567. luaClassBindingOut += "\t\tend\n"
  568. luaClassBindingOut += "\tend\n"
  569. luaClassBindingOut += "\tif self.__ptr == nil and arg[1] ~= \"__skip_ptr__\" then\n"
  570. if ckey == "EventHandler": # See LuaEventHandler above
  571. luaClassBindingOut += "\t\tself.__ptr = %s.%s(self)\n" % (libName, ckey)
  572. else:
  573. luaClassBindingOut += "\t\tself.__ptr = %s.%s(unpack(arg))\n" % (libName, ckey)
  574. luaClassBindingOut += "\tend\n"
  575. luaClassBindingOut += "end\n\n"
  576. else: # Non-constructors.
  577. if pm["rtnType"].find("static ") == -1: # Non-static method
  578. luaClassBindingOut += "function %s:%s(%s)\n" % (ckey, pm["name"], ", ".join(paramlist))
  579. if len(lparamlist):
  580. luaClassBindingOut += "\tlocal retVal = %s.%s_%s(self.__ptr, %s)\n" % (libName, ckey, pm["name"], ", ".join(lparamlist))
  581. else:
  582. luaClassBindingOut += "\tlocal retVal = %s.%s_%s(self.__ptr)\n" % (libName, ckey, pm["name"])
  583. else: # Static method
  584. luaClassBindingOut += "function %s.%s(%s)\n" % (ckey, pm["name"], ", ".join(paramlist))
  585. if len(lparamlist):
  586. luaClassBindingOut += "\tlocal retVal = %s.%s_%s(%s)\n" % (libName, ckey, pm["name"], ", ".join(lparamlist))
  587. else:
  588. luaClassBindingOut += "\tlocal retVal = %s.%s_%s()\n" % (libName, ckey, pm["name"])
  589. if not voidRet: # Was there a return value?
  590. if basicType == True: # Yes, a primitive
  591. luaClassBindingOut += "\treturn retVal\n"
  592. else: # Yes, a pointer was returned
  593. luaClassBindingOut += "\tif retVal == nil then return nil end\n"
  594. if vectorReturn == True:
  595. className = vectorReturnClass.replace("*", "")
  596. luaClassBindingOut += template_returnPtrLookupArray("\t",template_quote(className),"retVal")
  597. else:
  598. className = pm["rtnType"].replace("const", "").replace("&", "").replace("inline", "").replace("virtual", "").replace("static", "").replace("*","").replace(" ", "")
  599. luaClassBindingOut += template_returnPtrLookup("\t",template_quote(className),"retVal")
  600. luaClassBindingOut += "end\n\n" # Close out Lua generation
  601. parsed_methods.append(pm["name"]) # Method parse success
  602. luaDocOut += "\t\t</methods>\n"
  603. # With methods out of the way, do some final cleanup:
  604. # user pointer metatable creation in C++
  605. cppLoaderOut += "\n\tluaL_newmetatable(L, \"%s.%s\");\n" % (libName, ckey)
  606. if ckey not in disable_gc:
  607. cppLoaderOut += "\tlua_pushstring(L, \"__gc\");\n"
  608. cppLoaderOut += "\tlua_pushcfunction(L, %s_delete_%s);\n" % (libName, ckey)
  609. cppLoaderOut += "\tlua_settable(L, -3);\n"
  610. # Delete method (C++ side)
  611. cppRegisterOut += "\t\t{\"delete_%s\", %s_delete_%s},\n" % (ckey, libName, ckey)
  612. wrappersHeaderOut += "static int %s_delete_%s(lua_State *L) {\n" % (libName, ckey)
  613. wrappersHeaderOut += "\tluaL_checktype(L, 1, LUA_TUSERDATA);\n"
  614. wrappersHeaderOut += "\t%s *inst = (%s*) *((PolyBase**)lua_touserdata(L, 1));\n" % (ckey, ckey)
  615. wrappersHeaderOut += "\tdelete inst;\n"
  616. wrappersHeaderOut += "\treturn 0;\n"
  617. wrappersHeaderOut += "}\n\n"
  618. # Delete method (Lua side)
  619. luaClassBindingOut += "function %s:__delete()\n" % (ckey)
  620. luaClassBindingOut += "\t%s.delete_%s(self.__ptr)\n" % (libName, ckey)
  621. luaClassBindingOut += "end\n"
  622. if ckey == "EventHandler": # See LuaEventHandler above
  623. luaClassBindingOut += "\n\n"
  624. luaClassBindingOut += "function EventHandler:__handleEvent(event)\n"
  625. luaClassBindingOut += "\tevt = _G[\"Event\"](\"__skip_ptr__\")\n"
  626. luaClassBindingOut += "\tevt.__ptr = event\n"
  627. luaClassBindingOut += "\tself:handleEvent(evt)\n"
  628. #luaClassBindingOut += "\tself:handleEvent(event)\n"
  629. luaClassBindingOut += "end\n\n"
  630. # Let's use this opportunity to put in some other "generated" utility functions.
  631. luaClassBindingOut += "function __ptrToTable(className, ptr)\n"
  632. luaClassBindingOut += template_returnPtrLookup("\t","className","ptr")
  633. luaClassBindingOut += "end\n\n"
  634. # Add class to lua index file
  635. luaIndexOut += "require \"%s/%s\"\n" % (prefix, ckey)
  636. # Write lua file
  637. mkdir_p(apiClassPath)
  638. fout = open("%s/%s.lua" % (apiClassPath, ckey), "w")
  639. fout.write(luaClassBindingOut)
  640. luaDocOut += "\t</class>\n"
  641. except CppHeaderParser.CppParseError, e: # One input file parse; failed.
  642. print e
  643. sys.exit(1)
  644. luaDocOut += "</classes>\n"
  645. luaDocOut += "</docs>\n"
  646. # Footer boilerplate for wrappersHeaderOut and cppRegisterOut.
  647. wrappersHeaderOut += "} // namespace Polycode\n"
  648. cppRegisterOut += "\t\t{NULL, NULL}\n"
  649. cppRegisterOut += "\t};\n"
  650. cppRegisterOut += "\tluaL_openlib(L, \"%s\", %sLib, 0);\n" % (libName, libSmallName)
  651. cppRegisterOut += cppLoaderOut
  652. cppRegisterOut += "\treturn 1;\n"
  653. cppRegisterOut += "}"
  654. cppRegisterHeaderOut = "" # Def: Global C++ *LUA.h
  655. cppRegisterHeaderOut += "#pragma once\n"
  656. cppRegisterHeaderOut += "#include <%s>\n" % (mainInclude)
  657. cppRegisterHeaderOut += "extern \"C\" {\n"
  658. cppRegisterHeaderOut += "#include <stdio.h>\n"
  659. cppRegisterHeaderOut += "#include \"lua.h\"\n"
  660. cppRegisterHeaderOut += "#include \"lualib.h\"\n"
  661. cppRegisterHeaderOut += "#include \"lauxlib.h\"\n"
  662. cppRegisterHeaderOut += "int _PolyExport luaopen_%s(lua_State *L);\n" % (prefix)
  663. cppRegisterHeaderOut += "}\n"
  664. # Write out global files
  665. mkdir_p(includePath)
  666. mkdir_p(apiPath)
  667. mkdir_p(sourcePath)
  668. fout = open("%s/%sLUA.h" % (includePath, prefix), "w")
  669. fout.write(cppRegisterHeaderOut)
  670. luaDocPath = "../../../Documentation/Lua/xml"
  671. fout = open("%s/%s.xml" % (luaDocPath, prefix), "w")
  672. fout.write(luaDocOut)
  673. fout = open("%s/%s.lua" % (apiPath, prefix), "w")
  674. fout.write(luaIndexOut)
  675. fout = open("%s/%sLUAWrappers.h" % (includePath, prefix), "w")
  676. fout.write(wrappersHeaderOut)
  677. fout = open("%s/%sLUA.cpp" % (sourcePath, prefix), "w")
  678. fout.write(cppRegisterOut)
  679. # Create .pak zip archive
  680. pattern = '*.lua'
  681. os.chdir(apiPath)
  682. if libName == "Polycore":
  683. with ZipFile("api.pak", 'w') as myzip:
  684. for root, dirs, files in os.walk("."):
  685. for filename in fnmatch.filter(files, pattern):
  686. myzip.write(os.path.join(root, filename))
  687. if len(sys.argv) < 10:
  688. print ("Usage:\n%s [input path] [prefix] [main include] [lib small name] [lib name] [api path] [api class-path] [include path] [source path] [inherit-in-module-file path (optional)]" % (sys.argv[0]))
  689. sys.exit(1)
  690. else:
  691. createLUABindings(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], sys.argv[6], sys.argv[7], sys.argv[8], sys.argv[9], sys.argv[10] if len(sys.argv)>10 else None)