Fix module initialization
The way C modules are initialized was affected by one of the major breaking changes between 5.x versions. Rather than trying to cater to each version individually, we now just backport from newer versions. Namely from 5.2 to 5.1.
This commit is contained in:
parent
3838b9f52a
commit
30db8863e3
3 changed files with 11 additions and 44 deletions
|
@ -1,6 +1,4 @@
|
||||||
#ifndef callback_h_INCLUDED
|
#pragma once
|
||||||
#define callback_h_INCLUDED
|
|
||||||
|
|
||||||
|
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <pulse/context.h>
|
#include <pulse/context.h>
|
||||||
|
@ -40,6 +38,3 @@ void free_lua_callback(simple_callback_data*);
|
||||||
|
|
||||||
// Simple implementation of `pa_context_success_cb_t` that calls a provided Lua function.
|
// Simple implementation of `pa_context_success_cb_t` that calls a provided Lua function.
|
||||||
void success_callback(pa_context*, int, void*);
|
void success_callback(pa_context*, int, void*);
|
||||||
|
|
||||||
#endif // callback_h_INCLUDED
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#ifndef lua_util_h_INCLUDED
|
#pragma once
|
||||||
#define lua_util_h_INCLUDED
|
|
||||||
|
|
||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
|
@ -8,6 +7,9 @@
|
||||||
|
|
||||||
#if LUA_VERSION_NUM <= 501
|
#if LUA_VERSION_NUM <= 501
|
||||||
#define lua_rawlen lua_objlen
|
#define lua_rawlen lua_objlen
|
||||||
|
|
||||||
|
#define luaL_newlib(L, l) (luaL_newlibtable(L, l), luaL_setfuncs(L, l, 0))
|
||||||
|
#define luaL_newlibtable(L, l) (lua_createtable(L, 0, sizeof(l) / sizeof(l[0])))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LUA_VERSION_NUM > 501
|
#if LUA_VERSION_NUM > 501
|
||||||
|
@ -18,6 +20,3 @@ typedef struct luaU_enumfield {
|
||||||
const char* name;
|
const char* name;
|
||||||
const char* value;
|
const char* value;
|
||||||
} luaU_enumfield;
|
} luaU_enumfield;
|
||||||
|
|
||||||
|
|
||||||
#endif // lua_util_h_INCLUDED
|
|
||||||
|
|
|
@ -10,10 +10,8 @@
|
||||||
#include <lualib.h>
|
#include <lualib.h>
|
||||||
#include <pulse/glib-mainloop.h>
|
#include <pulse/glib-mainloop.h>
|
||||||
|
|
||||||
|
|
||||||
#if LUA_VERSION_NUM <= 501
|
#if LUA_VERSION_NUM <= 501
|
||||||
// Shamelessly copied from Lua 5.3 source.
|
// Shamelessly copied from Lua 5.3 source.
|
||||||
// TODO: What's the official way to do this in 5.1?
|
|
||||||
void luaL_setfuncs(lua_State* L, const luaL_Reg* l, int nup) {
|
void luaL_setfuncs(lua_State* L, const luaL_Reg* l, int nup) {
|
||||||
luaL_checkstack(L, nup, "too many upvalues");
|
luaL_checkstack(L, nup, "too many upvalues");
|
||||||
for (; l->name != NULL; l++) { /* fill the table with given functions */
|
for (; l->name != NULL; l++) { /* fill the table with given functions */
|
||||||
|
@ -29,12 +27,8 @@ void luaL_setfuncs(lua_State* L, const luaL_Reg* l, int nup) {
|
||||||
}
|
}
|
||||||
lua_pop(L, nup); /* remove upvalues */
|
lua_pop(L, nup); /* remove upvalues */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define luaL_newlib(L, l) (luaL_register(L, LUA_PULSEAUDIO, l))
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int pulseaudio_new(lua_State* L) {
|
int pulseaudio_new(lua_State* L) {
|
||||||
GMainContext* ctx = g_main_context_default();
|
GMainContext* ctx = g_main_context_default();
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
|
@ -86,17 +80,13 @@ int pulseaudio_new_context(lua_State* L) {
|
||||||
void createlib_volume(lua_State* L) {
|
void createlib_volume(lua_State* L) {
|
||||||
luaL_newmetatable(L, LUA_PA_VOLUME);
|
luaL_newmetatable(L, LUA_PA_VOLUME);
|
||||||
|
|
||||||
lua_createtable(L, 0, sizeof volume_f / sizeof volume_f[0]);
|
luaL_newlib(L, volume_f);
|
||||||
luaL_setfuncs(L, volume_f, 0);
|
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
luaL_setfuncs(L, volume_mt, 0);
|
luaL_setfuncs(L, volume_mt, 0);
|
||||||
|
|
||||||
#if LUA_VERSION_NUM <= 501
|
|
||||||
luaL_register(L, LUA_PA_VOLUME, volume_lib);
|
|
||||||
#else
|
|
||||||
luaL_newlib(L, volume_lib);
|
luaL_newlib(L, volume_lib);
|
||||||
#endif
|
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,17 +94,12 @@ void createlib_volume(lua_State* L) {
|
||||||
void createlib_proplist(lua_State* L) {
|
void createlib_proplist(lua_State* L) {
|
||||||
luaL_newmetatable(L, LUA_PA_PROPLIST);
|
luaL_newmetatable(L, LUA_PA_PROPLIST);
|
||||||
|
|
||||||
lua_createtable(L, 0, sizeof proplist_f / sizeof proplist_f[0]);
|
luaL_newlib(L, proplist_f);
|
||||||
luaL_setfuncs(L, proplist_f, 0);
|
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
luaL_setfuncs(L, proplist_mt, 0);
|
luaL_setfuncs(L, proplist_mt, 0);
|
||||||
|
|
||||||
#if LUA_VERSION_NUM <= 501
|
|
||||||
luaL_register(L, LUA_PA_PROPLIST, proplist_lib);
|
|
||||||
#else
|
|
||||||
luaL_newlib(L, proplist_lib);
|
luaL_newlib(L, proplist_lib);
|
||||||
#endif
|
|
||||||
|
|
||||||
// Create a metatable with an `__index` table for read-only enum fields.
|
// Create a metatable with an `__index` table for read-only enum fields.
|
||||||
lua_createtable(L, 0, 1);
|
lua_createtable(L, 0, 1);
|
||||||
|
@ -133,8 +118,7 @@ void createlib_proplist(lua_State* L) {
|
||||||
void createlib_context(lua_State* L) {
|
void createlib_context(lua_State* L) {
|
||||||
luaL_newmetatable(L, LUA_PA_CONTEXT);
|
luaL_newmetatable(L, LUA_PA_CONTEXT);
|
||||||
|
|
||||||
lua_createtable(L, 0, sizeof context_f / sizeof context_f[0]);
|
luaL_newlib(L, context_f);
|
||||||
luaL_setfuncs(L, context_f, 0);
|
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
luaL_setfuncs(L, context_mt, 0);
|
luaL_setfuncs(L, context_mt, 0);
|
||||||
|
@ -144,17 +128,12 @@ void createlib_context(lua_State* L) {
|
||||||
void createlib_pulseaudio(lua_State* L) {
|
void createlib_pulseaudio(lua_State* L) {
|
||||||
luaL_newmetatable(L, LUA_PULSEAUDIO);
|
luaL_newmetatable(L, LUA_PULSEAUDIO);
|
||||||
|
|
||||||
lua_createtable(L, 0, sizeof pulseaudio_f / sizeof pulseaudio_f[0]);
|
luaL_newlib(L, pulseaudio_f);
|
||||||
luaL_setfuncs(L, pulseaudio_f, 0);
|
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
luaL_setfuncs(L, pulseaudio_mt, 0);
|
luaL_setfuncs(L, pulseaudio_mt, 0);
|
||||||
|
|
||||||
#if LUA_VERSION_NUM <= 501
|
|
||||||
luaL_register(L, LUA_PULSEAUDIO, pulseaudio_lib);
|
|
||||||
#else
|
|
||||||
luaL_newlib(L, pulseaudio_lib);
|
luaL_newlib(L, pulseaudio_lib);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,17 +156,11 @@ LUA_MOD_EXPORT int luaopen_lua_libpulse_glib(lua_State* L) {
|
||||||
LUA_MOD_EXPORT int luaopen_lua_libpulse_glib_volume(lua_State* L) {
|
LUA_MOD_EXPORT int luaopen_lua_libpulse_glib_volume(lua_State* L) {
|
||||||
luaL_newmetatable(L, LUA_PA_VOLUME);
|
luaL_newmetatable(L, LUA_PA_VOLUME);
|
||||||
|
|
||||||
lua_createtable(L, 0, sizeof volume_f / sizeof volume_f[0]);
|
luaL_newlib(L, volume_f);
|
||||||
luaL_setfuncs(L, volume_f, 0);
|
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
luaL_setfuncs(L, volume_mt, 0);
|
luaL_setfuncs(L, volume_mt, 0);
|
||||||
|
|
||||||
#if LUA_VERSION_NUM <= 501
|
|
||||||
luaL_register(L, LUA_PA_VOLUME, volume_lib);
|
|
||||||
#else
|
|
||||||
luaL_newlib(L, volume_lib);
|
luaL_newlib(L, volume_lib);
|
||||||
#endif
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue