summaryrefslogtreecommitdiff
path: root/src/crawl/crawl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/crawl/crawl.cpp')
-rwxr-xr-xsrc/crawl/crawl.cpp43
1 files changed, 38 insertions, 5 deletions
diff --git a/src/crawl/crawl.cpp b/src/crawl/crawl.cpp
index 0698b75..24d6427 100755
--- a/src/crawl/crawl.cpp
+++ b/src/crawl/crawl.cpp
@@ -90,16 +90,15 @@ static vector<string> searchModuleFiles( const vector<string> &modules, const ve
return moduleFiles;
}
-static int lua_log( lua_State *l )
+static int lua_log_level( const LogLevel logLevel, lua_State *l )
{
size_t nofParams = lua_gettop( l );
if( nofParams == 0 ) return 0;
- const char *logLevel = luaL_checkstring( l, 1 );
ostringstream ss;
- for( size_t i = 2; i <= nofParams; i++ ) {
+ for( size_t i = 1; i <= nofParams; i++ ) {
int type = lua_type( l, i );
switch( type ) {
@@ -124,13 +123,32 @@ static int lua_log( lua_State *l )
}
}
- LOG( Logger::fromString( logLevel ) ) << ss.str( );
+ LOG( logLevel ) << ss.str( );
lua_pop( l, (int)nofParams );
return 0;
}
+
+#define lua_log( level ) \
+static int lua_log_ ## level( lua_State *l ) \
+{ \
+ return lua_log_level( log ## level, l ); \
+}
+
+lua_log( FATAL )
+lua_log( CRITICAL )
+lua_log( ERROR )
+lua_log( WARNING )
+lua_log( NOTICE )
+lua_log( INFO )
+lua_log( DEBUG )
+lua_log( DEBUG1 )
+lua_log( DEBUG2 )
+lua_log( DEBUG3 )
+lua_log( DEBUG4 )
+
int main( int /* argc */, char *argv[] )
{
try {
@@ -144,7 +162,22 @@ int main( int /* argc */, char *argv[] )
luaVm.loadSource( argv[1] );
// register logging function
- lua_pushcclosure( luaVm.handle( ), &lua_log, 0 );
+ luaL_Reg reg[12] = {
+ { "fatal", lua_log_FATAL },
+ { "critical", lua_log_CRITICAL },
+ { "error", lua_log_ERROR },
+ { "warning", lua_log_WARNING },
+ { "notice", lua_log_NOTICE },
+ { "info", lua_log_INFO },
+ { "debug", lua_log_DEBUG },
+ { "debug1", lua_log_DEBUG1 },
+ { "debug2", lua_log_DEBUG2 },
+ { "debug3", lua_log_DEBUG3 },
+ { "debug4", lua_log_DEBUG4 },
+ { NULL, NULL }
+ };
+ lua_newtable( luaVm.handle( ) );
+ luaL_setfuncs( luaVm.handle( ), reg, 0 );
lua_setglobal( luaVm.handle( ), "log" );
// execute main (to get basic configuration in form