From 7c1364816bce2ecfad1ecc118225b1fa6f28faed Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Wed, 15 Oct 2014 16:44:27 +0200 Subject: added getstringarray to luavm layer --- include/luaglue/LuaVM.hpp | 2 ++ src/crawl/GNUmakefile | 1 + src/crawl/crawl.cpp | 16 +++++++++++++++- src/libluaglue/LuaVM.cpp | 28 ++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/include/luaglue/LuaVM.hpp b/include/luaglue/LuaVM.hpp index 488c810..81261f3 100755 --- a/include/luaglue/LuaVM.hpp +++ b/include/luaglue/LuaVM.hpp @@ -5,6 +5,7 @@ #include "lua.hpp" +#include #include class LuaVM @@ -25,6 +26,7 @@ class LuaVM LUAGLUE_DLL_VISIBLE void fullGarbageCollect( ); LUAGLUE_DLL_VISIBLE std::string getString( const std::string &key ); + LUAGLUE_DLL_VISIBLE std::vector getStringArray( const std::string &key ); LUAGLUE_DLL_VISIBLE bool getBoolean( const std::string &key ); LUAGLUE_DLL_VISIBLE lua_State *handle( ); diff --git a/src/crawl/GNUmakefile b/src/crawl/GNUmakefile index cea25f5..778a72a 100755 --- a/src/crawl/GNUmakefile +++ b/src/crawl/GNUmakefile @@ -8,6 +8,7 @@ INCLUDE_CPPFLAGS = \ INCLUDE_DIRS = \ -I. \ + -I$(TOPDIR)/include \ -I$(TOPDIR)/include/logger \ -I$(TOPDIR)/include/util \ -I$(TOPDIR)/include/module \ diff --git a/src/crawl/crawl.cpp b/src/crawl/crawl.cpp index 648060c..88f6aa3 100755 --- a/src/crawl/crawl.cpp +++ b/src/crawl/crawl.cpp @@ -14,6 +14,8 @@ #include "LuaVM.hpp" +#include "FileUtils.hpp" + #include #include #include @@ -93,7 +95,19 @@ int main( int /* argc */, char *argv[] ) bool modulesSearchRecursive = luaVm.getBoolean( "crawler.modules_search_recursive" ); LOG( logNOTICE ) << "Loading modules from path '" << modulePath << "' " << ( modulesSearchRecursive ? "(recursive)" : "" ); - + + vector entries = directory_entries( modulePath, true, modulesSearchRecursive ); + vector::const_iterator it, end = entries.end( ); + for( it = entries.begin( ); it != end; it++ ) { + cout << (*it) << endl; + } + + vector modules = luaVm.getStringArray( "modules.urlnormalizers" ); + end = modules.end( ); + for( it = modules.begin( ); it != end; it++ ) { + cout << (*it) << endl; + } + vector normalizerModules; #ifndef _WIN32 normalizerModules.push_back( "./modules/urlnormalizer/simpleurl/mod_urlnormalizer_simple.so" ); diff --git a/src/libluaglue/LuaVM.cpp b/src/libluaglue/LuaVM.cpp index 637f668..04027af 100644 --- a/src/libluaglue/LuaVM.cpp +++ b/src/libluaglue/LuaVM.cpp @@ -273,3 +273,31 @@ bool LuaVM::getBoolean( const string &key ) return res; } + +vector LuaVM::getStringArray( const string &key ) +{ + vector res; + + int n = findValue( key ); + + if( !lua_istable( m_lua, -1 ) ) { + lua_pop( m_lua, n ); + ostringstream ss; + ss << "key '" << key << "' refers not to a table"; + throw runtime_error( ss.str( ) ); + } + + //dumpStack( ); + + lua_pushvalue( m_lua, -1 ); + lua_pushnil( m_lua ); + while( lua_next( m_lua, -2 ) ) { + res.push_back( lua_tostring( m_lua, -1 ) ); + lua_pop( m_lua, 1 ); + } + lua_pop( m_lua, 1 ); + + lua_pop( m_lua, n ); + + return res; +} -- cgit v1.2.3-54-g00ecf