mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 11:01:49 +00:00
refactor: 'lua' namespace expansion
This commit is contained in:
parent
7973a9c32b
commit
0647bc6f90
26 changed files with 613 additions and 723 deletions
|
|
@ -1,23 +1,15 @@
|
|||
#include "api_lua.hpp"
|
||||
#include "lua_util.hpp"
|
||||
#include "lua_commons.hpp"
|
||||
#include "LuaState.hpp"
|
||||
|
||||
#include "../../../coders/json.hpp"
|
||||
#include "../../../data/dynamic.hpp"
|
||||
|
||||
namespace scripting {
|
||||
extern lua::LuaState* state;
|
||||
}
|
||||
|
||||
static int l_json_stringify(lua_State* L) {
|
||||
auto value = lua::tovalue(L, 1);
|
||||
|
||||
if (auto mapptr = std::get_if<dynamic::Map_sptr>(&value)) {
|
||||
bool nice = lua_toboolean(L, 2);
|
||||
bool nice = lua::toboolean(L, 2);
|
||||
auto string = json::stringify(mapptr->get(), nice, " ");
|
||||
lua_pushstring(L, string.c_str());
|
||||
return 1;
|
||||
return lua::pushstring(L, string.c_str());
|
||||
} else {
|
||||
throw std::runtime_error("table expected");
|
||||
}
|
||||
|
|
@ -26,12 +18,11 @@ static int l_json_stringify(lua_State* L) {
|
|||
static int l_json_parse(lua_State* L) {
|
||||
auto string = lua::require_string(L, 1);
|
||||
auto element = json::parse("<string>", string);
|
||||
lua::pushvalue(L, element);
|
||||
return 1;
|
||||
return lua::pushvalue(L, element);
|
||||
}
|
||||
|
||||
const luaL_Reg jsonlib [] = {
|
||||
{"tostring", lua_wrap_errors<l_json_stringify>},
|
||||
{"parse", lua_wrap_errors<l_json_parse>},
|
||||
{"tostring", lua::wrap<l_json_stringify>},
|
||||
{"parse", lua::wrap<l_json_parse>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue