Re: Binded C++ Class In DLL
kuku super <[email protected]> Thu, 30 Jun 2011 15:18:33 +0800
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
i found the reason. because, luabind bind the .property member use the property_tag function pointer. so when bind the member in a dll with the property_tag pointer in the dll and when set the member in the .exe, the luabind::detail::class_rep::settable(lua_State* L) compare the pointer setted by dll and the &property_tag in .exe. of course they were different. so the problem occured. that's the bug. i solved this problem by setting property_tag a const pointer temporarily. would it be fixed? On Thu, Jun 30, 2011 at 11:19 AM, kuku super <[email protected]>wrote: > it's a simple example about this error, and i still have no idea..... > > ---------------------------BINDDLL.h-------------------------- > #ifndef BINDDLL_H > #define BINDDLL_H > > > #ifdef BINDDLL_EXPORTS > #define DLLEXPORT __declspec(dllexport) > #define DLLIMPORT __declspec(dllimport) > #else > #define DLLEXPORT > #define DLLIMPORT > #endif > > struct lua_State; > > bool DLLEXPORT Bind(lua_State* pState); > > #endif > > -------------------------------BINDDLL.cpp------------------------------- > -------------------------------just bind the BindTestClass > class---------------------------- > #include "BindDLL.h" > > #include <luabind/luabind.hpp> > #include <luabind/lua_include.hpp> > #include <luabind/operator.hpp> > #include <luabind/detail/convert_to_lua.hpp> > #include <luabind/iterator_policy.hpp> > > class BindTestClass > { > public: > int GetA() > { > return a; > } > void SetA(int i) > { > a = i; > } > int a; > char str[10]; > }; > > > static luabind::object Getstr(BindTestClass &bindTestClass, lua_State *L) > { > return luabind::object(L, bindTestClass.str); > } > > static void Setstr(BindTestClass &bindTestClass, luabind::argument const& > table) > { > strcpy_s(bindTestClass.str, 10, luabind::object_cast<const char*>(table)); > } > > > bool DLLEXPORT Bind(lua_State* pState) > { > luabind::object g = luabind::globals(pState); > > luabind::module(pState) > [ > luabind::class_<BindTestClass>("BindTestClass") > .def(luabind::constructor<>()) > .def_readwrite("a", &BindTestClass::a) > .property("str", Getstr, Setstr, luabind::raw(_2)) > ]; > > return true; > > } > > > ---------------------------------------LuaBindTestMain.cpp---------------------------------------------------- > > ----------------------------------------1-------------------------------------------------------------------------------- > > #include "BindDLL.h" > #include <luabind/luabind.hpp> > #include <luabind/lua_include.hpp> > #include <luabind/operator.hpp> > #include <luabind/detail/convert_to_lua.hpp> > #include <luabind/iterator_policy.hpp> > > class BindTestClass > { > public: > int GetA() > { > return a; > } > void SetA(int i) > { > a = i; > } > int a; > char str[10]; > }; > > static luabind::object Getstr(BindTestClass &bindTestClass, lua_State *L) > { > return luabind::object(L, bindTestClass.str); > } > > static void Setstr(BindTestClass &bindTestClass, luabind::argument const& > table) > { > strcpy_s(bindTestClass.str, 10, luabind::object_cast<const > char*>(table)); > } > > void main() > { > lua_State *pL = lua_open(); > > luaL_openlibs(pL); > luabind::open(pL); > luabind::object g = luabind::globals(pL); > luabind::module(pL) > [ > luabind::class_<BindTestClass>("BindTestClass") > .def(luabind::constructor<>()) > .def_readwrite("a", &BindTestClass::a) > .property("str", Getstr, Setstr, luabind::raw(_2)) > ]; > > //Bind(pL); > > int iRet = luaL_dostring(pL, > "local obj = BindTestClass();" > "obj.str = \"aaa\";" > ); > > if (iRet != 0) > { > printf("luaL_dostring failed:%s", lua_tostring(pL, -1)); > lua_pop(pL, 1); > } > > } > > > ---------------------------------------LuaBindTestMain.cpp---------------------------------------------------- > > ----------------------------------------2-------------------------------------------------------------------------------- > > #include "BindDLL.h" > #include <luabind/luabind.hpp> > #include <luabind/lua_include.hpp> > #include <luabind/operator.hpp> > #include <luabind/detail/convert_to_lua.hpp> > #include <luabind/iterator_policy.hpp> > > class BindTestClass > { > public: > int GetA() > { > return a; > } > void SetA(int i) > { > a = i; > } > int a; > char str[10]; > }; > > void main() > { > lua_State *pL = lua_open(); > > luaL_openlibs(pL); > luabind::open(pL); > > Bind(pL); > > int iRet = luaL_dostring(pL, > "local obj = BindTestClass();" > "obj.str = \"aaa\";" > ); > > if (iRet != 0) > { > printf("luaL_dostring failed:%s", lua_tostring(pL, -1)); > lua_pop(pL, 1); > } > > } > > > ------------------------------------------------------------------------------Code > end-------------------------------- > BindDLL.h and BindDll.cpp is in the DLL project. and luaBindTestMain.cpp is > exe project's code file. > > if i use the 1 LuaBindTestMain.cpp. "obj.str = "aaa;"" will call the > Setstr Function > and if i use the 2 LuaBindTestMain.cpp, "obj.str = "aaa;"" won't call the > Setstr Function > > > help please! > > > ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2d-c2 _______________________________________________ luabind-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/luabind-user