expose audio to twnlua

This commit is contained in:
veclavtalica 2025-01-15 04:15:08 +03:00
parent d5b42fa242
commit 9d0a2cab81
3 changed files with 28 additions and 4 deletions

View File

@ -34,7 +34,7 @@ def default(parameter):
def to_table(typedesc, variable, indent = 0): def to_table(typedesc, variable, indent = 0):
binding = ' ' * indent + "lua_createtable(L, 0, %i);\n" % len(typedesc["fields"]) binding = ' ' * indent + "lua_createtable(L, 0, %i);\n" % len(typedesc["fields"])
for field in 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"]) binding += ' ' * indent + "lua_pushnumber(L, (double)(%s));\n" % (variable + ".%s" % field["name"])
elif field["type"] == "bool": elif field["type"] == "bool":
binding += ' ' * indent + "lua_pushboolean(L, (%s));\n" % (variable + ".%s" % field["name"]) binding += ' ' * indent + "lua_pushboolean(L, (%s));\n" % (variable + ".%s" % field["name"])
@ -50,8 +50,8 @@ def from_table(typedesc, variable, indent = 0):
binding = "" binding = ""
for field in typedesc["fields"]: for field in typedesc["fields"]:
binding += ' ' * indent + "lua_getfield(L, -1, \"%s\");\n" % field["name"] binding += ' ' * indent + "lua_getfield(L, -1, \"%s\");\n" % field["name"]
if field["type"] == "float": if field["type"] == "float" or field["type"] == "uint8_t":
binding += ' ' * indent + "%s = (float)lua_tonumber(L, -1);\n" % (variable + ".%s" % field["name"]) binding += ' ' * indent + "%s = (%s)lua_tonumber(L, -1);\n" % (variable + ".%s" % field["name"], field["type"])
elif field["type"] == "bool": elif field["type"] == "bool":
binding += ' ' * indent + "%s = lua_toboolean(L, -1);\n" % (variable + ".%s" % field["name"]) binding += ' ' * indent + "%s = lua_toboolean(L, -1);\n" % (variable + ".%s" % field["name"])
elif field["type"] in api["types"]: elif field["type"] in api["types"]:

View File

@ -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 */ /* 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 */ /* path path must contain valid file extension to infer which file format it is */
/* supported formats: .ogg, .xm */ /* supported formats: .ogg, .xm */
TWN_API void audio_play(const char *path, TWN_API void audio_play(const char *audio,
const char *channel, /* optional */ const char *channel, /* optional */
bool repeat, /* default: false */ bool repeat, /* default: false */
float volume, /* default: 1.0f, range: 0.0f to 1.0f */ float volume, /* default: 1.0f, range: 0.0f to 1.0f */

View File

@ -213,6 +213,30 @@
{ "name": "textures", "type": "char *", "default": {} } { "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": { "types": {