From 9d0a2cab814137020ce8607e206a3519a43b5204 Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Wed, 15 Jan 2025 04:15:08 +0300 Subject: [PATCH] expose audio to twnlua --- apps/twnlua/bindgen.py | 6 +++--- include/twn_audio.h | 2 +- share/twn_api.json | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/apps/twnlua/bindgen.py b/apps/twnlua/bindgen.py index af61aad..2bb7b7a 100755 --- a/apps/twnlua/bindgen.py +++ b/apps/twnlua/bindgen.py @@ -34,7 +34,7 @@ def default(parameter): 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": + if field["type"] == "float" or field["type"] == "uint8_t": binding += ' ' * indent + "lua_pushnumber(L, (double)(%s));\n" % (variable + ".%s" % field["name"]) elif field["type"] == "bool": binding += ' ' * indent + "lua_pushboolean(L, (%s));\n" % (variable + ".%s" % field["name"]) @@ -50,8 +50,8 @@ def from_table(typedesc, variable, indent = 0): binding = "" for field in typedesc["fields"]: binding += ' ' * indent + "lua_getfield(L, -1, \"%s\");\n" % field["name"] - if field["type"] == "float": - binding += ' ' * indent + "%s = (float)lua_tonumber(L, -1);\n" % (variable + ".%s" % field["name"]) + if field["type"] == "float" or field["type"] == "uint8_t": + binding += ' ' * indent + "%s = (%s)lua_tonumber(L, -1);\n" % (variable + ".%s" % field["name"], field["type"]) elif field["type"] == "bool": binding += ' ' * indent + "%s = lua_toboolean(L, -1);\n" % (variable + ".%s" % field["name"]) elif field["type"] in api["types"]: diff --git a/include/twn_audio.h b/include/twn_audio.h index 755b9f4..7424011 100644 --- a/include/twn_audio.h +++ b/include/twn_audio.h @@ -9,7 +9,7 @@ /* plays audio file at specified channel or at scratch channel if NULL is passed, without ability to refer to it later */ /* path path must contain valid file extension to infer which file format it is */ /* supported formats: .ogg, .xm */ -TWN_API void audio_play(const char *path, +TWN_API void audio_play(const char *audio, const char *channel, /* optional */ bool repeat, /* default: false */ float volume, /* default: 1.0f, range: 0.0f to 1.0f */ diff --git a/share/twn_api.json b/share/twn_api.json index 22f3b0e..52010e2 100644 --- a/share/twn_api.json +++ b/share/twn_api.json @@ -213,6 +213,30 @@ { "name": "textures", "type": "char *", "default": {} } ] }, + + "audio_play": { + "module": "audio", + "symbol": "play", + "header": "twn_audio.h", + "params": [ + { "name": "audio", "type": "char *" }, + { "name": "channel", "type": "char *", "default": {} }, + { "name": "repeat", "type": "bool", "default": false }, + { "name": "volume", "type": "float", "default": 1.0 }, + { "name": "panning", "type": "float", "default": 0.0 } + ] + }, + + "audio_parameter": { + "module": "audio", + "symbol": "parameter", + "header": "twn_audio.h", + "params": [ + { "name": "channel", "type": "char *" }, + { "name": "parameter", "type": "char *" }, + { "name": "value", "type": "float" } + ] + } }, "types": {