Re: attempt to concatenate field 'value' (a function value)
Andreas Grob <[email protected]> Sat, 01 Nov 2014 19:13:36 +0100
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
Hello, Your Lua code should not be working at all, since no libraries are loaded and print isn't even defined. After adding luaL_openlibs(L); after creating the Lua state, it works fine for me: $ ./lua value : 4 Regards, Andreas Am 01.11.2014 um 18:45 schrieb [email protected]: > Can anybody explain this for me? It used to work on an older system with > lua5.1. > > i'm now using lua5.2, luabind version us 0.9.1 (on both systems) > > g++ -o lua lua.cpp -lluabind -llua5.2 -ldl -I /usr/include/lua5.2 > ./lua > lua runtime error > [string "function test(t)..."]:2: attempt to concatenate field 'value' (a > function value) > > extern "C" { > #include "lua.h" > #include "lualib.h" > #include "lauxlib.h" > } > > #include <luabind/luabind.hpp> > #include <iostream> > > struct Test > { > Test(int v) : value(v) {}; > ~Test() {}; > int value; > }; > > > int DebuggerFunc(lua_State* L) > { > luabind::object error_msg(luabind::from_stack(L, -1)); > std::cerr << error_msg << std::endl; > return 0; > } > > int main() { > lua_State *L = luaL_newstate(); > luabind::open(L); > > luabind::module(L) > [ > luabind::class_<Test>("Test") > .def(luabind::constructor<int>()) > .def_readonly("value",&Test::value) > ]; > > luaL_dostring( > L, > "function test(t)\n" > " print(\"value : \" .. t.value)\n" > "end\n" > ); > > Test t(4); > > try { > luabind::call_function<int>(L, "test", &t); > } > catch (const luabind::error &er) > { > std::cerr << er.what() << std::endl; > lua_State* Ler=er.state(); > DebuggerFunc(Ler); > } > catch (...) > { > std::cerr << "Unknown error!" << std::endl; > } > lua_close(L); > } > > > ------------------------------------------------------------------------------ > _______________________________________________ > luabind-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/luabind-user ------------------------------------------------------------------------------