/apps/twnlua: use lua_numberx for slightly more optimized defaults
This commit is contained in:
parent
192907a0db
commit
8d67e44009
@ -8,9 +8,6 @@ with open(sys.argv[1], 'r') if sys.argv[1] != "-" else sys.stdin as f:
|
||||
api = json.loads(api_source)
|
||||
|
||||
|
||||
# TODO: use lua_to--x functions for defaults, so that fewer function calls are made
|
||||
# TODO: use lua_createtable for preallocation
|
||||
|
||||
def default(parameter):
|
||||
basetype = parameter["type"].rsplit(' *', 1)[0]
|
||||
if parameter["type"] == "float":
|
||||
@ -72,12 +69,17 @@ for procedure, procedure_desc in api["procedures"].items():
|
||||
binding += " %s %s;\n" % (parameter["type"], parameter["name"])
|
||||
binding += " lua_getfield(L, 1, \"%s\");\n" % parameter["name"]
|
||||
|
||||
if "default" in parameter:
|
||||
if "default" in parameter and parameter["type"] != "float":
|
||||
binding += " if (lua_isnoneornil(L, -1))\n"
|
||||
binding += " %s = %s;\n" % (parameter["name"], default(parameter))
|
||||
binding += " else\n "
|
||||
|
||||
if parameter["type"] == "float":
|
||||
if "default" in parameter:
|
||||
binding += " int is_%s_num;\n" % parameter["name"]
|
||||
binding += " %s = (float)lua_tonumberx(L, -1, &is_%s_num);\n" % (parameter["name"], parameter["name"]);
|
||||
binding += " if (!is_%s_num) %s = %s;\n" % (parameter["name"], parameter["name"], default(parameter))
|
||||
else:
|
||||
binding += " %s = (float)lua_tonumber(L, -1);\n" % (parameter["name"]);
|
||||
elif parameter["type"] == "bool":
|
||||
binding += " %s = lua_toboolean(L, -1);\n" % (parameter["name"]);
|
||||
|
Loading…
Reference in New Issue
Block a user