From a2076a77c1e8422f3b81b9ccd24ba637667b3203 Mon Sep 17 00:00:00 2001 From: Marius Petcu Date: Thu, 30 Sep 2021 21:36:44 +0300 Subject: [PATCH] Fix CreateSound, CreateStream and PlaySound --- bridge/fmod_generated_template.c | 8 +++++--- bridge/generate_bindings.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/bridge/fmod_generated_template.c b/bridge/fmod_generated_template.c index eb623da..63dcf1f 100644 --- a/bridge/fmod_generated_template.c +++ b/bridge/fmod_generated_template.c @@ -22,6 +22,8 @@ inline static void throwError(FMOD_RESULT res, lua_State* L) { /* Basic types */ +#define optional(L, index, typename, x) (lua_isnoneornil(L, index) ? ((typename)0) : (x)) + #define FMODBridge_push_char(L, x) lua_pushnumber(L, (lua_Number)(x)) #define FMODBridge_check_char(L, index) ((char)luaL_checknumber(L, index)) #define FMODBridge_push_short(L, x) lua_pushnumber(L, (lua_Number)(x)) @@ -693,9 +695,9 @@ static int _FMODBridge_func_FMOD_Studio_CommandReplay_GetCommandString(lua_State {% if f.generated %}#ifndef FMODBridge_func_{{ f.name }} #define FMODBridge_func_{{ f.name }} _FMODBridge_func_{{ f.name }} static int _FMODBridge_func_{{ f.name }}(lua_State *L) { - {% for arg in f.args %}{% if arg.usage == "input" %}{{ arg.type.c_type }} {{ arg.name }} = FMODBridge_check_{{ arg.type.name }}(L, {{ arg.arg_index }}); - {% elif arg.usage == "input_deref" %}{{ arg.type.c_type }}* {{ arg.name }} = FMODBridge_check_ptr_{{ arg.type.name }}(L, {{ arg.arg_index }}); - {% elif arg.usage == "input_ptr" %}{{ arg.type.child.c_type }} {{ arg.name }} = FMODBridge_check_{{ arg.type.child.name }}(L, {{ arg.arg_index }}); + {% for arg in f.args %}{% if arg.usage == "input" %}{{ arg.type.c_type }} {{ arg.name }} = {% if arg.optional %}optional(L, {{ arg.arg_index }}, {{ arg.type.c_type }}, {% endif %}FMODBridge_check_{{ arg.type.name }}(L, {{ arg.arg_index }}){% if arg.optional %}){% endif %}; + {% elif arg.usage == "input_deref" %}{{ arg.type.c_type }}* {{ arg.name }} = {% if arg.optional %}optional(L, {{ arg.arg_index }}, {{ arg.type.c_type }}*, {% endif %}FMODBridge_check_ptr_{{ arg.type.name }}(L, {{ arg.arg_index }}){% if arg.optional %}){% endif %}; + {% elif arg.usage == "input_ptr" %}{{ arg.type.child.c_type }} {{ arg.name }} = {% if arg.optional %}optional(L, {{ arg.arg_index }}, {{ arg.type.child.c_type }}, {% endif %}FMODBridge_check_{{ arg.type.child.name }}(L, {{ arg.arg_index }}){% if arg.optional %}){% endif %}; {% elif arg.usage == "output" %}{{ arg.type.child.c_type }} {{ arg.name }}; {% elif arg.usage == "output_ptr" %}{{ arg.type.c_type }} {{ arg.name }} = FMODBridge_push_{{ arg.type.name }}(L, NULL); {% endif %}{% endfor %}ensure({{ f.library }}, {{ f.name }}, FMOD_RESULT{% for arg in f.args %}, {{ arg.type.c_type }}{% endfor %}); diff --git a/bridge/generate_bindings.py b/bridge/generate_bindings.py index 3f20066..7e24905 100644 --- a/bridge/generate_bindings.py +++ b/bridge/generate_bindings.py @@ -23,6 +23,28 @@ "output": "&", } +arg_usage_overrides = { + "FMOD_System_CreateSound": { + "exinfo": "input" + }, + "FMOD_System_CreateStream": { + "exinfo": "input" + }, +} + +optional_arguments = { + "FMOD_System_CreateSound": { + "exinfo": True + }, + "FMOD_System_CreateStream": { + "exinfo": True + }, + "FMOD_System_PlaySound": { + "channelgroup": True, + "paused": True, + }, +} + valid = re.compile(r"^_*(IDs|[A-Z][a-z]+|[A-Z0-9]+(?![a-z]))") def to_snake_case(s): components = [] @@ -155,6 +177,7 @@ class MethodArgument: def __init__(self, node): self.name = node.name self.arg_index = 0 + self.optional = False type = ParsedTypeDecl(node=node.type) self.type = type self.usage = "unknown" @@ -184,9 +207,16 @@ def __init__(self, node): self.library = "UK" self.struct = None + def parse_arguments(self): + arg_overrides = arg_usage_overrides.get(self.name, {}) + optionals = optional_arguments.get(self.name, {}) + for param in self.node.type.args.params: - self.args.append(MethodArgument(param)) + arg = MethodArgument(param) + arg.usage = arg_overrides.get(arg.name, arg.usage) + arg.optional = optionals.get(arg.name, arg.optional) + self.args.append(arg) def detect_scope(self): first_arg = self.args[0]