'dynamic' namespace refactor (step 1/2)

This commit is contained in:
MihailRis
2024-05-07 16:00:52 +03:00
parent 80e7bcb203
commit d33edd4cd9
16 changed files with 248 additions and 392 deletions
+8 -8
View File
@@ -11,22 +11,22 @@ namespace scripting {
static int l_json_stringify(lua_State* L) {
auto value = scripting::state->tovalue(1);
if (value->type != dynamic::valtype::map) {
if (auto mapptr = std::get_if<dynamic::Map*>(&value->value)) {
bool nice = lua_toboolean(L, 2);
auto string = json::stringify(*mapptr, nice, " ");
lua_pushstring(L, string.c_str());
return 1;
} else {
luaL_error(L, "table expected");
return 0;
}
bool nice = lua_toboolean(L, 2);
auto string = json::stringify(std::get<dynamic::Map*>(value->value), nice, " ");
lua_pushstring(L, string.c_str());
return 1;
}
static int l_json_parse(lua_State* L) {
auto string = lua_tostring(L, 1);
auto element = json::parse("<string>", string);
auto value = std::make_unique<dynamic::Value>(
dynamic::valtype::map, element.release()
);
auto value = std::make_unique<dynamic::Value>(element.release());
scripting::state->pushvalue(*value);
return 1;
}