Skip to content

Commit

Permalink
Fix CreateSound, CreateStream and PlaySound
Browse files Browse the repository at this point in the history
  • Loading branch information
dapetcu21 committed Sep 30, 2021
1 parent 182a131 commit a2076a7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
8 changes: 5 additions & 3 deletions bridge/fmod_generated_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 %});
Expand Down
32 changes: 31 additions & 1 deletion bridge/generate_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit a2076a7

Please sign in to comment.