Following up my own issue...
I misunderstood the Luabind INSTALL instructions and so even though I built Luabind correctly, I was not specifying LUABIND_DYNAMIC_LINK when compiling my app. The symptom was (to me) rather odd: when I trapped the check for whether to use the property setter (ref. line 320 of class_rep.cpp where it does this:
if (lua_tocfunction(L, -1) == &property_tag) ...
), I found that the two sides were not equal, even though &property_tag is what was originally pushed on the stack:
Left side: 0x00411db1 luabind::detail::property_tag(struct lua_State *) int (lua_State *)*
Right side: 0x001a2690 luabind::detail::property_tag(lua_State *) int (lua_State *)*
Adding LUABIND_DYNAMIC_LINK fixes the problem but introduces a very ugly set of compile warnings:
Warning 1 warning C4251: 'luabind::detail::class_registry::m_classes' : class 'std::map<_Kty,_Ty,_Pr>' needs to have dll-interface to be used by clients of struct 'luabind::detail::class_registry' c:\saved_software\luabind-0.8.1\luabind\detail\class_registry.hpp 70
Warning 2 warning C4251: 'luabind::detail::object_rep::m_lua_table_ref' : struct 'luabind::detail::lua_reference' needs to have dll-interface to be used by clients of class 'luabind::detail::object_rep' c:\saved_software\luabind-0.8.1\luabind\detail\object_rep.hpp 79
Warning 3 warning C4251: 'luabind::detail::object_rep::m_dependency_ref' : struct 'luabind::detail::lua_reference' needs to have dll-interface to be used by clients of class 'luabind::detail::object_rep' c:\saved_software\luabind-0.8.1\luabind\detail\object_rep.hpp 82
Warning 4 warning C4251: 'luabind::detail::class_rep::m_bases' : class 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'luabind::detail::class_rep' c:\saved_software\luabind-0.8.1\luabind\detail\class_rep.hpp 327
Warning 5 warning C4251: 'luabind::detail::class_rep::m_self_ref' : struct 'luabind::detail::lua_reference' needs to have dll-interface to be used by clients of class 'luabind::detail::class_rep' c:\saved_software\luabind-0.8.1\luabind\detail\class_rep.hpp 340
Warning 6 warning C4251: 'luabind::detail::class_rep::m_table' : class 'luabind::handle' needs to have dll-interface to be used by clients of class 'luabind::detail::class_rep' c:\saved_software\luabind-0.8.1\luabind\detail\class_rep.hpp 347
Warning 7 warning C4251: 'luabind::detail::class_rep::m_default_table' : class 'luabind::handle' needs to have dll-interface to be used by clients of class 'luabind::detail::class_rep' c:\saved_software\luabind-0.8.1\luabind\detail\class_rep.hpp 351
Warning 8 warning C4251: 'luabind::detail::class_rep::m_getters' : class 'std::map<_Kty,_Ty,_Pr>' needs to have dll-interface to be used by clients of class 'luabind::detail::class_rep' c:\saved_software\luabind-0.8.1\luabind\detail\class_rep.hpp 365
Warning 9 warning C4251: 'luabind::detail::class_rep::m_setters' : class 'std::map<_Kty,_Ty,_Pr>' needs to have dll-interface to be used by clients of class 'luabind::detail::class_rep' c:\saved_software\luabind-0.8.1\luabind\detail\class_rep.hpp 366
Warning 10 warning C4251: 'luabind::detail::class_rep::m_operators' : class 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'luabind::detail::class_rep' c:\saved_software\luabind-0.8.1\luabind\detail\class_rep.hpp 368
Warning 11 warning C4251: 'luabind::detail::class_rep::m_static_constants' : class 'std::map<_Kty,_Ty,_Pr>' needs to have dll-interface to be used by clients of class 'luabind::detail::class_rep' c:\saved_software\luabind-0.8.1\luabind\detail\class_rep.hpp 373
Anyone know how to avoid those?
Thanks again,
Sean
seanmhogan wrote:
Hi. I'm having a devil of a time binding to a class property and then setting that property from Lua. I'm using Lua 5.1, Luabind 0.8.1, Boost 1.39 and Visual Studio 2005.
The C++ code:
struct Tough
{
Tough(){}
~Tough(){}
int Tough::get_i() const { return i; }
void Tough::set_i(int _i) { i = _i; }
int i;
};
int main()
{
lua_State* L = lua_open();
luaL_openlibs(L);
luabind::open(L);
module(L) [
class_<Tough>("Tough")
.def(constructor<>())
.property("i", &Tough::get_i, &Tough::set_i)
];
luaL_dofile(L, "test.lua");
object tough1 = globals(L)["tough1"];
Tough* ptough = object_cast<Tough*>(tough1);
printf("i=%d\n", ptough->get_i());
}
test.lua contains simply:
tough1 = Tough()
tough1.i = 8
The Tough::set_i() method is never called and stough->i is left as -842150451 (uninitialized). Am I missing something obvious here?
Thanks,
Sean
---
Sean Hogan
Marport Canada
shogan@marport.com