feature: allow use of ngx.null in ngx.log() and print() arguments.

This commit is contained in:
agentzh (章亦春) 2012-02-12 22:53:50 +08:00
Родитель 2f1c2a5e00
Коммит 96e9b3038e
2 изменённых файлов: 42 добавлений и 1 удалений

Просмотреть файл

@ -116,6 +116,14 @@ log_wrapper(ngx_http_request_t *r, const char *ident, int level, lua_State *L)
break;
case LUA_TLIGHTUSERDATA:
if (lua_touserdata(L, i) == NULL) {
size += sizeof("null") - 1;
break;
}
continue;
default:
msg = lua_pushfstring(L, "string, number, boolean, or nil "
"expected, got %s", lua_typename(L, type));
@ -161,6 +169,14 @@ log_wrapper(ngx_http_request_t *r, const char *ident, int level, lua_State *L)
break;
case LUA_TLIGHTUSERDATA:
*p++ = 'n';
*p++ = 'u';
*p++ = 'l';
*p++ = 'l';
break;
default:
return luaL_error(L, "impossible to reach here");
}

Просмотреть файл

@ -11,7 +11,7 @@ repeat_each(2);
#log_level('warn');
#worker_connections(1024);
plan tests => blocks() * repeat_each() * 2;
plan tests => repeat_each() * (blocks() * 3 + 1);
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
@ -38,6 +38,8 @@ GET /lua
--- response_body
true
null
--- no_error_log
[error]
@ -52,6 +54,8 @@ null
GET /lua
--- response_body
ngx.null: null
--- no_error_log
[error]
@ -66,4 +70,25 @@ ngx.null: null
GET /lua
--- response_body
ngx.null: null
--- no_error_log
[error]
=== TEST 4: log ngx.null
--- config
location /lua {
content_by_lua '
print("ngx.null: ", ngx.null)
ngx.say("done")
';
}
--- request
GET /lua
--- response_body
done
--- error_log
ngx.null: null
--- no_error_log
[error]