From: Francesco M. <fr...@us...> - 2006-05-20 12:18:51
|
Update of /cvsroot/wxlua/wxLua/modules/luamodule/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv22340/modules/luamodule/src Added Files: Makefile luamodule.cpp Log Message: added luamodule --- NEW FILE: luamodule.cpp --- ///////////////////////////////////////////////////////////////////////////// // Purpose: wxLuaModuleApp - code to allow wxLua to be used as a module using require"wx" // Author: John Labenski, J Winwood // Created: 14/11/2001 // Copyright: (c) 2001-2002 Lomtick Software. All rights reserved. // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// #include "wx/wx.h" #include "wxlua/include/wxlstate.h" extern "C" { int luaopen_wx(lua_State *L); // force C linkage w/o name mangling } static wxLuaState s_wxlState; // This is our wxLuaState for the module // Declare the binding initialization functions as extern so we don't have to // #include the binding header for simplicity. extern bool wxLuaBinding_wx_init(); extern bool wxLuaBinding_wxstc_init(); // ---------------------------------------------------------------------------- // wxLuaModuleApp // ---------------------------------------------------------------------------- class wxLuaModuleApp : public wxApp { public: wxLuaModuleApp() : wxApp() {} // Override the base class virtual functions bool OnInit(); int OnExit(); int MainLoop(); void OnLua( wxLuaEvent &event ); void DisplayError(const wxString &errorStr) const; private: DECLARE_ABSTRACT_CLASS(wxLuaModuleApp); DECLARE_EVENT_TABLE(); }; // ---------------------------------------------------------------------------- // wxLuaModuleApp // ---------------------------------------------------------------------------- IMPLEMENT_ABSTRACT_CLASS(wxLuaModuleApp, wxApp); IMPLEMENT_APP_NO_MAIN(wxLuaModuleApp) BEGIN_EVENT_TABLE(wxLuaModuleApp, wxApp) EVT_LUA_PRINT (wxID_ANY, wxLuaModuleApp::OnLua) EVT_LUA_ERROR (wxID_ANY, wxLuaModuleApp::OnLua) //EVT_LUA_DEBUG_HOOK (wxID_ANY, wxLuaModuleApp::OnLua) END_EVENT_TABLE() // Override the base class virtual functions bool wxLuaModuleApp::OnInit() { return true; } int wxLuaModuleApp::OnExit() { int retval = 0; wxApp::OnExit(); return retval; } int wxLuaModuleApp::MainLoop() { // only run the mainloop if there are any toplevel windows int retval = 0; bool initialized = (wxTopLevelWindows.GetCount() != 0); if (initialized) retval = wxApp::MainLoop(); return retval; } void wxLuaModuleApp::OnLua( wxLuaEvent &event ) { DisplayError(event.GetString()); } void wxLuaModuleApp::DisplayError(const wxString &errorStr) const { #ifdef __WXMSW__ wxMessageBox(errorStr, wxT("wxLua")); #else wxPrintf(wxT("%s\n"), errorStr.c_str()); #endif } // ---------------------------------------------------------------------------- // luaopen_wx the C function for require to call // ---------------------------------------------------------------------------- wxLuaModuleApp* app = NULL; int luaopen_wx(lua_State *L) { // only initialize the wxLuaState once, allows require to be called more than once if (!s_wxlState.Ok()) { int argc = 0; wxChar **argv = NULL; wxEntryStart(argc, argv); wxTheApp->CallOnInit(); wxTheApp->SetExitOnFrameDelete(true); wxInitAllImageHandlers(); wxLuaBinding_wx_init(); s_wxlState.Create(L, WXLUASTATE_SETSTATE); s_wxlState.SetEventHandler((wxEvtHandler*)wxTheApp); } lua_getglobal(L, "wx"); // push global wx table on the stack return 1; } --- NEW FILE: Makefile --- # File: Makefile # Author: John Labenski, J Winwood # Created: 2004 # Updated: # Copyright: (c) 2002. J Winwood # # Makefile for wxLua standalone sample using gmake # --- wxLua parameters ------------------------------------------------------- WXLUA_LIBVERSION_CURRENT = 1 WXLUA_LIBVERSION_REVISION = 5 WXLUA_LIBVERSION_AGE = 0 WXLUA_DIR = ../../.. WXLUA_LIBDIR = $(WXPREFIX)/lib LUA = $(WXLUA_DIR)/bin/lua # --- wxWidgets parameters from wx-config ------------------------------------ WXCONFIG := wx-config WXPREFIX = $(shell $(WXCONFIG) --prefix) WXEXECDIR = $(shell $(WXCONFIG) --exec-prefix) WXBASENAME = $(shell $(WXCONFIG) --basename) WXVERSION = $(shell $(WXCONFIG) --version) WXRELEASE = $(shell $(WXCONFIG) --release) WXCXXFLAGS = $(shell $(WXCONFIG) --cxxflags) WXLDLIBS = $(shell $(WXCONFIG) --libs) WXCXX = $(shell $(WXCONFIG) --cxx) WXLIB_DIR = $(WXEXECDIR)/lib # ---------------------------------------------------------------------------- CXXFLAGS = $(WXCXXFLAGS) -MMD -g -Wall LDLIBS = $(WXLDLIBS) CXX = $(WXCXX) PROGRAM = wx.so LUA_LIBS = $(WXLUA_DIR)/lib/liblua.a WXLUA_LIB = $(WXBASENAME)_wxlua-$(WXRELEASE) WXLUADEBUG_LIB = $(WXBASENAME)_wxluadebug-$(WXRELEASE) WXLUASOCKET_LIB = $(WXBASENAME)_wxluasocket-$(WXRELEASE) WXLUABIND_LIB = $(WXBASENAME)_wxluabind-$(WXRELEASE) WXLUASTC_LIB = $(WXBASENAME)_wxluastc-$(WXRELEASE) WXSTC_LIB = $(WXBASENAME)_stc-$(WXRELEASE) WXXRC_LIB = $(WXBASENAME)_xrc-$(WXRELEASE) WXFL_LIB = $(WXBASENAME)_fl-$(WXRELEASE) APPEXTRADEFS = -I$(WXLUA_DIR) -I$(WXLUA_DIR)/modules -I$(WXPREFIX)/contrib/include -fexceptions -DLUACALL= -DWXLUA_LUA_NEWTHREAD # This will build a static wxLua app, staticly linked to .a libs #APPEXTRALIBS=-L$(WXLIB_DIR) $(WXLIB_DIR)/lib$(WXLUA_LIB).a $(WXLIB_DIR)/lib$(STC_LIB).a $(WXLIB_DIR)/lib$(WXXRC_LIB).a $(WXLIB_DIR)/lib$(WXFL_LIB).a $(LUA_LIBS) # This will build a shared wxLua app, dynamicly linked to .so libs # -l$(WXFL_LIB) APPEXTRALIBS=-L$(WXLIB_DIR) -L$(WXLUA_LIBDIR) -l$(WXSTC_LIB) -l$(WXXRC_LIB) -l$(WXLUABIND_LIB) -l$(WXLUASTC_LIB) -l$(WXLUA_LIB) -l$(WXLUADEBUG_LIB) -l$(WXLUASOCKET_LIB) #OBJECTS=luamodule.o #DEPFILES=$(OBJECTS:.o=.d) # NOTE: this works too #wx.so: luamodule.cpp # gcc -I../modules/ `wx-config --cxxflags` -g -O -shared -o wx.so -fpic \ # ~/wx/wx/config_gtk2/lib/libwx_gtk2ud_wxlua-2.7.so \ # ~/wx/wx/config_gtk2/lib/libwx_gtk2ud_wxluabind-2.7.so \ # ~/wx/wx/config_gtk2/lib/libwx_gtk2ud_wxluadebug-2.7.so \ # ~/wx/wx/config_gtk2/lib/libwx_gtk2ud_wxluasocket-2.7.so \ # `wx-config --libs` luamodule.cpp .cpp.o: $(CXX) -c $(CXXFLAGS) $(APPEXTRADEFS) -o $@ $< all: lua wxLuaLib wxLuaDebugLib wxLuaSocketLib wxLuaBindings wxSTCBindings wx.so wx.so: luamodule.cpp $(OBJECTS) $(LUA_LIBS) wxLuaLib wxLuaDebugLib wxLuaSocketLib wxLuaBindings $(CXX) $(CXXFLAGS) $(APPEXTRADEFS) -g -O -shared -o wx.so -fpic \ $(LDLIBS) $(APPEXTRALIBS) \ luamodule.cpp lua: @(cd $(WXLUA_DIR)/modules/lua && make linux) wxwidgets_bindings: @(cd $(WXLUA_DIR)/bindings/wxwidgets && make) wxstc_bindings: @(cd $(WXLUA_DIR)/bindings/wxstc && make) wxLuaBindings: @(cd $(WXLUA_DIR)/modules/wxbind/src && make) wxSTCBindings: @(cd $(WXLUA_DIR)/modules/wxbindstc/src && make) wxLuaLib: @(cd $(WXLUA_DIR)/modules/wxlua/src && make) wxLuaDebugLib: @(cd $(WXLUA_DIR)/modules/wxluadebug/src && make) wxLuaSocketLib: @(cd $(WXLUA_DIR)/modules/wxluasocket/src && make) clean: rm -f $(OBJECTS) $(DEPFILES) $(PROGRAM) core cleanall: rm -f $(OBJECTS) $(DEPFILES) $(PROGRAM) core @(cd $(WXLUA_DIR)/modules/lua && make clean) @(cd $(WXLUA_DIR)/bindings/wxwidgets && make clean) @(cd $(WXLUA_DIR)/modules/wxbind/src && make clean) @(cd $(WXLUA_DIR)/modules/wxbindstc/src && make clean) @(cd $(WXLUA_DIR)/modules/wxlua/src && make clean) @(cd $(WXLUA_DIR)/modules/wxluadebug/src && make clean) @(cd $(WXLUA_DIR)/modules/wxluasocket/src && make clean) #-include $(DEPFILES) |