summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-10-01 20:30:01 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2014-10-01 20:30:01 +0200
commitee52b3eab8cc7feb49fa6db964b94b35e2bc8bac (patch)
tree19836bc002121846a897e1d54014d2bed8278422 /src
parenta8b82e12caea9f2ef6ea57239be47e31a7bba5c9 (diff)
downloadcrawler-ee52b3eab8cc7feb49fa6db964b94b35e2bc8bac.tar.gz
crawler-ee52b3eab8cc7feb49fa6db964b94b35e2bc8bac.tar.bz2
reading some Lua globals
Diffstat (limited to 'src')
-rw-r--r--src/crawl/crawl.conf4
-rwxr-xr-xsrc/crawl/crawl.cpp5
-rw-r--r--src/libluaglue/LuaVM.cpp34
3 files changed, 39 insertions, 4 deletions
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 );
+ }
+}