From b2cc655554e1d63cdb25a531747864dde5313230 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Wed, 10 Sep 2014 13:29:39 -0700 Subject: [PATCH] change: resty: print() is now identical to ngx.say(), which is more in line with the std "print" function. thanks Michal Cichra for the original patch in #65. --- util/resty | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/util/resty b/util/resty index 397edae..01c7c66 100755 --- a/util/resty +++ b/util/resty @@ -178,13 +178,22 @@ $lua_package_path_config return concat(dst) end - print = function (...) + local function output(...) local args = {...} return stdout:write(expand_table(args, true)) end - ngx.print = print - ngx.say = function (...) local ok, err = print(...) if ok then return print("\\\\n") end return ok, err end + + ngx.print = output + ngx.say = function (...) + local ok, err = output(...) + if ok then + return output("\\\\n") + end + return ok, err + end + print = ngx.say + ngx.flush = function (...) return stdout:flush() end -- we cannot close stdout here due to a bug in Lua: ngx.eof = function (...) return true end