diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2014-10-04 22:43:38 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2014-10-04 22:43:38 +0200 |
commit | 62901873f5b7e37beb81037caae5808396528270 (patch) | |
tree | c89401e4a293144f850b1d81a3c533912ae145c6 /tests | |
parent | 6dd4e6dcdd17accb4e2884d3acc78dfed3aa3ed7 (diff) | |
download | crawler-62901873f5b7e37beb81037caae5808396528270.tar.gz crawler-62901873f5b7e37beb81037caae5808396528270.tar.bz2 |
first experiments with tolua and Lua glue code in a module and how to
make it usable in a Lua script
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/tolua/Base.hpp | 11 | ||||
-rw-r--r-- | tests/tolua/GNUmakefile | 40 | ||||
-rwxr-xr-x | tests/tolua/libtest1/GNUmakefile | 48 | ||||
-rwxr-xr-x | tests/tolua/libtest1/TestMod.cpp | 23 | ||||
-rwxr-xr-x | tests/tolua/libtest1/TestMod.hpp | 20 | ||||
-rw-r--r-- | tests/tolua/libtest1/TestMod.pkg | 10 | ||||
-rwxr-xr-x | tests/tolua/test1.cpp | 43 | ||||
-rw-r--r-- | tests/tolua/test1.lua | 1 |
8 files changed, 196 insertions, 0 deletions
diff --git a/tests/tolua/Base.hpp b/tests/tolua/Base.hpp new file mode 100755 index 0000000..db6a8ad --- /dev/null +++ b/tests/tolua/Base.hpp @@ -0,0 +1,11 @@ +#ifndef __BASE_H +#define __BASE_H + +class Base +{ + public: + virtual ~Base( ) { } + virtual void hello( ) = 0; +}; + +#endif diff --git a/tests/tolua/GNUmakefile b/tests/tolua/GNUmakefile new file mode 100644 index 0000000..124c959 --- /dev/null +++ b/tests/tolua/GNUmakefile @@ -0,0 +1,40 @@ +TOPDIR = ../.. + +SUBDIRS = libtest1 + +#INCLUDE_CXXFLAGS = \ +# -DUSE_MODULELOADER + +INCLUDE_DIRS = \ + -I. \ + -I$(TOPDIR)/include/luaglue \ + -I$(TOPDIR)/include/logger \ + -I$(TOPDIR)/include/util \ + -I$(TOPDIR)/include/module + +INCLUDE_LDFLAGS = \ + -L$(TOPDIR)/src/libluaglue \ + -L$(TOPDIR)/src/liblogger + +INCLUDE_LIBS = \ + -lluaglue \ + -llua \ + -llogger + +TEST_CPP_BINS = \ + test1$(EXE) + +OBJS = + +-include $(TOPDIR)/makefiles/gmake/sub.mk + +local_all: + +local_clean: + +local_distclean: + +LD_LIBRARY_PATH=$(TOPDIR)/src/libutil:$(TOPDIR)/src/liblogger:$(TOPDIR)/src/libcrawler:$(TOPDIR)/src/libluaglue + +local_test: + LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) ./test1 test1.lua diff --git a/tests/tolua/libtest1/GNUmakefile b/tests/tolua/libtest1/GNUmakefile new file mode 100755 index 0000000..9393a93 --- /dev/null +++ b/tests/tolua/libtest1/GNUmakefile @@ -0,0 +1,48 @@ +TOPDIR = ../../.. + +SUBDIRS = + +-include $(TOPDIR)/makefiles/gmake/platform.mk + +INCLUDE_DIRS = \ + -I. -I$(TOPDIR)/src -I.. \ + -I$(TOPDIR)/include/module \ + -I$(TOPDIR)/include/util + +INCLUDE_CXXFLAGS = \ + +INCLUDE_LDFLAGS = \ + -L$(TOPDIR)/src/libcrawler + +INCLUDE_LIBS = \ + -lcrawler \ + -ltolua + +DYNAMIC_MODULE = \ + mod_test.so + +STATIC_LIB = \ + libtest.a + +CPP_OBJS = \ + TestMod.o \ + TestModLua.o + +-include $(TOPDIR)/makefiles/gmake/sub.mk + +TestModLua.cpp: TestMod.pkg + tolua -H TestModLua.hpp -o TestModLua.cpp TestMod.pkg + +local_all: + +local_clean: + @-rm TestModLua.cpp TestModLua.hpp + +local_distclean: + +local_install: + +local_uninstall: + +local_test: + diff --git a/tests/tolua/libtest1/TestMod.cpp b/tests/tolua/libtest1/TestMod.cpp new file mode 100755 index 0000000..491001c --- /dev/null +++ b/tests/tolua/libtest1/TestMod.cpp @@ -0,0 +1,23 @@ +#include "TestMod.hpp" +#include "tolua.h" +#include "TestModLua.hpp" + +#include <iostream> + +using namespace std; + +void Derived::hello( ) +{ + cout << "hello" << endl; +} + +static void initModule( ) +{ +// tolua_TestMod_open( 0 /* m_lua, where from? */ ); +} + +static void destroyModule( ) +{ +} + +REGISTER_MODULE( "testmod", &initModule, &destroyModule, Base, Derived ) diff --git a/tests/tolua/libtest1/TestMod.hpp b/tests/tolua/libtest1/TestMod.hpp new file mode 100755 index 0000000..f4886cd --- /dev/null +++ b/tests/tolua/libtest1/TestMod.hpp @@ -0,0 +1,20 @@ +#ifndef __TESTMOD_H +#define __TESTMOD_H + +#include "Base.hpp" + +#include "ModuleRegistry.hpp" + +class Derived : public Base +{ + public: + Derived( ) { } + + virtual ~Derived( ) { } + + virtual void hello( ); +}; + +DECLARE_MODULE( Base ) + +#endif diff --git a/tests/tolua/libtest1/TestMod.pkg b/tests/tolua/libtest1/TestMod.pkg new file mode 100644 index 0000000..4fed1d3 --- /dev/null +++ b/tests/tolua/libtest1/TestMod.pkg @@ -0,0 +1,10 @@ +$#include "TestMod.hpp" + +class Derived : public Base +{ + Derived( ) { } + + virtual ~Derived( ) { } + + virtual void hello( ); +}; diff --git a/tests/tolua/test1.cpp b/tests/tolua/test1.cpp new file mode 100755 index 0000000..a2e91cb --- /dev/null +++ b/tests/tolua/test1.cpp @@ -0,0 +1,43 @@ +#include "Logger.hpp" +#include "LuaVM.hpp" +#include "ModuleLoader.hpp" +#include "Base.hpp" + +#include <stdexcept> +#include <vector> + +using namespace std; + +int main( int /* argc */, char *argv[] ) +{ + try { + Logger::instance( ).openConsoleLog( logDEBUG ); + + LuaVM luaVm; + + vector<string> modules; + modules.push_back( "./libtest1/mod_test.so" ); + ModuleLoader<Base> loader( modules ); + + Logger::instance( ).openConsoleLog( logDEBUG ); + + luaVm.loadSource( argv[1] ); + luaVm.executeMain( ); + + //luaVm.dumpState( ); + + //Base *obj = loader.create( "testmod" ); + //obj->hello( ); + //loader.destroy( obj ); + + return 0; + } catch( exception &e ) { + LOG( logFATAL ) << "ERROR: " << e.what( ); + return 1; + } catch( ... ) { + LOG( logFATAL ) << "ERROR: unknown exception!"; + return 1; + } + + return 0; +} diff --git a/tests/tolua/test1.lua b/tests/tolua/test1.lua new file mode 100644 index 0000000..20d97cf --- /dev/null +++ b/tests/tolua/test1.lua @@ -0,0 +1 @@ +local b = Derived:new( ) |