@@ -346,7 +346,9 @@ LWAN_LUA_METHOD(request_date)
346
346
return 1 ;
347
347
}
348
348
349
- #define IMPLEMENT_LOG_FUNCTION (name ) \
349
+ #define FOR_EACH_LOG_FUNCTION (X ) X(info) X(warning) X(error) X(critical) X(debug)
350
+
351
+ #define IMPLEMENT_FUNCTION (name ) \
350
352
static int lwan_lua_log_##name(lua_State *L) \
351
353
{ \
352
354
size_t log_str_len = 0; \
@@ -355,26 +357,18 @@ LWAN_LUA_METHOD(request_date)
355
357
lwan_status_##name("%.*s", (int)log_str_len, log_str); \
356
358
return 0; \
357
359
}
358
-
359
- IMPLEMENT_LOG_FUNCTION (info )
360
- IMPLEMENT_LOG_FUNCTION (warning )
361
- IMPLEMENT_LOG_FUNCTION (error )
362
- IMPLEMENT_LOG_FUNCTION (critical )
363
-
364
- #undef IMPLEMENT_LOG_FUNCTION
360
+ FOR_EACH_LOG_FUNCTION (IMPLEMENT_FUNCTION )
361
+ #undef IMPLEMENT_FUNCTION
365
362
366
363
static int luaopen_log (lua_State * L )
367
364
{
368
365
static const char * metatable_name = "Lwan.log" ;
366
+ #define LOG_FUNCTION (name ) {#name, lwan_lua_log_##name},
369
367
static const struct luaL_Reg functions [] = {
370
- #define LOG_FUNCTION (name ) {#name , lwan_lua_log_##name}
371
- LOG_FUNCTION (info ),
372
- LOG_FUNCTION (warning ),
373
- LOG_FUNCTION (error ),
374
- LOG_FUNCTION (critical ),
375
- {},
376
- #undef LOG_FUNCTION
368
+ FOR_EACH_LOG_FUNCTION (LOG_FUNCTION )
369
+ {}
377
370
};
371
+ #undef LOG_FUNCTION
378
372
379
373
luaL_newmetatable (L , metatable_name );
380
374
luaL_register (L , metatable_name , functions );
0 commit comments