lib: Introduce WpSettings API

- WpSettings is a singleton object which attaches itself to the core
  and registry, it provides a get_instance () for its clients.
- WpSettings provides API to get/set wireplumber settings and rules.
- main.c loads the new object and makes sure it is available for
  for all the modules and scripts. This is achieved by introducing
  a new activation step.
- Add the lua bindings for get_setting API.
This commit is contained in:
Ashok Sidipotu
2022-03-22 03:38:35 +05:30
committed by Julian Bouzas
parent e9391b195f
commit 8fd8b01b7a
9 changed files with 351 additions and 5 deletions

View File

@@ -1472,6 +1472,26 @@ impl_module_new (lua_State *L)
}
}
static int
get_setting (lua_State *L)
{
const char *setting = luaL_checkstring (L, 1);
WpSettings *s = wp_settings_get_instance (get_wp_core (L));
if (s)
{
gboolean value = wp_settings_get_boolean (s, setting);
lua_pushboolean (L, value);
}
else
lua_pushnil (L);
return 1;
}
static const luaL_Reg settings_methods[] = {
{ "get_setting", get_setting },
{ NULL, NULL }
};
void
wp_lua_scripting_api_init (lua_State *L)
{
@@ -1492,6 +1512,9 @@ wp_lua_scripting_api_init (lua_State *L)
luaL_newlib (L, plugin_funcs);
lua_setglobal (L, "WpPlugin");
luaL_newlib (L, settings_methods);
lua_setglobal (L, "WpSettings");
wp_lua_scripting_pod_init (L);
wp_lua_scripting_json_init (L);

View File

@@ -210,4 +210,6 @@ SANDBOX_EXPORT = {
State = WpState_new,
LocalModule = WpImplModule_new,
ImplMetadata = WpImplMetadata_new,
Settings = WpSettings,
I18n = I18n
}