m-lua-scripting: fixes

This commit is contained in:
George Kiagiadakis
2021-02-02 17:58:28 +02:00
parent 29559b4065
commit ddf7eb1ecb
2 changed files with 31 additions and 6 deletions

View File

@@ -115,18 +115,33 @@ find_script (const gchar * script)
{ {
g_autofree gchar * file = g_build_filename ( g_autofree gchar * file = g_build_filename (
wp_get_config_dir (), "scripts", script, NULL); wp_get_config_dir (), "scripts", script, NULL);
wp_trace ("trying %s", file);
if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
return g_steal_pointer (&file);
}
{
g_autofree gchar * file = g_build_filename (
wp_get_data_dir (), "scripts", script, NULL);
wp_trace ("trying %s", file);
if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
return g_steal_pointer (&file); return g_steal_pointer (&file);
} }
/* {XDG_DATA_DIRS,/usr/local/share,/usr/share}/wireplumber/scripts */ /* {XDG_DATA_DIRS,/usr/local/share,/usr/share}/wireplumber/scripts */
const gchar * const * data_dirs = g_get_system_data_dirs (); const gchar * const * data_dirs = g_get_system_data_dirs ();
while (*data_dirs) { for (; *data_dirs; data_dirs++) {
g_autofree gchar * file = g_build_filename ( g_autofree gchar * file = g_build_filename (
*data_dirs, "wireplumber", "scripts", script, NULL); *data_dirs, "wireplumber", "scripts", script, NULL);
wp_trace ("trying %s", file);
if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) if (g_file_test (file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
return g_steal_pointer (&file); return g_steal_pointer (&file);
data_dirs++;
} }
return NULL; return NULL;
} }

View File

@@ -13,10 +13,13 @@
static gboolean static gboolean
add_spa_libs (lua_State *L, WpCore * core, GError ** error) add_spa_libs (lua_State *L, WpCore * core, GError ** error)
{ {
switch (lua_getglobal (L, "spa_libs")) { lua_getglobal (L, "SANDBOX_COMMON_ENV");
switch (lua_getfield (L, -1, "spa_libs")) {
case LUA_TTABLE: case LUA_TTABLE:
break; break;
case LUA_TNIL: case LUA_TNIL:
wp_debug ("no spa_libs specified");
goto done; goto done;
default: default:
g_set_error (error, WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_INVALID_ARGUMENT, g_set_error (error, WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_INVALID_ARGUMENT,
@@ -36,6 +39,8 @@ add_spa_libs (lua_State *L, WpCore * core, GError ** error)
const gchar *regex = lua_tostring (L, -2); const gchar *regex = lua_tostring (L, -2);
const gchar *lib = lua_tostring (L, -1); const gchar *lib = lua_tostring (L, -1);
wp_debug ("add spa lib: %s -> %s", regex, lib);
int ret = pw_context_add_spa_lib (wp_core_get_pw_context (core), regex, int ret = pw_context_add_spa_lib (wp_core_get_pw_context (core), regex,
lib); lib);
if (ret < 0) { if (ret < 0) {
@@ -49,7 +54,7 @@ add_spa_libs (lua_State *L, WpCore * core, GError ** error)
} }
done: done:
lua_pop (L, 1); /* pop the spa_libs table */ lua_pop (L, 2); /* pop spa_libs & SANDBOX_COMMON_ENV */
return TRUE; return TRUE;
} }
@@ -109,10 +114,13 @@ lua_to_gvariant (lua_State *L, int index)
static gboolean static gboolean
load_components (lua_State *L, WpCore * core, GError ** error) load_components (lua_State *L, WpCore * core, GError ** error)
{ {
switch (lua_getglobal (L, "components")) { lua_getglobal (L, "SANDBOX_COMMON_ENV");
switch (lua_getfield (L, -1, "components")) {
case LUA_TTABLE: case LUA_TTABLE:
break; break;
case LUA_TNIL: case LUA_TNIL:
wp_debug ("no components specified");
goto done; goto done;
default: default:
g_set_error (error, WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_INVALID_ARGUMENT, g_set_error (error, WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_INVALID_ARGUMENT,
@@ -157,6 +165,8 @@ load_components (lua_State *L, WpCore * core, GError ** error)
args = lua_to_gvariant (L, -1); args = lua_to_gvariant (L, -1);
} }
wp_debug ("load component: %s (%s)", component, type);
if (!wp_core_load_component (core, component, type, args, error)) if (!wp_core_load_component (core, component, type, args, error))
return FALSE; return FALSE;
@@ -165,7 +175,7 @@ load_components (lua_State *L, WpCore * core, GError ** error)
} }
done: done:
lua_pop (L, 1); /* pop the components table */ lua_pop (L, 2); /* pop components & SANDBOX_COMMON_ENV */
return TRUE; return TRUE;
} }