Repository navigation
parsing: switching from json to ordered_json #3731
|
Imagine I have this code piece which parses a json to a lua table: void settable_from_json(LuaState* state, nlohmann::json json)
{
lua_createtable(state, 0, 0);
lua_checkstack(state, 2);
for (auto const& item : json.items())
parse_json_item(item, state);
}parse_json_item contains this and can call itself recursivly to parse arrays/objects: When changing the type to Any hints on how to solve this? |
Answered by
falbrechtskirchinger
Sep 8, 2022
Replies: 1 comment 4 replies
|
A few observations upfront:
For your primary issue, I'll need to take a look at the source and will update this post shortly. Edit: Can you provide the full error message or at least point out the line that triggers the error? |
4 replies
Answer selected by
robinsch
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A few observations upfront:
detailnamespace directly (andjson_abi_v3_11_2is an inline namespace and should be omitted in this context). I recommend you passitem.key()anditem.value()toparse_json_item().nlohmann::basic_jsonby (const) reference.lua_pushstring(state, val.value().get<std::string>().c_str())– I hopelua_pushstringcreates a copy of the string, otherwise your string will point to invalid memory after the end of the statement..get_ref<const std::string&>().c_str()avoids this issue and skips creating an unnecessary temporary.For your primary issue, I'll need to take a look at the source and will update this post shortly.
…