From 3ad2c27ff8a10041c50e333f83e0454dfd16897e Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Mon, 23 May 2022 16:28:06 +0200 Subject: [PATCH] feat(volume): Add constructor --- src/lua_libpulse_glib/volume.c | 6 ++++++ src/lua_libpulse_glib/volume.h | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/lua_libpulse_glib/volume.c b/src/lua_libpulse_glib/volume.c index f2e514a..8421280 100644 --- a/src/lua_libpulse_glib/volume.c +++ b/src/lua_libpulse_glib/volume.c @@ -6,6 +6,12 @@ #include +int volume_new(lua_State* L) { + pa_cvolume* cvol = volume_from_lua(L, 1); + return volume_to_lua(L, cvol); +} + + int volume_to_lua(lua_State* L, const pa_cvolume* pa_volume) { volume_t* volume = lua_newuserdata(L, sizeof(volume_t)); if (pa_volume == NULL) { diff --git a/src/lua_libpulse_glib/volume.h b/src/lua_libpulse_glib/volume.h index d931bdc..e529143 100644 --- a/src/lua_libpulse_glib/volume.h +++ b/src/lua_libpulse_glib/volume.h @@ -47,6 +47,13 @@ int volume__newindex(lua_State*); /// Static Functions /// @section static +/** Creates an instance of @{Volume}. + * + * @tparam table values An array of channel volumes. + * @treturn Volume + */ +int volume_new(lua_State*); + /** Checks whether a value is a valid @{Volume}. * @@ -228,8 +235,9 @@ static const struct luaL_Reg volume_mt[] = { static const struct luaL_Reg volume_lib[] = { - {"is_valid", volume_is_valid}, - { NULL, NULL } + {"new", volume_new }, + { "is_valid", volume_is_valid}, + { NULL, NULL } };