MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / json_protect_conversion

Function json_protect_conversion

deps/lua/src/lua_cjson.c:1318–1341  ·  view source on GitHub ↗

Call target function in protected mode with all supplied args. * Assumes target function only returns a single non-nil value. * Convert and return thrown errors as: nil, "error message" */

Source from the content-addressed store, hash-verified

1316 * Assumes target function only returns a single non-nil value.
1317 * Convert and return thrown errors as: nil, "error message" */
1318static int json_protect_conversion(lua_State *l)
1319{
1320 int err;
1321
1322 /* Deliberately throw an error for invalid arguments */
1323 luaL_argcheck(l, lua_gettop(l) == 1, 1, "expected 1 argument");
1324
1325 /* pcall() the function stored as upvalue(1) */
1326 lua_pushvalue(l, lua_upvalueindex(1));
1327 lua_insert(l, 1);
1328 err = lua_pcall(l, 1, 1, 0);
1329 if (!err)
1330 return 1;
1331
1332 if (err == LUA_ERRRUN) {
1333 lua_pushnil(l);
1334 lua_insert(l, -2);
1335 return 2;
1336 }
1337
1338 /* Since we are not using a custom error handler, the only remaining
1339 * errors are memory related */
1340 return luaL_error(l, "Memory allocation error in CJSON protected call");
1341}
1342
1343/* Return cjson module table */
1344static int lua_cjson_new(lua_State *l)

Callers

nothing calls this directly

Calls 6

lua_gettopFunction · 0.85
lua_pushvalueFunction · 0.85
lua_insertFunction · 0.85
lua_pcallFunction · 0.85
lua_pushnilFunction · 0.85
luaL_errorFunction · 0.85

Tested by

no test coverage detected