diff --git a/src/lua_libpulse_glib/context.c b/src/lua_libpulse_glib/context.c index 34eba5d..5998431 100644 --- a/src/lua_libpulse_glib/context.c +++ b/src/lua_libpulse_glib/context.c @@ -1,6 +1,7 @@ #include "context.h" #include "pulseaudio.h" +#include "lua_util.h" #include #include @@ -196,7 +197,7 @@ int context_subscribe(lua_State* L) { lua_pa_context* ctx = luaL_checkudata(L, 1, LUA_PA_CONTEXT); luaL_checktype(L, 2, LUA_TFUNCTION); - size_t pos = lua_objlen(ctx->event_callback_data->L, 1) + 1; + size_t pos = lua_rawlen(ctx->event_callback_data->L, 1) + 1; // Duplicate the callback function, so we can move it over to the other thread lua_pushvalue(L, 2); lua_xmove(L, ctx->event_callback_data->L, 1); @@ -211,7 +212,7 @@ int context_unsubscribe(lua_State* L) { lua_pa_context* ctx = luaL_checkudata(L, 1, LUA_PA_CONTEXT); lua_State* thread_L = ctx->event_callback_data->L; size_t pos = 0; - size_t len = lua_objlen(thread_L, 1); + size_t len = lua_rawlen(thread_L, 1); if (len == 0) { return 0; diff --git a/src/lua_libpulse_glib/introspection.c b/src/lua_libpulse_glib/introspection.c index d404dd9..a77eb2a 100644 --- a/src/lua_libpulse_glib/introspection.c +++ b/src/lua_libpulse_glib/introspection.c @@ -55,7 +55,7 @@ void sink_info_callback(pa_context* c, const pa_sink_info* info, int eol, void* if (data->is_list) { if (!eol) { - int i = lua_objlen(L, 2); + int i = lua_rawlen(L, 2); lua_pushinteger(L, i + 1); sink_info_to_lua(L, info); lua_settable(L, 2); @@ -446,7 +446,7 @@ void source_info_callback(pa_context* c, const pa_source_info* info, int eol, vo if (data->is_list) { if (!eol) { - int i = lua_objlen(L, 2); + int i = lua_rawlen(L, 2); lua_pushinteger(L, i + 1); source_info_to_lua(L, info); lua_settable(L, 2); @@ -827,7 +827,7 @@ void sink_input_info_callback(pa_context* c, const pa_sink_input_info* info, int if (data->is_list) { if (!eol) { - int i = lua_objlen(L, 2); + int i = lua_rawlen(L, 2); lua_pushinteger(L, i + 1); sink_input_info_to_lua(L, info); lua_settable(L, 2); @@ -1100,7 +1100,7 @@ void source_output_info_callback(pa_context* c, const pa_source_output_info* inf if (data->is_list) { if (!eol) { - int i = lua_objlen(L, 2); + int i = lua_rawlen(L, 2); lua_pushinteger(L, i + 1); source_output_info_to_lua(L, info); lua_settable(L, 2); diff --git a/src/lua_libpulse_glib/lua_util.h b/src/lua_libpulse_glib/lua_util.h index 139d8cd..6128b41 100644 --- a/src/lua_libpulse_glib/lua_util.h +++ b/src/lua_libpulse_glib/lua_util.h @@ -6,6 +6,13 @@ #define LUA_MOD_EXPORT extern +#if LUA_VERSION_NUM <= 501 +#define lua_rawlen lua_objlen +#endif + +#if LUA_VERSION_NUM > 501 +#define lua_equal(L, i1, i2) lua_compare(L, i1, i2, LUA_OPEQ) +#endif typedef struct luaU_enumfield { const char* name; diff --git a/src/lua_libpulse_glib/volume.c b/src/lua_libpulse_glib/volume.c index 8421280..5183aeb 100644 --- a/src/lua_libpulse_glib/volume.c +++ b/src/lua_libpulse_glib/volume.c @@ -35,7 +35,7 @@ int volume_to_lua(lua_State* L, const pa_cvolume* pa_volume) { pa_cvolume* volume_from_lua(lua_State* L, int index) { switch (lua_type(L, index)) { case LUA_TTABLE: { - uint8_t channels = (uint8_t) lua_objlen(L, index); + uint8_t channels = (uint8_t) lua_rawlen(L, index); if (channels > PA_CHANNELS_MAX) { channels = PA_CHANNELS_MAX; } @@ -82,7 +82,7 @@ int volume__eq(lua_State* L) { int volume__index(lua_State* L) { volume_t* volume = luaL_checkudata(L, 1, LUA_PA_VOLUME); - int index = luaL_checkint(L, 2); + int index = (int) luaL_checkinteger(L, 2); luaL_argcheck(L, index >= 1 && index <= (PA_CHANNELS_MAX + 1), 2, "channel index out of bounds"); lua_pushinteger(L, volume->inner.values[index - 1]); return 1;