From 08be1164cbaa7ec69bd229e138d3ad86b169f68f Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 5 Oct 2014 12:39:48 +0200 Subject: trying to initialize tolua glue code in test module, segfaulting still --- include/luaglue/LuaVM.hpp | 2 ++ src/libluaglue/LuaVM.cpp | 5 +++++ tests/tolua/libtest1/GNUmakefile | 3 ++- tests/tolua/libtest1/TestMod.cpp | 7 +++++-- tests/tolua/test1.cpp | 4 +--- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/luaglue/LuaVM.hpp b/include/luaglue/LuaVM.hpp index a8a6524..f25cc3e 100755 --- a/include/luaglue/LuaVM.hpp +++ b/include/luaglue/LuaVM.hpp @@ -14,6 +14,8 @@ class LuaVM void loadSource( const char *sourceFilename ); void executeMain( ); void dumpState( ); + + lua_State *handle( ); private: void initialize( ); diff --git a/src/libluaglue/LuaVM.cpp b/src/libluaglue/LuaVM.cpp index 7c1ce51..cf8935f 100644 --- a/src/libluaglue/LuaVM.cpp +++ b/src/libluaglue/LuaVM.cpp @@ -16,6 +16,11 @@ LuaVM::~LuaVM( ) lua_close( m_lua ); } +lua_State *LuaVM::handle( ) +{ + return m_lua; +} + void LuaVM::initialize( ) { m_lua = luaL_newstate( ); diff --git a/tests/tolua/libtest1/GNUmakefile b/tests/tolua/libtest1/GNUmakefile index 9393a93..b53a1b2 100755 --- a/tests/tolua/libtest1/GNUmakefile +++ b/tests/tolua/libtest1/GNUmakefile @@ -7,7 +7,8 @@ SUBDIRS = INCLUDE_DIRS = \ -I. -I$(TOPDIR)/src -I.. \ -I$(TOPDIR)/include/module \ - -I$(TOPDIR)/include/util + -I$(TOPDIR)/include/util \ + -I$(TOPDIR)/include/luaglue INCLUDE_CXXFLAGS = \ diff --git a/tests/tolua/libtest1/TestMod.cpp b/tests/tolua/libtest1/TestMod.cpp index 491001c..912d652 100755 --- a/tests/tolua/libtest1/TestMod.cpp +++ b/tests/tolua/libtest1/TestMod.cpp @@ -1,6 +1,7 @@ #include "TestMod.hpp" #include "tolua.h" #include "TestModLua.hpp" +#include "LuaVM.hpp" #include @@ -11,9 +12,11 @@ void Derived::hello( ) cout << "hello" << endl; } -static void initModule( ) +static void initModule( void *user_data ) { -// tolua_TestMod_open( 0 /* m_lua, where from? */ ); + LuaVM *luaVm = (LuaVM *)user_data; + + tolua_TestMod_open( luaVm->handle( ) ); } static void destroyModule( ) diff --git a/tests/tolua/test1.cpp b/tests/tolua/test1.cpp index a2e91cb..fe2801a 100755 --- a/tests/tolua/test1.cpp +++ b/tests/tolua/test1.cpp @@ -17,9 +17,7 @@ int main( int /* argc */, char *argv[] ) vector modules; modules.push_back( "./libtest1/mod_test.so" ); - ModuleLoader loader( modules ); - - Logger::instance( ).openConsoleLog( logDEBUG ); + ModuleLoader loader( modules, (void *)&luaVm ); luaVm.loadSource( argv[1] ); luaVm.executeMain( ); -- cgit v1.2.3-54-g00ecf