summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xinclude/luaglue/LuaVM.hpp7
-rw-r--r--src/crawl/crawl.conf4
-rwxr-xr-xsrc/crawl/crawl.cpp5
-rw-r--r--src/libluaglue/LuaVM.cpp34
4 files changed, 45 insertions, 5 deletions
diff --git a/include/luaglue/LuaVM.hpp b/include/luaglue/LuaVM.hpp
index 48faaeb..a8a6524 100755
--- a/include/luaglue/LuaVM.hpp
+++ b/include/luaglue/LuaVM.hpp
@@ -3,19 +3,24 @@
#include "lua.hpp"
+#include <string>
+
class LuaVM
{
public:
LuaVM( );
~LuaVM( );
- void loadSource( const char *filename );
+ void loadSource( const char *sourceFilename );
+ void executeMain( );
+ void dumpState( );
private:
void initialize( );
private:
lua_State *m_lua;
+ std::string m_sourceFilename;
};
#endif
diff --git a/src/crawl/crawl.conf b/src/crawl/crawl.conf
index 1717bb9..ddc1da6 100644
--- a/src/crawl/crawl.conf
+++ b/src/crawl/crawl.conf
@@ -7,6 +7,10 @@ crawler = {
}
+logger = {
+ level = DEBUG
+}
+
-- seeds: URLS which are fed in the beginning to the URL frontier
seeds = {
diff --git a/src/crawl/crawl.cpp b/src/crawl/crawl.cpp
index f10075f..4f3eb00 100755
--- a/src/crawl/crawl.cpp
+++ b/src/crawl/crawl.cpp
@@ -66,7 +66,8 @@ int main( int /* argc */, char *argv[] )
Logger::instance( ).openConsoleLog( logDEBUG );
luaVm.loadSource( argv[1] );
-
+ luaVm.executeMain( );
+
#ifndef _WIN32
struct sigaction sa;
memset( &sa, 0, sizeof( struct sigaction ) );
@@ -277,6 +278,8 @@ int main( int /* argc */, char *argv[] )
frontiers.destroy( frontier );
LOG( logNOTICE ) << "Crawler stopped.. normal shutdown..";
+
+ luaVm.dumpState( );
return 0;
} catch( exception &e ) {
diff --git a/src/libluaglue/LuaVM.cpp b/src/libluaglue/LuaVM.cpp
index 9363cac..7c1ce51 100644
--- a/src/libluaglue/LuaVM.cpp
+++ b/src/libluaglue/LuaVM.cpp
@@ -2,6 +2,7 @@
#include <stdexcept>
#include <sstream>
+#include <iostream>
using namespace std;
@@ -22,15 +23,42 @@ void LuaVM::initialize( )
luaL_openlibs( m_lua );
}
-void LuaVM::loadSource( const char *filename )
+void LuaVM::loadSource( const char *sourceFilename )
{
int res;
- res = luaL_loadfile( m_lua, filename );
+ m_sourceFilename.assign( sourceFilename );
+
+ res = luaL_loadfile( m_lua, m_sourceFilename.c_str( ) );
+ if( res != 0 ) {
+ ostringstream ss;
+ ss << "Can't read Lua source file from file '" << m_sourceFilename << "': " << lua_tostring( m_lua, -1 );
+ lua_pop( m_lua, 1 );
+ throw std::runtime_error( ss.str( ) );
+ }
+}
+
+void LuaVM::executeMain( )
+{
+ int res;
+
+ res = lua_pcall( m_lua, 0, LUA_MULTRET, 0 );
if( res != 0 ) {
ostringstream ss;
- ss << "Can't read Lua source file from file '" << filename << "': " << lua_tostring( m_lua, -1 );
+ ss << "Can't execute main body of Lua source file '" << m_sourceFilename << "': " << lua_tostring( m_lua, -1 );
lua_pop( m_lua, 1 );
throw std::runtime_error( ss.str( ) );
}
}
+
+void LuaVM::dumpState( )
+{
+ lua_rawgeti( m_lua, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS );
+ lua_pushnil( m_lua );
+ while( lua_next( m_lua, -2 ) ) {
+ if( lua_type( m_lua, -2 ) == LUA_TSTRING ) {
+ cout << lua_tostring( m_lua, -2 ) << endl;
+ }
+ lua_pop( m_lua, 1 );
+ }
+}