# HG changeset patch # User jbe # Date 1406466201 -7200 # Node ID 453d8f8fbacec06593ee9002ecaac7727e48d7fd # Parent c507f8d62931c7b63a0155523f6234ac2ec9b821 Extended function json.type(...) to accept two arguments, to allow return of "null" diff -r c507f8d62931 -r 453d8f8fbace libraries/json/json.c --- a/libraries/json/json.c Sun Jul 27 14:44:20 2014 +0200 +++ b/libraries/json/json.c Sun Jul 27 15:03:21 2014 +0200 @@ -266,10 +266,26 @@ } static int json_type(lua_State *L) { - lua_settop(L, 1); - lua_pushvalue(L, 1); + if (lua_gettop(L) >= 2) { + lua_pushvalue(L, 1); + lua_rawget(L, JSON_UPVAL_NULLS); + lua_pushvalue(L, 2); + lua_rawget(L, -2); + if (lua_toboolean(L, -1)) { + lua_getmetatable(L, 1); + if (lua_rawequal(L, -1, JSON_UPVAL_METATABLE)) { + lua_pushliteral(L, "null"); + return 1; + } + } + lua_settop(L, 2); + lua_rawget(L, 1); + } else { + lua_settop(L, 1); + } + lua_pushvalue(L, -1); lua_rawget(L, JSON_UPVAL_TYPES); - if (lua_isnil(L, -1)) lua_pushstring(L, lua_typename(L, lua_type(L, 1))); + if (lua_isnil(L, -1)) lua_pushstring(L, lua_typename(L, lua_type(L, -2))); return 1; }