我使用 wxwdigets 做了一个类
//wrapper over wxIPV4address
class IPV4addressLua : public wxIPV4address
{
public:
IPV4addressLua();
~IPV4addressLua();
bool SetService (const wxString &service);
bool SetService (unsigned short service);
unsigned short GetService () const;
wxSockAddress* GetwxSockAddress();
wxIPV4address GetwxIPV4address();
wxSocketServer* GetwxSocketServer();
};
我像这样为 SWIG 输入制作 abc.i 文件
%module wxAppManagerLua
%{
#include "wxAppManager.h"
#include "wx/socket.h"
%}
//wxIPV4address 类 IPV4addressLua 的封装 //: public wxIPV4address ....................................
然后我编写 make 文件来生成 SWIG 绑定:===
TARGET= wxAppManagerLua.so
WRAPPER= wxAppManager_wrap.cxx
SRCS= $(ROOTSRC)/wxAppManager.cpp $(ROOTSRC)/XMLReader.cpp $(WRAPPER)
INTERFACE=wxAppManager.i
CC= g++
FLAGS=-shared -fPIC -DDEBUG=1
SWIGFLGS= -lua -c++ -includeall -v
RM=rm -rfv
all:$(WRAPPER)
$(TARGET) : $(SRCS)
$(CC) $(FLAGS) -o $(TARGET) $(SRCS) $(EXTRAINC) $(WXCONFIGFLGS)
$(WRAPPER):
swig $(SWIGFLGS) -I/usr/include $(EXTRAINC) $(INTERFACE)
clean:
$(RM) *.so* $(WRAPPER)
~
...
===== 我像这样生成我的:-
g++ -g -shared -fPIC -o wxAppManagerLua.so ./wxAppManager_wrap.cxx ./wxAppManager/src/XMLReader.cpp ./wxAppManager/src/wxAppManager.cpp -I./ -I./wxAppManager/inc/ -I/usr/local/lib/wx/include/gtk2-ansi-debug-2.8 -I/usr/local/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXDEBUG__ -D__WXGTK__ -pthread -L/usr/local/lib -pthread -lwx_gtk2d_richtext-2.8 -lwx_gtk2d_aui-2.8 -lwx_gtk2d_xrc-2.8 -lwx_gtk2d_qa-2.8 -lwx_gtk2d_html-2.8 -lwx_gtk2d_adv-2.8 -lwx_gtk2d_core-2.8 -lwx_based_xml-2.8 -lwx_based_net-2.8 -lwx_based-2.8
=====
我这样写我的lua文件:
function CreateServer()
-- Create the address - defaults to localhost:0 initially
local addr = wxAppManagerLua.IPV4addressLua()
if addr ~= nil then
print(" Calling Bind Port ")
addr:SetService(3000)
end
port = addr:GetService()
print(" Binded to Port "..port)
-- Create the socket
SockAddr = wx.wxSockAddress
--CODE FAILS HERE
SOCKSERVER = wx.wxSocketServer(addr)
…………
...
我的代码在最后一行失败说..
SockTestAppMgr.wx.lua:584: wxLua: 期望参数 1 有一个“wxSockAddress”,但得到一个“用户数据”。 函数调用:'wxSocketServer(userdata)' 01. wxSocketServer::wxSocketServer([wxSockAddress, integer]) 堆栈回溯: [C]:在函数“wxSocketServer”中 SockTestAppMgr.wx.lua:584:在函数“CreateServer”中 SockTestAppMgr.wx.lua:682:在函数'main'中 SockTestAppMgr.wx.lua:694:在主块中
===== 请注意..... wxSockAddess 是 wxIPV4address 的基类,我从中派生了我的类。
检查此链接http://docs.wxwidgets.org/trunk/classwx_i_paddress.html
任何人都可以帮忙吗?
我的诊断是:-
基本问题是每当我制作 sos 时......使用 SWIG 并尝试从 lua 引用函数或类......它工作正常,直到我引用任何 wxwidget 类或函数......即使我的两个 sos 也能够引用到跨sos的类......但不是wxwidgets类......虽然......如果我继续将wx.so的任何类引用到wx.so的任何其他类,它就可以工作......
请让我知道是什么阻止了 lua 理解我的类的类型到任何类的 wxwidgets。
我知道 wxwidgets 的绑定是通过传统方法生成的,而不是通过 SWIG 生成的 ..这会导致问题吗?