2022-06-06 23:03:26 -04:00
|
|
|
// Encode lua data structure into json, and decode them again.
|
|
|
|
|
//
|
|
|
|
|
// See the doc(http.jsonencode) to read about limitations of the encoder.
|
|
|
|
|
//
|
|
|
|
|
#ifndef JSON_HPP
|
|
|
|
|
#define JSON_HPP
|
|
|
|
|
|
|
|
|
|
#include "luastack.hpp"
|
|
|
|
|
#include "wrap-string.hpp"
|
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
|
|
namespace json {
|
|
|
|
|
// Encode json.
|
|
|
|
|
//
|
|
|
|
|
// See doc(http.jsonencode) for a lot more information.
|
|
|
|
|
//
|
|
|
|
|
// Returns an error message. If the error message is an
|
|
|
|
|
// empty string, then the encoding was successful.
|
|
|
|
|
//
|
|
|
|
|
eng::string encode(LuaStack &LS, LuaSlot in, eng::string &out, bool indent, int maxlen);
|
|
|
|
|
|
|
|
|
|
// Decode json.
|
|
|
|
|
//
|
|
|
|
|
// See doc(http.jsondecode) for a lot more information.
|
|
|
|
|
//
|
|
|
|
|
// The only error condition is syntactically invalid json.
|
2022-06-07 01:54:08 -04:00
|
|
|
// In that case, we return false and set 'out' to the
|
|
|
|
|
// token 'error'.
|
2022-06-06 23:03:26 -04:00
|
|
|
//
|
|
|
|
|
bool decode(LuaStack &LS, LuaSlot out, std::string_view in);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // JSON_HPP
|
|
|
|
|
|