input system rework
This commit is contained in:
@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.21)
|
||||
cmake_policy(SET CMP0171 NEW)
|
||||
project(twnlua LANGUAGES C)
|
||||
|
||||
option(TWN_OUT_DIR "Artifact destination" ${CMAKE_SOURCE_DIR})
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
endif()
|
||||
@ -41,5 +39,4 @@ set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/luabind.c
|
||||
)
|
||||
|
||||
cmake_path(GET TWN_OUT_DIR STEM LAST_ONLY GAME_PROJECT_NAME)
|
||||
use_townengine(${GAME_PROJECT_NAME} "${SOURCE_FILES}" ${TWN_OUT_DIR})
|
||||
use_townengine("${SOURCE_FILES}" ${TWN_OUT_DIR})
|
||||
|
@ -116,7 +116,6 @@ for procedure, procedure_desc in api["procedures"].items():
|
||||
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"]:
|
||||
# TODO: handle enums
|
||||
type_desc = procedure_desc["return"] if type(procedure_desc["return"]) is dict else api["types"][procedure_desc["return"]]
|
||||
binding += " %s result = %s(%s);\n" % (type_desc["c_type"], procedure, ", ".join(param["name"] for param in procedure_desc["params"]))
|
||||
binding += to_table(type_desc, "result", 4)
|
||||
@ -150,21 +149,6 @@ for typename, typedesc in used_converters.items():
|
||||
raise BaseException("Unhandled converter field type '%s'" % (field["type"]))
|
||||
converter += " lua_pop(L, %i);\n" % len(typedesc["fields"]);
|
||||
|
||||
# TODO: wild idea: use compile time built hash table
|
||||
elif "enums" in typedesc:
|
||||
storages += ["struct %sHashItem { char *key; %s value; };\nstatic struct %sHashItem *%s_map = NULL;\n" % (typename, typename, typename, typename.lower())]
|
||||
|
||||
# TODO: use arena
|
||||
for enum in typedesc["enums"]:
|
||||
initializer = " shput(%s_map, \"%s\", %s);" % (typename.lower(), enum, typedesc["enums"][enum])
|
||||
initializers += [initializer]
|
||||
|
||||
deinitializers += [" shfree(%s_map);" % typename.lower()]
|
||||
|
||||
converter += " char const *value = lua_tostring(L, -1);\n";
|
||||
converter += " %s = shget(%s_map, value);\n" % (typename.lower(), typename.lower())
|
||||
converter += " lua_pop(L, 1);\n";
|
||||
|
||||
converter += " return %s;\n}\n" % (typename.lower())
|
||||
converters += [converter]
|
||||
|
||||
|
@ -33,7 +33,7 @@ def to_lua_type_annot(typedesc):
|
||||
|
||||
print("error(\"townengine lua api file is not supposed to be imported!\")")
|
||||
|
||||
type_annotations, enum_annotations = {}, {}
|
||||
type_annotations = {}
|
||||
type_annotations["ctx"] = r"{ %s, udata: table }" % \
|
||||
', '.join("%s: %s" % (f["name"], to_lua_type_annot(f["type"])) for f in api["types"]["Context"]["fields"])
|
||||
|
||||
@ -41,12 +41,6 @@ for annot in type_annotations:
|
||||
print("---@type " + type_annotations[annot])
|
||||
print(r"%s = nil" % annot)
|
||||
|
||||
enum_annotations["Control"] = \
|
||||
'|'.join('\'"%s"\'' % e for e in api["types"]["Control"]["enums"])
|
||||
|
||||
for annot in enum_annotations:
|
||||
print("---@alias %s %s" % (annot, enum_annotations[annot]))
|
||||
|
||||
procedure_annotations = {}
|
||||
for procedure, procedure_desc in api["procedures"].items():
|
||||
procedure_annotations[procedure] = {}
|
||||
|
Reference in New Issue
Block a user