lua: json: add method to merge json containers

This commit is contained in:
Stefan Ursella
2024-04-26 07:26:52 +02:00
parent 42370f0547
commit fd7a1af7ff
2 changed files with 38 additions and 0 deletions

View File

@@ -167,6 +167,20 @@ push_luajson (lua_State *L, WpSpaJson *json, gint n_recursions)
}
}
static int
spa_json_merge (lua_State *L)
{
WpSpaJson *a = wplua_checkboxed (L, 1, WP_TYPE_SPA_JSON);
WpSpaJson *b = wplua_checkboxed (L, 2, WP_TYPE_SPA_JSON);
WpSpaJson *merge = wp_json_utils_merge_containers(a, b);
if(!merge)
luaL_error (L, "only Json container merge supported");
wplua_pushboxed (L, WP_TYPE_SPA_JSON, merge);
return 1;
}
static int
spa_json_parse (lua_State *L)
{
@@ -340,6 +354,7 @@ static const luaL_Reg spa_json_methods[] = {
{ "is_array", spa_json_is_array },
{ "is_object", spa_json_is_object },
{ "parse", spa_json_parse },
{ "merge", spa_json_merge },
{ NULL, NULL }
};