mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-09 19:30:29 +00:00
Update EncodeJson in redbean to ignore useoutput outside of request handling
This commit is contained in:
parent
0793d9cf80
commit
7e1055fdb6
2 changed files with 10 additions and 4 deletions
|
@ -508,10 +508,15 @@ FUNCTIONS
|
||||||
encodebase64.c.
|
encodebase64.c.
|
||||||
|
|
||||||
EncodeJson(value[,options:table]) → json:str
|
EncodeJson(value[,options:table]) → json:str
|
||||||
Turns passed Lua value into a JSON string. The following options
|
Turns passed Lua value into a JSON string. Tables with non-zero
|
||||||
can be used:
|
length (as reported by `#`) are encoded as arrays with non-array
|
||||||
|
elements ignored. Empty tables are encoded as empty arrays. All
|
||||||
|
other tables are encoded as objects with numerical keys
|
||||||
|
converted to strings (so `{[3]=1}` is encoded as `{"3":1}`).
|
||||||
|
The following options can be used:
|
||||||
- useoutput: (bool=false) encodes the result directly to the
|
- useoutput: (bool=false) encodes the result directly to the
|
||||||
output buffer and returns `nil` value.
|
output buffer and returns `nil` value. This option is
|
||||||
|
ignored if used outside of request handling code.
|
||||||
- numformat: (string="%.14g") sets numeric format to be used.
|
- numformat: (string="%.14g") sets numeric format to be used.
|
||||||
- maxdepth: (number=64) sets the max number of nested tables.
|
- maxdepth: (number=64) sets the max number of nested tables.
|
||||||
|
|
||||||
|
|
|
@ -4764,7 +4764,8 @@ static int LuaEncodeJson(lua_State *L) {
|
||||||
if (lua_istable(L, 2)) {
|
if (lua_istable(L, 2)) {
|
||||||
lua_settop(L, 2); // discard any extra arguments
|
lua_settop(L, 2); // discard any extra arguments
|
||||||
lua_getfield(L, 2, "useoutput");
|
lua_getfield(L, 2, "useoutput");
|
||||||
if (lua_isboolean(L, -1)) useoutput = lua_toboolean(L, -1);
|
// ignore useoutput outside of request handling
|
||||||
|
if (ishandlingrequest && lua_isboolean(L, -1)) useoutput = lua_toboolean(L, -1);
|
||||||
lua_getfield(L, 2, "maxdepth");
|
lua_getfield(L, 2, "maxdepth");
|
||||||
maxdepth = luaL_optinteger(L, -1, maxdepth);
|
maxdepth = luaL_optinteger(L, -1, maxdepth);
|
||||||
lua_getfield(L, 2, "numformat");
|
lua_getfield(L, 2, "numformat");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue