MCPcopy Create free account
hub / github.com/defold/defold / Json_Encode

Function Json_Encode

engine/script/src/script_json.cpp:180–200  ·  view source on GitHub ↗

encode a lua table to a JSON string * Encode a lua table to a JSON string. * A Lua error is raised for syntax errors. * * @name json.encode * @param tbl [type:table] lua table to encode * @param [options] [type:table] table with encode options * * - [type:string] `encode_empty_table_as_object`: whether to encode an empty table as an JSON object or array (def

Source from the content-addressed store, hash-verified

178 * ```
179 */
180 static int Json_Encode(lua_State* L)
181 {
182 int top = lua_gettop(L);
183 if (top == 0)
184 {
185 luaL_error(L, "json.encode requires one argument.");
186 }
187
188 char* json = 0;
189 size_t json_length = 0;
190 if (LuaToJson(L, 1, 2, &json, &json_length))
191 {
192 lua_pushlstring(L, json, json_length);
193 free(json);
194 } else {
195 lua_pushnil(L);
196 }
197
198 assert(top + 1 == lua_gettop(L));
199 return 1;
200 }
201
202 /*# null
203 * Represents the null primitive from a json file

Callers

nothing calls this directly

Calls 7

lua_gettopFunction · 0.85
luaL_errorFunction · 0.85
LuaToJsonFunction · 0.85
lua_pushlstringFunction · 0.85
freeFunction · 0.85
lua_pushnilFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected