MCPcopy Create free account
hub / github.com/PlutoLang/Pluto / encode

Function encode

src/ljson.cpp:140–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138}
139
140static int encode(lua_State* L) {
141 int fmt = 0; // compact
142 if (lua_type(L, 2) == LUA_TBOOLEAN)
143 {
144 if (lua_istrue(L, 2))
145 {
146 fmt = 1; // pretty
147 }
148 }
149 else
150 {
151 static const char* const fmts[] = { "compact", "pretty", "msgpack", nullptr };
152 fmt = luaL_checkoption(L, 2, "compact", fmts);
153 }
154
155 auto& up = *pluto_newclassinst(L, soup::UniquePtr<soup::JsonNode>);
156 checkJson(L, 1, up);
157
158 switch (fmt)
159 {
160 case 0: default:
161 pluto_pushstring(L, up->encode());
162 break;
163
164 case 1:
165 pluto_pushstring(L, up->encodePretty());
166 break;
167
168 case 2:
169 soup::StringWriter sw;
170 up->msgpackEncode(sw);
171 pluto_pushstring(L, std::move(sw.data));
172 break;
173 }
174 return 1;
175}
176
177static int decode(lua_State* L)
178{

Callers 1

url_encodeFunction · 0.70

Calls 5

lua_typeFunction · 0.85
lua_istrueFunction · 0.85
luaL_checkoptionFunction · 0.85
checkJsonFunction · 0.85
pluto_pushstringFunction · 0.85

Tested by

no test coverage detected