From c757efa3ee6f395e3ada3088065c73eb953f6834 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Tue, 14 Oct 2014 13:08:41 +0200 Subject: added initialize_libcrawler instead of silly tolua trick in the main program --- include/crawler/libcrawler.hpp | 6 ++++++ src/crawl/GNUmakefile | 4 ---- src/crawl/crawl.cpp | 14 +++----------- src/libcrawler/GNUmakefile | 10 ++++++++-- src/libcrawler/Makefile.W32 | 6 ++++-- src/libcrawler/URL.cpp | 2 -- src/libcrawler/libcrawler.cpp | 18 ++++++++++++++++++ 7 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 include/crawler/libcrawler.hpp create mode 100644 src/libcrawler/libcrawler.cpp diff --git a/include/crawler/libcrawler.hpp b/include/crawler/libcrawler.hpp new file mode 100644 index 0000000..a615bc9 --- /dev/null +++ b/include/crawler/libcrawler.hpp @@ -0,0 +1,6 @@ +#ifndef __LIBCRAWLER_H +#define __LIBCRAWLER_H + +void initialize_libcrawler( void *user_data ); + +#endif diff --git a/src/crawl/GNUmakefile b/src/crawl/GNUmakefile index 5a9051a..cea25f5 100755 --- a/src/crawl/GNUmakefile +++ b/src/crawl/GNUmakefile @@ -36,10 +36,6 @@ endif ifeq ($(WITH_LUA),1) INCLUDE_CXXFLAGS += \ -DWITH_LUA - -INCLUDE_DIRS += \ - -I$(TOPDIR)/src/libcrawler \ - $(TOLUA_INCLUDES) endif CPP_OBJS = \ diff --git a/src/crawl/crawl.cpp b/src/crawl/crawl.cpp index 4abd37c..648060c 100755 --- a/src/crawl/crawl.cpp +++ b/src/crawl/crawl.cpp @@ -6,6 +6,7 @@ #include "URLNormalizer.hpp" #include "URLFilter.hpp" #include "TypeDetect.hpp" +#include "libcrawler.hpp" #include "ModuleLoader.hpp" @@ -55,18 +56,14 @@ BOOL WINAPI termHandler( DWORD ctrlType ) #endif -#ifdef WITH_LUA -// TODO: should be in the laoding function of libcrawl -#include "tolua.h" -#include "URLLua.hpp" -#endif - static int counter = 0; int main( int /* argc */, char *argv[] ) { try { LuaVM luaVm; + + initialize_libcrawler( (void *)&luaVm ); //Logger::instance( ).openConsoleLog( logDEBUG ); @@ -107,11 +104,6 @@ int main( int /* argc */, char *argv[] ) #endif ModuleLoader urlNormalizers( normalizerModules, CLOSE_DEFERRED, (void *)&luaVm ); -#ifdef WITH_LUA - // TODO: should be in the laoding function of libcrawl - tolua_URL_open( luaVm.handle( ) ); -#endif - // initialize crawler function luaVm.executeFunction( "init" ); diff --git a/src/libcrawler/GNUmakefile b/src/libcrawler/GNUmakefile index d546058..e337c4f 100755 --- a/src/libcrawler/GNUmakefile +++ b/src/libcrawler/GNUmakefile @@ -4,7 +4,12 @@ SUBDIRS = -include $(TOPDIR)/makefiles/gmake/platform.mk -INCLUDE_CPPFLAGS = \ +INCLUDE_CXXFLAGS = \ + +ifeq ($(WITH_LUA),1) +INCLUDE_CXXFLAGS += \ + -DWITH_LUA +endif INCLUDE_LDFLAGS = \ @@ -43,7 +48,8 @@ DYNAMIC_LIB_PATCH = 0 CPP_OBJS = \ URL.o \ MIMEType.o \ - SpoolRewindInputStream.o + SpoolRewindInputStream.o \ + libcrawler.o ifeq ($(WITH_LUA),1) CPP_OBJS += \ diff --git a/src/libcrawler/Makefile.W32 b/src/libcrawler/Makefile.W32 index d3cd06c..716fef0 100755 --- a/src/libcrawler/Makefile.W32 +++ b/src/libcrawler/Makefile.W32 @@ -45,7 +45,8 @@ INCLUDE_LIBS = $(INCLUDE_LIBS) \ CPP_OBJS = \ URL.obj \ MIMEType.obj \ - SpoolRewindInputStream.obj + SpoolRewindInputStream.obj \ + libcrawler.obj !IFDEF WITH_LUA CPP_OBJS = $(CPP_OBJS) \ @@ -55,7 +56,8 @@ CPP_OBJS = $(CPP_OBJS) \ DYNAMIC_CPP_OBJS = \ URL.dllobj \ MIMEType.dllobj \ - SpoolRewindInputStream.dllobj + SpoolRewindInputStream.dllobj \ + libcrawler.dllobj !IFDEF WITH_LUA DYNAMIC_CPP_OBJS = $(DYNAMIC_CPP_OBJS) \ diff --git a/src/libcrawler/URL.cpp b/src/libcrawler/URL.cpp index f208500..6128edc 100644 --- a/src/libcrawler/URL.cpp +++ b/src/libcrawler/URL.cpp @@ -1,5 +1,3 @@ #include "URL.hpp" URL URL::Null; - - diff --git a/src/libcrawler/libcrawler.cpp b/src/libcrawler/libcrawler.cpp new file mode 100644 index 0000000..0c549a4 --- /dev/null +++ b/src/libcrawler/libcrawler.cpp @@ -0,0 +1,18 @@ +#include "libcrawler.hpp" + +#include + +#ifdef WITH_LUA +#include "tolua.h" +#include "URLLua.hpp" +#include "LuaVM.hpp" +#endif + +void initialize_libcrawler( void *user_data ) +{ +#ifdef WITH_LUA + LuaVM *vm = (LuaVM *)user_data; + tolua_URL_open( vm->handle( ) ); +#endif +} + -- cgit v1.2.3-54-g00ecf