HTTP now automatically encodes jsonvalue content

This commit is contained in:
2022-06-07 01:54:08 -04:00
parent 779d9e20b8
commit 79b84a588a
9 changed files with 191 additions and 61 deletions

View File

@@ -13,6 +13,7 @@
LuaTokenConstant(json_null, "null", "");
LuaTokenConstant(json_object, "object", "");
LuaTokenConstant(json_error, "error", "");
static void indent(eng::ostringstream &oss, int level) {
if (level < NOINDENT_LEVEL) {
@@ -543,23 +544,26 @@ bool decode(LuaStack &LS, LuaSlot out, std::string_view v) {
lua_State *L = LS.state();
// Try to read a single value from the view.
int top = lua_gettop(L);
bool ok = decode_value(L, v);
lua_replace(L, out.index());
if (!ok) return false;
// There should be nothing left of the input text.
if (v.size() > 0) {
lua_pushnil(L);
lua_replace(L, out.index());
lua_settop(L, top);
if (!ok) {
LS.set(out, LuaToken("error"));
return false;
}
// Special case: if the top-level result is jsonnull,
// then change it to nil.
// Special case: if the top level value is 'null', change
// it to 'nil.'
if (LS.istoken(out)) {
LS.set(out, LuaNil);
}
// There should be nothing left of the input text.
if (v.size() > 0) {
LS.set(out, LuaToken("error"));
return false;
}
return true;
}