lib: Add _get_{int,string}() APIs
- add integer and string version of the APIs, - Also Refine the APIs, return value to indicate the setting existance and a new param to return the value of the setting. - add their lua bindings as well, in lua binding the return value nil indicates that the setting is not defnied. - Add corresponding C and lua tests as well. - Add a few handy debug msgs.
This commit is contained in:

committed by
Julian Bouzas

parent
a4f16a98f0
commit
7d304096e5
@@ -1485,8 +1485,59 @@ get_boolean (lua_State *L)
|
||||
|
||||
if (s)
|
||||
{
|
||||
gboolean value = wp_settings_get_boolean (s, setting);
|
||||
lua_pushboolean (L, value);
|
||||
gboolean value = 0;
|
||||
if (wp_settings_get_boolean (s, setting, &value))
|
||||
lua_pushboolean (L, value);
|
||||
else
|
||||
lua_pushnil (L);
|
||||
}
|
||||
else
|
||||
lua_pushnil (L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_string (lua_State *L)
|
||||
{
|
||||
const char *setting = luaL_checkstring (L, 1);
|
||||
const char *m = NULL;
|
||||
|
||||
if (lua_type (L, 2) == LUA_TSTRING)
|
||||
m = luaL_checkstring (L, 2);
|
||||
|
||||
g_autoptr (WpSettings) s = wp_settings_get_instance (get_wp_core (L), m);
|
||||
|
||||
if (s)
|
||||
{
|
||||
const gchar *value = NULL;
|
||||
if (wp_settings_get_string (s, setting, &value))
|
||||
lua_pushstring (L, value);
|
||||
else
|
||||
lua_pushnil (L);
|
||||
}
|
||||
else
|
||||
lua_pushnil (L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_int (lua_State *L)
|
||||
{
|
||||
const char *setting = luaL_checkstring (L, 1);
|
||||
const char *m = NULL;
|
||||
|
||||
if (lua_type (L, 2) == LUA_TSTRING)
|
||||
m = luaL_checkstring (L, 2);
|
||||
|
||||
g_autoptr (WpSettings) s = wp_settings_get_instance (get_wp_core (L), m);
|
||||
|
||||
if (s)
|
||||
{
|
||||
gint64 value = 0;
|
||||
if (wp_settings_get_int (s, setting, &value))
|
||||
lua_pushinteger (L, value);
|
||||
else
|
||||
lua_pushnil (L);
|
||||
}
|
||||
else
|
||||
lua_pushnil (L);
|
||||
@@ -1521,6 +1572,8 @@ apply_rule (lua_State *L)
|
||||
static const luaL_Reg settings_methods[] = {
|
||||
{ "get_boolean", get_boolean },
|
||||
{ "apply_rule", apply_rule },
|
||||
{ "get_string", get_string },
|
||||
{ "get_int", get_int },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user