|
|
@@ -136,8 +136,7 @@ def ret(ret_el):
|
|
|
wglue("lua_pushnil(l);")
|
|
|
wglue("return 1;")
|
|
|
else:
|
|
|
- wglue("lua_pushstring(l, \"Glue code returned nullptr\");")
|
|
|
- wglue("return -1;")
|
|
|
+ wglue("return luaL_error(l, \"Returned nullptr. Location %s:%d %s\", ANKI_FILE, __LINE__, ANKI_FUNC);")
|
|
|
ident(-1)
|
|
|
wglue("}")
|
|
|
wglue("")
|
|
|
@@ -152,8 +151,7 @@ def ret(ret_el):
|
|
|
wglue("if(ret) [[unlikely]]")
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
- wglue("lua_pushstring(l, \"Glue code returned an error\");")
|
|
|
- wglue("return -1;")
|
|
|
+ wglue("return luaL_error(l, \"Returned an error. Location %s:%d %s\", ANKI_FILE, __LINE__, ANKI_FUNC);")
|
|
|
ident(-1)
|
|
|
wglue("}")
|
|
|
wglue("")
|
|
|
@@ -164,19 +162,19 @@ def ret(ret_el):
|
|
|
wglue("ud = static_cast<LuaUserData*>(voidp);")
|
|
|
wglue("luaL_setmetatable(l, \"%s\");" % type)
|
|
|
|
|
|
- wglue("extern LuaUserDataTypeInfo luaUserDataTypeInfo%s;" % type)
|
|
|
+ wglue("extern LuaUserDataTypeInfo g_luaUserDataTypeInfo%s;" % type)
|
|
|
if is_ptr:
|
|
|
- wglue("ud->initPointed(&luaUserDataTypeInfo%s, ret);" % type)
|
|
|
+ wglue("ud->initPointed(&g_luaUserDataTypeInfo%s, ret);" % type)
|
|
|
elif is_ref:
|
|
|
- wglue("ud->initPointed(&luaUserDataTypeInfo%s, &ret);" % type)
|
|
|
+ wglue("ud->initPointed(&g_luaUserDataTypeInfo%s, &ret);" % type)
|
|
|
else:
|
|
|
wglue("size = LuaUserData::computeSizeForGarbageCollected<%s>();" % type)
|
|
|
wglue("voidp = lua_newuserdata(l, size);")
|
|
|
wglue("luaL_setmetatable(l, \"%s\");" % type)
|
|
|
|
|
|
wglue("ud = static_cast<LuaUserData*>(voidp);")
|
|
|
- wglue("extern LuaUserDataTypeInfo luaUserDataTypeInfo%s;" % type)
|
|
|
- wglue("ud->initGarbageCollected(&luaUserDataTypeInfo%s);" % type)
|
|
|
+ wglue("extern LuaUserDataTypeInfo g_luaUserDataTypeInfo%s;" % type)
|
|
|
+ wglue("ud->initGarbageCollected(&g_luaUserDataTypeInfo%s);" % type)
|
|
|
|
|
|
wglue("::new(ud->getData<%s>()) %s(std::move(ret));" % (type, type))
|
|
|
|
|
|
@@ -191,36 +189,36 @@ def arg(arg_txt, stack_index, index):
|
|
|
|
|
|
if type_is_bool(type) or type_is_number(type):
|
|
|
wglue("%s arg%d;" % (type, index))
|
|
|
- wglue("if(LuaBinder::checkNumber(l, %d, arg%d)) [[unlikely]]" % (stack_index, index))
|
|
|
+ wglue("if(LuaBinder::checkNumber(l, ANKI_FILE, __LINE__, ANKI_FUNC, %d, arg%d)) [[unlikely]]" % (stack_index, index))
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
- wglue("return -1;")
|
|
|
+ wglue("return lua_error(l);")
|
|
|
ident(-1)
|
|
|
wglue("}")
|
|
|
elif type == "char" or type == "CString":
|
|
|
wglue("const char* arg%d;" % index)
|
|
|
- wglue("if(LuaBinder::checkString(l, %d, arg%d)) [[unlikely]]" % (stack_index, index))
|
|
|
+ wglue("if(LuaBinder::checkString(l, ANKI_FILE, __LINE__, ANKI_FUNC, %d, arg%d)) [[unlikely]]" % (stack_index, index))
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
- wglue("return -1;")
|
|
|
+ wglue("return lua_error(l);")
|
|
|
ident(-1)
|
|
|
wglue("}")
|
|
|
elif type_is_enum(type):
|
|
|
wglue("lua_Number arg%dTmp;" % index)
|
|
|
- wglue("if(LuaBinder::checkNumber(l, %d, arg%dTmp)) [[unlikely]]" % (stack_index, index))
|
|
|
+ wglue("if(LuaBinder::checkNumber(l, ANKI_FILE, __LINE__, ANKI_FUNC, %d, arg%dTmp)) [[unlikely]]" % (stack_index, index))
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
- wglue("return -1;")
|
|
|
+ wglue("return lua_error(l);")
|
|
|
ident(-1)
|
|
|
wglue("}")
|
|
|
wglue("const %s arg%d = %s(arg%dTmp);" % (type, index, type, index))
|
|
|
else:
|
|
|
# Must be user type
|
|
|
- wglue("extern LuaUserDataTypeInfo luaUserDataTypeInfo%s;" % type)
|
|
|
- wglue("if(LuaBinder::checkUserData(l, %d, luaUserDataTypeInfo%s, ud)) [[unlikely]]" % (stack_index, type))
|
|
|
+ wglue("extern LuaUserDataTypeInfo g_luaUserDataTypeInfo%s;" % type)
|
|
|
+ wglue("if(LuaBinder::checkUserData(l, ANKI_FILE, __LINE__, ANKI_FUNC, %d, g_luaUserDataTypeInfo%s, ud)) [[unlikely]]" % (stack_index, type))
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
- wglue("return -1;")
|
|
|
+ wglue("return lua_error(l);")
|
|
|
ident(-1)
|
|
|
wglue("}")
|
|
|
wglue("")
|
|
|
@@ -279,10 +277,10 @@ def check_args(args_el, bias):
|
|
|
else:
|
|
|
count = bias
|
|
|
|
|
|
- wglue("if(LuaBinder::checkArgsCount(l, %d)) [[unlikely]]" % count)
|
|
|
+ wglue("if(LuaBinder::checkArgsCount(l, ANKI_FILE, __LINE__, ANKI_FUNC, %d)) [[unlikely]]" % count)
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
- wglue("return -1;")
|
|
|
+ wglue("return lua_error(l);")
|
|
|
ident(-1)
|
|
|
wglue("}")
|
|
|
wglue("")
|
|
|
@@ -336,8 +334,8 @@ def method(class_name, meth_el):
|
|
|
meth_name = meth_el.get("name")
|
|
|
meth_alias = get_meth_alias(meth_el)
|
|
|
|
|
|
- wglue("/// Pre-wrap method %s::%s." % (class_name, meth_name))
|
|
|
- wglue("static inline int pwrap%s%s(lua_State* l)" % (class_name, meth_alias))
|
|
|
+ wglue("// Wrap method %s::%s." % (class_name, meth_name))
|
|
|
+ wglue("static inline int wrap%s%s(lua_State* l)" % (class_name, meth_alias))
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
write_local_vars()
|
|
|
@@ -346,10 +344,10 @@ def method(class_name, meth_el):
|
|
|
|
|
|
# Get this pointer
|
|
|
wglue("// Get \"this\" as \"self\"")
|
|
|
- wglue("if(LuaBinder::checkUserData(l, 1, luaUserDataTypeInfo%s, ud))" % class_name)
|
|
|
+ wglue("if(LuaBinder::checkUserData(l, ANKI_FILE, __LINE__, ANKI_FUNC, 1, g_luaUserDataTypeInfo%s, ud)) [[unlikely]]" % class_name)
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
- wglue("return -1;")
|
|
|
+ wglue("return lua_error(l);")
|
|
|
ident(-1)
|
|
|
wglue("}")
|
|
|
wglue("")
|
|
|
@@ -385,25 +383,6 @@ def method(class_name, meth_el):
|
|
|
wglue("}")
|
|
|
wglue("")
|
|
|
|
|
|
- # Write the actual function
|
|
|
- wglue("/// Wrap method %s::%s." % (class_name, meth_name))
|
|
|
- wglue("static int wrap%s%s(lua_State* l)" % (class_name, meth_alias))
|
|
|
- wglue("{")
|
|
|
- ident(1)
|
|
|
- wglue("int res = pwrap%s%s(l);" % (class_name, meth_alias))
|
|
|
- wglue("if(res >= 0)")
|
|
|
- wglue("{")
|
|
|
- ident(1)
|
|
|
- wglue("return res;")
|
|
|
- ident(-1)
|
|
|
- wglue("}")
|
|
|
- wglue("")
|
|
|
- wglue("lua_error(l);")
|
|
|
- wglue("return 0;")
|
|
|
- ident(-1)
|
|
|
- wglue("}")
|
|
|
- wglue("")
|
|
|
-
|
|
|
|
|
|
def static_method(class_name, meth_el):
|
|
|
""" Handle a static method """
|
|
|
@@ -411,7 +390,7 @@ def static_method(class_name, meth_el):
|
|
|
meth_name = meth_el.get("name")
|
|
|
meth_alias = get_meth_alias(meth_el)
|
|
|
|
|
|
- wglue("/// Pre-wrap static method %s::%s." % (class_name, meth_name))
|
|
|
+ wglue("// Wrap static method %s::%s." % (class_name, meth_name))
|
|
|
wglue("static inline int pwrap%s%s(lua_State* l)" % (class_name, meth_alias))
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
@@ -442,30 +421,11 @@ def static_method(class_name, meth_el):
|
|
|
wglue("}")
|
|
|
wglue("")
|
|
|
|
|
|
- # Write the actual function
|
|
|
- wglue("/// Wrap static method %s::%s." % (class_name, meth_name))
|
|
|
- wglue("static int wrap%s%s(lua_State* l)" % (class_name, meth_alias))
|
|
|
- wglue("{")
|
|
|
- ident(1)
|
|
|
- wglue("int res = pwrap%s%s(l);" % (class_name, meth_alias))
|
|
|
- wglue("if(res >= 0)")
|
|
|
- wglue("{")
|
|
|
- ident(1)
|
|
|
- wglue("return res;")
|
|
|
- ident(-1)
|
|
|
- wglue("}")
|
|
|
- wglue("")
|
|
|
- wglue("lua_error(l);")
|
|
|
- wglue("return 0;")
|
|
|
- ident(-1)
|
|
|
- wglue("}")
|
|
|
- wglue("")
|
|
|
-
|
|
|
|
|
|
def constructor(constr_el, class_name, constructor_idx):
|
|
|
""" Handle constructor """
|
|
|
|
|
|
- wglue("/// Pre-wrap constructor for %s." % (class_name))
|
|
|
+ wglue("// Pre-wrap constructor for %s." % (class_name))
|
|
|
wglue("static inline int pwrap%sCtor%d(lua_State* l)" % (class_name, constructor_idx))
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
@@ -481,10 +441,10 @@ def constructor(constr_el, class_name, constructor_idx):
|
|
|
|
|
|
wglue("size = LuaUserData::computeSizeForGarbageCollected<%s>();" % class_name)
|
|
|
wglue("voidp = lua_newuserdata(l, size);")
|
|
|
- wglue("luaL_setmetatable(l, luaUserDataTypeInfo%s.m_typeName);" % class_name)
|
|
|
+ wglue("luaL_setmetatable(l, g_luaUserDataTypeInfo%s.m_typeName);" % class_name)
|
|
|
wglue("ud = static_cast<LuaUserData*>(voidp);")
|
|
|
- wglue("extern LuaUserDataTypeInfo luaUserDataTypeInfo%s;" % class_name)
|
|
|
- wglue("ud->initGarbageCollected(&luaUserDataTypeInfo%s);" % class_name)
|
|
|
+ wglue("extern LuaUserDataTypeInfo g_luaUserDataTypeInfo%s;" % class_name)
|
|
|
+ wglue("ud->initGarbageCollected(&g_luaUserDataTypeInfo%s);" % class_name)
|
|
|
wglue("::new(ud->getData<%s>()) %s(%s);" % (class_name, class_name, args_str))
|
|
|
wglue("")
|
|
|
|
|
|
@@ -518,7 +478,7 @@ def constructors(constructors_el, class_name):
|
|
|
raise Exception("Found no <constructor>")
|
|
|
|
|
|
# Create the landing function
|
|
|
- wglue("/// Wrap constructors for %s." % class_name)
|
|
|
+ wglue("// Wrap constructors for %s." % class_name)
|
|
|
wglue("static int wrap%sCtor(lua_State* l)" % class_name)
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
@@ -559,7 +519,7 @@ def constructors(constructors_el, class_name):
|
|
|
def destructor(class_name):
|
|
|
""" Create a destructor """
|
|
|
|
|
|
- wglue("/// Wrap destructor for %s." % (class_name))
|
|
|
+ wglue("// Wrap destructor for %s." % (class_name))
|
|
|
wglue("static int wrap%sDtor(lua_State* l)" % class_name)
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
@@ -567,10 +527,10 @@ def destructor(class_name):
|
|
|
|
|
|
check_args(None, 1)
|
|
|
|
|
|
- wglue("if(LuaBinder::checkUserData(l, 1, luaUserDataTypeInfo%s, ud)) [[unlikely]]" % class_name)
|
|
|
+ wglue("if(LuaBinder::checkUserData(l, ANKI_FILE, __LINE__, ANKI_FUNC, 1, g_luaUserDataTypeInfo%s, ud)) [[unlikely]]" % class_name)
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
- wglue("return -1;")
|
|
|
+ wglue("return lua_error(l);")
|
|
|
ident(-1)
|
|
|
wglue("}")
|
|
|
wglue("")
|
|
|
@@ -601,7 +561,7 @@ def class_(class_el):
|
|
|
if serialize:
|
|
|
# Serialize
|
|
|
serialize_cb_name = "serialize%s" % class_name
|
|
|
- wglue("/// Serialize %s" % class_name)
|
|
|
+ wglue("// Serialize %s" % class_name)
|
|
|
wglue("static void %s(LuaUserData& self, void* data, PtrSize& size)" % serialize_cb_name)
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
@@ -613,7 +573,7 @@ def class_(class_el):
|
|
|
|
|
|
# Deserialize
|
|
|
deserialize_cb_name = "deserialize%s" % class_name
|
|
|
- wglue("/// De-serialize %s" % class_name)
|
|
|
+ wglue("// De-serialize %s" % class_name)
|
|
|
wglue("static void %s(const void* data, LuaUserData& self)" % deserialize_cb_name)
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
@@ -629,7 +589,7 @@ def class_(class_el):
|
|
|
deserialize_cb_name = "nullptr"
|
|
|
|
|
|
# Write the type info
|
|
|
- wglue("LuaUserDataTypeInfo luaUserDataTypeInfo%s = {" % class_name)
|
|
|
+ wglue("LuaUserDataTypeInfo g_luaUserDataTypeInfo%s = {" % class_name)
|
|
|
ident(1)
|
|
|
wglue("%d, \"%s\", LuaUserData::computeSizeForGarbageCollected<%s>(), %s, %s" %
|
|
|
(type_sig(class_name), class_name, class_name, serialize_cb_name, deserialize_cb_name))
|
|
|
@@ -642,7 +602,7 @@ def class_(class_el):
|
|
|
wglue("const LuaUserDataTypeInfo& LuaUserData::getDataTypeInfoFor<%s>()" % class_name)
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
- wglue("return luaUserDataTypeInfo%s;" % class_name)
|
|
|
+ wglue("return g_luaUserDataTypeInfo%s;" % class_name)
|
|
|
ident(-1)
|
|
|
wglue("}")
|
|
|
wglue("")
|
|
|
@@ -676,15 +636,15 @@ def class_(class_el):
|
|
|
meth_names_aliases.append([meth_name, meth_alias, is_static])
|
|
|
|
|
|
# Start class declaration
|
|
|
- wglue("/// Wrap class %s." % class_name)
|
|
|
+ wglue("// Wrap class %s." % class_name)
|
|
|
wglue("static inline void wrap%s(lua_State* l)" % class_name)
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
- wglue("LuaBinder::createClass(l, &luaUserDataTypeInfo%s);" % class_name)
|
|
|
+ wglue("LuaBinder::createClass(l, &g_luaUserDataTypeInfo%s);" % class_name)
|
|
|
|
|
|
# Register constructor
|
|
|
if has_constructor:
|
|
|
- wglue("LuaBinder::pushLuaCFuncStaticMethod(l, luaUserDataTypeInfo%s.m_typeName, \"new\", wrap%sCtor);" %
|
|
|
+ wglue("LuaBinder::pushLuaCFuncStaticMethod(l, g_luaUserDataTypeInfo%s.m_typeName, \"new\", wrap%sCtor);" %
|
|
|
(class_name, class_name))
|
|
|
|
|
|
# Register destructor
|
|
|
@@ -697,7 +657,7 @@ def class_(class_el):
|
|
|
meth_alias = meth_name_alias[1]
|
|
|
is_static = meth_name_alias[2]
|
|
|
if is_static:
|
|
|
- wglue("LuaBinder::pushLuaCFuncStaticMethod(l, luaUserDataTypeInfo%s.m_typeName, \"%s\", wrap%s%s);" %
|
|
|
+ wglue("LuaBinder::pushLuaCFuncStaticMethod(l, g_luaUserDataTypeInfo%s.m_typeName, \"%s\", wrap%s%s);" %
|
|
|
(class_name, meth_alias, class_name, meth_alias))
|
|
|
else:
|
|
|
wglue("LuaBinder::pushLuaCFuncMethod(l, \"%s\", wrap%s%s);" % (meth_alias, class_name, meth_alias))
|
|
|
@@ -715,8 +675,8 @@ def function(func_el):
|
|
|
func_name = func_el.get("name")
|
|
|
func_alias = get_meth_alias(func_el)
|
|
|
|
|
|
- wglue("/// Pre-wrap function %s." % func_name)
|
|
|
- wglue("static inline int pwrap%s(lua_State* l)" % func_alias)
|
|
|
+ wglue("// Wrap function %s." % func_name)
|
|
|
+ wglue("static inline int wrap%s(lua_State* l)" % func_alias)
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
write_local_vars()
|
|
|
@@ -753,31 +713,12 @@ def function(func_el):
|
|
|
wglue("}")
|
|
|
wglue("")
|
|
|
|
|
|
- # Write the actual function
|
|
|
- wglue("/// Wrap function %s." % func_name)
|
|
|
- wglue("static int wrap%s(lua_State* l)" % func_alias)
|
|
|
- wglue("{")
|
|
|
- ident(1)
|
|
|
- wglue("int res = pwrap%s(l);" % func_alias)
|
|
|
- wglue("if(res >= 0)")
|
|
|
- wglue("{")
|
|
|
- ident(1)
|
|
|
- wglue("return res;")
|
|
|
- ident(-1)
|
|
|
- wglue("}")
|
|
|
- wglue("")
|
|
|
- wglue("lua_error(l);")
|
|
|
- wglue("return 0;")
|
|
|
- ident(-1)
|
|
|
- wglue("}")
|
|
|
- wglue("")
|
|
|
-
|
|
|
|
|
|
def enum(enum_el):
|
|
|
enum_name = enum_el.get("name")
|
|
|
|
|
|
# Write the type info
|
|
|
- wglue("LuaUserDataTypeInfo luaUserDataTypeInfo%s = {" % enum_name)
|
|
|
+ wglue("LuaUserDataTypeInfo g_luaUserDataTypeInfo%s = {" % enum_name)
|
|
|
ident(1)
|
|
|
wglue("%d, \"%s\", 0, nullptr, nullptr" % (type_sig(enum_name), enum_name))
|
|
|
ident(-1)
|
|
|
@@ -789,20 +730,20 @@ def enum(enum_el):
|
|
|
wglue("const LuaUserDataTypeInfo& LuaUserData::getDataTypeInfoFor<%s>()" % enum_name)
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
- wglue("return luaUserDataTypeInfo%s;" % enum_name)
|
|
|
+ wglue("return g_luaUserDataTypeInfo%s;" % enum_name)
|
|
|
ident(-1)
|
|
|
wglue("}")
|
|
|
wglue("")
|
|
|
|
|
|
# Start declaration
|
|
|
- wglue("/// Wrap enum %s." % enum_name)
|
|
|
+ wglue("// Wrap enum %s." % enum_name)
|
|
|
wglue("static inline void wrap%s(lua_State* l)" % enum_name)
|
|
|
wglue("{")
|
|
|
ident(1)
|
|
|
|
|
|
wglue("lua_newtable(l);") # Push new table
|
|
|
- wglue("lua_setglobal(l, luaUserDataTypeInfo%s.m_typeName);" % enum_name) # Pop and make global
|
|
|
- wglue("lua_getglobal(l, luaUserDataTypeInfo%s.m_typeName);" % enum_name) # Push the table again
|
|
|
+ wglue("lua_setglobal(l, g_luaUserDataTypeInfo%s.m_typeName);" % enum_name) # Pop and make global
|
|
|
+ wglue("lua_getglobal(l, g_luaUserDataTypeInfo%s.m_typeName);" % enum_name) # Push the table again
|
|
|
wglue("")
|
|
|
|
|
|
# Now the table is at the top of the stack
|
|
|
@@ -866,7 +807,7 @@ def main():
|
|
|
func_names.append(f.get("name"))
|
|
|
|
|
|
# Wrap function
|
|
|
- wglue("/// Wrap the module.")
|
|
|
+ wglue("// Wrap the module.")
|
|
|
wglue("void wrapModule%s(lua_State* l)" % get_base_fname(filename))
|
|
|
wglue("{")
|
|
|
ident(1)
|