/apps/twnlua: actually use 32 bit

This commit is contained in:
veclavtalica 2025-02-08 12:23:35 +03:00
parent 85d7d54eed
commit 3bf8d7bedb
3 changed files with 5 additions and 4 deletions

View File

@ -30,7 +30,7 @@ add_custom_target(
DEPENDS ${TWN_OUT_DIR}/data/scripts/twnapi.lua
)
add_compile_definitions(LUA_32BITS)
add_compile_definitions(LUA_32BITS=1)
set(SOURCE_FILES
game.c

View File

@ -36,7 +36,7 @@ def to_table(typedesc, variable, indent = 0):
binding = ' ' * indent + "lua_createtable(L, 0, %i);\n" % len(typedesc["fields"])
for field in typedesc["fields"]:
if field["type"] == "float" or field["type"] == "uint8_t":
binding += ' ' * indent + "lua_pushnumber(L, (double)(%s));\n" % (variable + ".%s" % field["name"])
binding += ' ' * indent + "lua_pushnumber(L, (float)(%s));\n" % (variable + ".%s" % field["name"])
elif field["type"] == "bool":
binding += ' ' * indent + "lua_pushboolean(L, (%s));\n" % (variable + ".%s" % field["name"])
elif field["type"] in api["types"]:
@ -109,7 +109,7 @@ for procedure, procedure_desc in api["procedures"].items():
if procedure_desc["return"] == "bool":
binding += " lua_pushboolean(L, (int)(%s(%s)));\n" % (procedure, ", ".join(param["name"] for param in procedure_desc["params"]))
elif procedure_desc["return"] == "float":
binding += " lua_pushnumber(L, (double)(%s(%s)));\n" % (procedure, ", ".join(param["name"] for param in procedure_desc["params"]))
binding += " lua_pushnumber(L, (float)(%s(%s)));\n" % (procedure, ", ".join(param["name"] for param in procedure_desc["params"]))
elif procedure_desc["return"] == "char *":
binding += " lua_pushstring(L, %s(%s));\n" % (procedure, ", ".join(param["name"] for param in procedure_desc["params"]))
elif type(procedure_desc["return"]) is dict or procedure_desc["return"] in api["types"]:

View File

@ -210,8 +210,9 @@ extern "C" {
/*
@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats.
*/
#if !defined(LUA_32BITS)
#define LUA_32BITS 0
#endif
/*
@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for