luabind-user Mailing List for luabind (Page 4)
Brought to you by:
arvidn,
daniel_wallin
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
(54) |
May
(66) |
Jun
(56) |
Jul
(114) |
Aug
(84) |
Sep
(20) |
Oct
(30) |
Nov
(16) |
Dec
(38) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(36) |
Feb
(27) |
Mar
(32) |
Apr
(83) |
May
(66) |
Jun
(64) |
Jul
(63) |
Aug
(45) |
Sep
(14) |
Oct
(24) |
Nov
(19) |
Dec
(17) |
2005 |
Jan
(28) |
Feb
(20) |
Mar
(30) |
Apr
(19) |
May
(14) |
Jun
(18) |
Jul
(18) |
Aug
(6) |
Sep
(34) |
Oct
(46) |
Nov
(26) |
Dec
(44) |
2006 |
Jan
(41) |
Feb
(25) |
Mar
(42) |
Apr
(23) |
May
(21) |
Jun
(34) |
Jul
(44) |
Aug
(25) |
Sep
(29) |
Oct
(36) |
Nov
(7) |
Dec
(1) |
2007 |
Jan
(46) |
Feb
(22) |
Mar
(6) |
Apr
(10) |
May
(19) |
Jun
(20) |
Jul
|
Aug
(11) |
Sep
(33) |
Oct
(18) |
Nov
(13) |
Dec
(10) |
2008 |
Jan
(7) |
Feb
(6) |
Mar
(9) |
Apr
(5) |
May
(14) |
Jun
(29) |
Jul
(15) |
Aug
(10) |
Sep
(75) |
Oct
(43) |
Nov
(38) |
Dec
(40) |
2009 |
Jan
(62) |
Feb
(61) |
Mar
(74) |
Apr
(22) |
May
(31) |
Jun
(32) |
Jul
(32) |
Aug
(36) |
Sep
(7) |
Oct
(20) |
Nov
(51) |
Dec
(65) |
2010 |
Jan
(38) |
Feb
(48) |
Mar
(57) |
Apr
(21) |
May
(23) |
Jun
(41) |
Jul
(58) |
Aug
(17) |
Sep
(39) |
Oct
(15) |
Nov
(3) |
Dec
(13) |
2011 |
Jan
(35) |
Feb
(40) |
Mar
(17) |
Apr
(34) |
May
(39) |
Jun
(34) |
Jul
(19) |
Aug
(23) |
Sep
|
Oct
(20) |
Nov
(7) |
Dec
(12) |
2012 |
Jan
(13) |
Feb
(27) |
Mar
(15) |
Apr
(32) |
May
(9) |
Jun
(5) |
Jul
(4) |
Aug
|
Sep
(26) |
Oct
(4) |
Nov
(18) |
Dec
(4) |
2013 |
Jan
(15) |
Feb
(4) |
Mar
|
Apr
(20) |
May
(6) |
Jun
(10) |
Jul
(17) |
Aug
(6) |
Sep
(19) |
Oct
(3) |
Nov
(1) |
Dec
|
2014 |
Jan
(1) |
Feb
(6) |
Mar
|
Apr
|
May
(4) |
Jun
|
Jul
|
Aug
(3) |
Sep
(6) |
Oct
|
Nov
(6) |
Dec
|
2015 |
Jan
|
Feb
|
Mar
(3) |
Apr
(1) |
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(2) |
Dec
(10) |
2016 |
Jan
(2) |
Feb
(1) |
Mar
|
Apr
(1) |
May
(1) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
From: Glen F. <hol...@gm...> - 2013-08-28 11:09:37
|
Hello there, I'm using luabind and trying to get the Lua subclass name from an instance of the base class in C++. I want to use get_class_info(), but it expects an "argument" rather than an "object". Perhaps there is a better way to do this, besides trying to figure out how to convert a luabind::object into a luabind::adl::argument… Here is some example code that should illustrate the problem: class BaseClass { public: virtual ~BaseClass() {} std::string getClassName(lua_State* L); // ... more stuff... }; class BaseClass_wrapper : public BaseClass, public luabind::wrap_base { // ... some stuff... }; std::string BaseClass::getClassName(lua_State* L) { BaseClass_wrapper* p = dynamic_cast<BaseClass_wrapper*>(this); std::string className("UNKNOWN"); if (p != 0) { luabind::object myObject(L, p); luabind::class_info info = luabind::get_class_info(myObject); // no good! // no viable conversion from 'luabind::object' to 'const luabind::adl::argument' className = info.name; } return className; } Thanks for any suggestions, Glen. |
From: Christian <neu...@ya...> - 2013-07-28 20:07:25
|
On Sunday 28 July 2013, at 20:33:12, Glen Fraser <hol...@gm...> wrote: > Okay, thanks. I wasn't 100% sure where you meant I should put this code -- > i.e. where you call your bindLuaPart(). In the wrapper object's > constructor? No, that would theoretically be ideal, but unfortunately, at this point the normal (weak) reference (wrapped_self_t) is not initialized, so this does not work. > What I tried is this: when I add a new object (wherever it comes from) to my > C++ container, I run a method based on your code below -- if the object > being added to my C++ container is based on the Lua wrapper class (tested > using dynamic_cast), then I get its luabind wrapped_self_t and set its > "strong ref" as in your code. That's approximately the way I use it (in my case, the method is called from Lua, because at this point I know which class is wrap_base derived. But this might be different in your case). > This seems to work, thanks! I hope this "fix" (hack?) remains more or less > valid for future updates to luabind (if there ever are any ;-). > > Can you explain what this is doing? I guess it just creates a strong > reference to the Lua object, so it doesn't get garbage collected? Yes. This means that you need to delete/destroy the object from C++ to avoid memory leaks, the object references itself in a way so that the Lua GC does not see the cycle (intentionally). > Do I need to do anything specific if the C++ object gets deleted (e.g. in its > destructor), to release this strong reference to the Lua-side object? > Should I create a matching function, that calls reset() on its > m_strong_ref? No, that is not necessary. The strong reference is stored in the wrap_base class (as a Lua registry reference using a RAII wrapper around luaL_ref/unref), which means that is destroyed (which has the same effect as calling reset() on it) in the destructor automatically. > Thanks, > Glen. You're welcome, Christian PS: Sorry that my last answer was so garbled ;) > On Jul 23, 2013, at 12:20 PM, Christian <neu...@ya...> wrote: > > On Tuesday 23 July 2013, at 12:00:29, Glen Fraser <hol...@gm...> wrote: > >>> The struct name "only_accepts_nonconst_pointers" is meant as an error > >>> message: adopt only works with non-const pointers (meaning that the > >>> adopted type must be both a pointer and a non-const one). > >> > >> Thanks, Christian -- I saw that, but I don't know how to fix it. > >> Presumably this is related to the fact that the object I'm trying to > >> "adopt" is held in a smart pointer (boost::shared_ptr). But I haven't > >> declared the smart_ptr as const anywhere… > >> > >> I declare my class binding like this: > >> class_<Actor, Actor_wrapper, boost::shared_ptr<Actor> >("Actor") > >> .def(constructor<const string &>()) > >> .def("draw", &Actor::draw, &Actor_wrapper::default_draw) > >> ]; > >> > >> And the function I'm trying to call from C++ is like this: > > Sorry, I hit accidentaly sent my message before it was finished, here is > > the function: > > > > void bindLuaPart() > > { > > > > luabind::wrapped_self_t& wrapper = > > > > luabind::detail::wrap_access::ref(*this); > > > > if (wrapper.m_strong_ref.is_valid()) { > > > > LOG_W("Double call to wrap_Component::bindLuaPart"); > > return; > > > > } > > wrapper.get(wrapper.state()); > > wrapper.m_strong_ref.set(wrapper.state()); > > > > } > > > > This is highly dependent on implementation details though, but it works at > > least with the original luabind. > > > > -------------------------------------------------------------------------- > > ---- See everything from the browser to the database with AppDynamics > > Get end-to-end visibility with application monitoring from AppDynamics > > Isolate bottlenecks and diagnose root cause in seconds. > > Start your free trial of AppDynamics Pro today! > > http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktr > > k > > _______________________________________________ > > luabind-user mailing list > > lua...@li... > > https://lists.sourceforge.net/lists/listinfo/luabind-user > > ---------------------------------------------------------------------------- > -- See everything from the browser to the database with AppDynamics > Get end-to-end visibility with application monitoring from AppDynamics > Isolate bottlenecks and diagnose root cause in seconds. > Start your free trial of AppDynamics Pro today! > http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk > _______________________________________________ > luabind-user mailing list > lua...@li... > https://lists.sourceforge.net/lists/listinfo/luabind-user |
From: Glen F. <hol...@gm...> - 2013-07-28 18:33:25
|
Okay, thanks. I wasn't 100% sure where you meant I should put this code -- i.e. where you call your bindLuaPart(). In the wrapper object's constructor? What I tried is this: when I add a new object (wherever it comes from) to my C++ container, I run a method based on your code below -- if the object being added to my C++ container is based on the Lua wrapper class (tested using dynamic_cast), then I get its luabind wrapped_self_t and set its "strong ref" as in your code. This seems to work, thanks! I hope this "fix" (hack?) remains more or less valid for future updates to luabind (if there ever are any ;-). Can you explain what this is doing? I guess it just creates a strong reference to the Lua object, so it doesn't get garbage collected? Do I need to do anything specific if the C++ object gets deleted (e.g. in its destructor), to release this strong reference to the Lua-side object? Should I create a matching function, that calls reset() on its m_strong_ref? Thanks, Glen. On Jul 23, 2013, at 12:20 PM, Christian <neu...@ya...> wrote: > On Tuesday 23 July 2013, at 12:00:29, Glen Fraser <hol...@gm...> wrote: >>> The struct name "only_accepts_nonconst_pointers" is meant as an error >>> message: adopt only works with non-const pointers (meaning that the >>> adopted type must be both a pointer and a non-const one). >> >> Thanks, Christian -- I saw that, but I don't know how to fix it. Presumably >> this is related to the fact that the object I'm trying to "adopt" is held >> in a smart pointer (boost::shared_ptr). But I haven't declared the >> smart_ptr as const anywhere… >> >> I declare my class binding like this: >> >> class_<Actor, Actor_wrapper, boost::shared_ptr<Actor> >("Actor") >> .def(constructor<const string &>()) >> .def("draw", &Actor::draw, &Actor_wrapper::default_draw) >> ]; >> >> And the function I'm trying to call from C++ is like this: > Sorry, I hit accidentaly sent my message before it was finished, here is the > function: > > void bindLuaPart() > { > luabind::wrapped_self_t& wrapper = > luabind::detail::wrap_access::ref(*this); > if (wrapper.m_strong_ref.is_valid()) { > LOG_W("Double call to wrap_Component::bindLuaPart"); > return; > } > wrapper.get(wrapper.state()); > wrapper.m_strong_ref.set(wrapper.state()); > } > > This is highly dependent on implementation details though, but it works at > least with the original luabind. > > ------------------------------------------------------------------------------ > See everything from the browser to the database with AppDynamics > Get end-to-end visibility with application monitoring from AppDynamics > Isolate bottlenecks and diagnose root cause in seconds. > Start your free trial of AppDynamics Pro today! > http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk > _______________________________________________ > luabind-user mailing list > lua...@li... > https://lists.sourceforge.net/lists/listinfo/luabind-user |
From: Szulak <sz...@ou...> - 2013-07-25 11:10:16
|
>> Daniel Walter <daniel.walter <at> helmundwalter.de> writes: Hey there, Did you solve your problem? I am having the same problem, used additional getter to get dereferenced value, but as you said, there must be a better way. Regards, Szulak |
From: Christian <neu...@ya...> - 2013-07-23 10:20:29
|
On Tuesday 23 July 2013, at 12:00:29, Glen Fraser <hol...@gm...> wrote: > > The struct name "only_accepts_nonconst_pointers" is meant as an error > > message: adopt only works with non-const pointers (meaning that the > > adopted type must be both a pointer and a non-const one). > > Thanks, Christian -- I saw that, but I don't know how to fix it. Presumably > this is related to the fact that the object I'm trying to "adopt" is held > in a smart pointer (boost::shared_ptr). But I haven't declared the > smart_ptr as const anywhere… > > I declare my class binding like this: > > class_<Actor, Actor_wrapper, boost::shared_ptr<Actor> >("Actor") > .def(constructor<const string &>()) > .def("draw", &Actor::draw, &Actor_wrapper::default_draw) > ]; > > And the function I'm trying to call from C++ is like this: Sorry, I hit accidentaly sent my message before it was finished, here is the function: void bindLuaPart() { luabind::wrapped_self_t& wrapper = luabind::detail::wrap_access::ref(*this); if (wrapper.m_strong_ref.is_valid()) { LOG_W("Double call to wrap_Component::bindLuaPart"); return; } wrapper.get(wrapper.state()); wrapper.m_strong_ref.set(wrapper.state()); } This is highly dependent on implementation details though, but it works at least with the original luabind. |
From: Christian <neu...@ya...> - 2013-07-23 10:17:49
|
On Tuesday 23 July 2013, at 12:00:29, Glen Fraser <hol...@gm...> wrote: > > The struct name "only_accepts_nonconst_pointers" is meant as an error > > message: adopt only works with non-const pointers (meaning that the > > adopted type must be both a pointer and a non-const one). > > Thanks, Christian -- I saw that, but I don't know how to fix it. Presumably > this is related to the fact that the object I'm trying to "adopt" is held > in a smart pointer (boost::shared_ptr). But I haven't declared the > smart_ptr as const anywhere… > Adopt checks exactly for const plain pointers and will issue said error message otherwise. And if you think about it, it makes sense: Plain pointers do not have any particular ownership semantics, so you must tell luabind about it using policies such as adopt. Smart pointers on the other hand, do already have ownership semantics: shared_ptr e.g. has shared ownership. > I declare my class binding like this: > > class_<Actor, Actor_wrapper, boost::shared_ptr<Actor> >("Actor") > .def(constructor<const string &>()) > .def("draw", &Actor::draw, &Actor_wrapper::default_draw) > ]; > > And the function I'm trying to call from C++ is like this: > > boost::shared_ptr<Actor> fromLua = > luabind::call_function<boost::shared_ptr<Actor> >(mLua, > "makeActorSubclass", "bobby")[luabind::adopt(luabind::result)]; > > The function makeActorSubclass is a simple Lua script that creates an > instance of a class derived from Actor in Lua (this creation code works > fine without the adopt policy stuff...except it doesn't transfer ownership > to C++, so the object gets garbage-collected later on!). > > function makeActorSubclass(name) > return ActorSubclass(name) > end > So the lua part of your object get's collected? I think I had a similar problem, which I solved using a hack in my wrapper class, by doing the (here) crucial part of adopt manually using a member function like this: > Any ideas on how to get rid of my const problem? I do see the following > comment in the luabind docs: > > get_const_holder() has been removed. Automatic conversions between > smart_ptr<X>and smart_ptr<X const> no longer work. > > But I'm not sure what that means, and whether it applies in my case (I don't > have any smart_ptr<X const> usages that I know of). > > Glen. > > On Jul 23, 2013, at 10:55 AM, Christian <neu...@ya...> wrote: > > On Tuesday 23 July 2013, at 10:11:13, Glen Fraser <hol...@gm...> wrote: > >> Now, when I try to use the adopt policy, I get errors like Sympaval had > >> (in > >> this thread: > >> http://lua.2524044.n2.nabble.com/Remove-an-object-from-the-lua-state-tp75 > >> 83 > >> 423p7583425.html). He didn't manage to get adopt working when binding, > >> but > >> rather chose to instead use it with using call_function. > >> > >> Same as him -- I get errors like this, when trying to use adopt(_2) in a > >> def(): > >> > >> .../boost/include/boost/preprocessor/iteration/detail/local.hpp:37:9: No > >> member named 'consumed_args' in 'luabind::detail::adopt_policy<2, > >> void>::only_accepts_nonconst_pointers' > >> .../boost/include/boost/preprocessor/iteration/detail/local.hpp:37:9: No > >> member named 'converter_postcall' in 'luabind::detail::adopt_policy<2, > >> void>::only_accepts_nonconst_pointers' > >> .../addons/ofxLua/src/luabind/luabind/detail/call.hpp:295:48: No member > >> named 'apply' in 'luabind::detail::adopt_policy<2, > >> void>::only_accepts_nonconst_pointers' > >> > >> And when I try to use it with call_function: > >> > >> .../addons/ofxLua/src/luabind/luabind/detail/call_function.hpp:200:20: No > >> member named 'match' in 'luabind::detail::adopt_policy<0, > >> void>::only_accepts_nonconst_pointers' > > > > The struct name "only_accepts_nonconst_pointers" is meant as an error > > message: adopt only works with non-const pointers (meaning that the > > adopted type must be both a pointer and a non-const one). > > > > Hope I could help, > > Christian |
From: Glen F. <hol...@gm...> - 2013-07-23 10:00:41
|
> The struct name "only_accepts_nonconst_pointers" is meant as an error message: > adopt only works with non-const pointers (meaning that the adopted type must > be both a pointer and a non-const one). Thanks, Christian -- I saw that, but I don't know how to fix it. Presumably this is related to the fact that the object I'm trying to "adopt" is held in a smart pointer (boost::shared_ptr). But I haven't declared the smart_ptr as const anywhere… I declare my class binding like this: class_<Actor, Actor_wrapper, boost::shared_ptr<Actor> >("Actor") .def(constructor<const string &>()) .def("draw", &Actor::draw, &Actor_wrapper::default_draw) ]; And the function I'm trying to call from C++ is like this: boost::shared_ptr<Actor> fromLua = luabind::call_function<boost::shared_ptr<Actor> >(mLua, "makeActorSubclass", "bobby")[luabind::adopt(luabind::result)]; The function makeActorSubclass is a simple Lua script that creates an instance of a class derived from Actor in Lua (this creation code works fine without the adopt policy stuff...except it doesn't transfer ownership to C++, so the object gets garbage-collected later on!). function makeActorSubclass(name) return ActorSubclass(name) end Any ideas on how to get rid of my const problem? I do see the following comment in the luabind docs: get_const_holder() has been removed. Automatic conversions between smart_ptr<X>and smart_ptr<X const> no longer work. But I'm not sure what that means, and whether it applies in my case (I don't have any smart_ptr<X const> usages that I know of). Glen. On Jul 23, 2013, at 10:55 AM, Christian <neu...@ya...> wrote: > On Tuesday 23 July 2013, at 10:11:13, Glen Fraser <hol...@gm...> wrote: >> Now, when I try to use the adopt policy, I get errors like Sympaval had (in >> this thread: >> http://lua.2524044.n2.nabble.com/Remove-an-object-from-the-lua-state-tp7583 >> 423p7583425.html). He didn't manage to get adopt working when binding, but >> rather chose to instead use it with using call_function. >> >> Same as him -- I get errors like this, when trying to use adopt(_2) in a >> def(): >> >> .../boost/include/boost/preprocessor/iteration/detail/local.hpp:37:9: No >> member named 'consumed_args' in 'luabind::detail::adopt_policy<2, >> void>::only_accepts_nonconst_pointers' >> .../boost/include/boost/preprocessor/iteration/detail/local.hpp:37:9: No >> member named 'converter_postcall' in 'luabind::detail::adopt_policy<2, >> void>::only_accepts_nonconst_pointers' >> .../addons/ofxLua/src/luabind/luabind/detail/call.hpp:295:48: No member >> named 'apply' in 'luabind::detail::adopt_policy<2, >> void>::only_accepts_nonconst_pointers' >> >> And when I try to use it with call_function: >> >> .../addons/ofxLua/src/luabind/luabind/detail/call_function.hpp:200:20: No >> member named 'match' in 'luabind::detail::adopt_policy<0, >> void>::only_accepts_nonconst_pointers' >> > > The struct name "only_accepts_nonconst_pointers" is meant as an error message: > adopt only works with non-const pointers (meaning that the adopted type must > be both a pointer and a non-const one). > > Hope I could help, > Christian > |
From: Christian <neu...@ya...> - 2013-07-23 08:55:40
|
On Tuesday 23 July 2013, at 10:11:13, Glen Fraser <hol...@gm...> wrote: > How embarrassing, sorry for the noise, I was barking up the wrong tree. > This turned out to be (of course) a stupid change where I was including > adopt_policy.hpp before luabind.hpp -- doh! > > Sorry. > > Now, when I try to use the adopt policy, I get errors like Sympaval had (in > this thread: > http://lua.2524044.n2.nabble.com/Remove-an-object-from-the-lua-state-tp7583 > 423p7583425.html). He didn't manage to get adopt working when binding, but > rather chose to instead use it with using call_function. > > Same as him -- I get errors like this, when trying to use adopt(_2) in a > def(): > > .../boost/include/boost/preprocessor/iteration/detail/local.hpp:37:9: No > member named 'consumed_args' in 'luabind::detail::adopt_policy<2, > void>::only_accepts_nonconst_pointers' > .../boost/include/boost/preprocessor/iteration/detail/local.hpp:37:9: No > member named 'converter_postcall' in 'luabind::detail::adopt_policy<2, > void>::only_accepts_nonconst_pointers' > .../addons/ofxLua/src/luabind/luabind/detail/call.hpp:295:48: No member > named 'apply' in 'luabind::detail::adopt_policy<2, > void>::only_accepts_nonconst_pointers' > > And when I try to use it with call_function: > > .../addons/ofxLua/src/luabind/luabind/detail/call_function.hpp:200:20: No > member named 'match' in 'luabind::detail::adopt_policy<0, > void>::only_accepts_nonconst_pointers' > The struct name "only_accepts_nonconst_pointers" is meant as an error message: adopt only works with non-const pointers (meaning that the adopted type must be both a pointer and a non-const one). Hope I could help, Christian > Is this because the latest luabind requires C++0x/C++11 compilation and > standard libs? Currently, I can't do that because I'm using it inside > OpenFrameworks v0074, which still uses std::tr1 things -- but I guess I can > try to change that locally (if that's the solution). Or should I go back > to an older version of luabind? > > Thanks again (though I feel like I'm talking to myself ;-), > Glen. |
From: Glen F. <hol...@gm...> - 2013-07-23 08:11:25
|
How embarrassing, sorry for the noise, I was barking up the wrong tree. This turned out to be (of course) a stupid change where I was including adopt_policy.hpp before luabind.hpp -- doh! Sorry. Now, when I try to use the adopt policy, I get errors like Sympaval had (in this thread: http://lua.2524044.n2.nabble.com/Remove-an-object-from-the-lua-state-tp7583423p7583425.html). He didn't manage to get adopt working when binding, but rather chose to instead use it with using call_function. Same as him -- I get errors like this, when trying to use adopt(_2) in a def(): .../boost/include/boost/preprocessor/iteration/detail/local.hpp:37:9: No member named 'consumed_args' in 'luabind::detail::adopt_policy<2, void>::only_accepts_nonconst_pointers' .../boost/include/boost/preprocessor/iteration/detail/local.hpp:37:9: No member named 'converter_postcall' in 'luabind::detail::adopt_policy<2, void>::only_accepts_nonconst_pointers' .../addons/ofxLua/src/luabind/luabind/detail/call.hpp:295:48: No member named 'apply' in 'luabind::detail::adopt_policy<2, void>::only_accepts_nonconst_pointers' And when I try to use it with call_function: .../addons/ofxLua/src/luabind/luabind/detail/call_function.hpp:200:20: No member named 'match' in 'luabind::detail::adopt_policy<0, void>::only_accepts_nonconst_pointers' Is this because the latest luabind requires C++0x/C++11 compilation and standard libs? Currently, I can't do that because I'm using it inside OpenFrameworks v0074, which still uses std::tr1 things -- but I guess I can try to change that locally (if that's the solution). Or should I go back to an older version of luabind? Thanks again (though I feel like I'm talking to myself ;-), Glen. On Jul 22, 2013, at 4:49 PM, Glen Fraser <hol...@gm...> wrote: > It turns out that the patch does not fix my problem. After more web-searching, I see I should be using the adopt policy (http://www.rasterbar.com/products/luabind/docs.html#adopt), to pass Lua object ownership to C++. However, whenever I try to include luabind/adopt_policy.hpp, I get tons of errors (on Xcode 4.6.3 with clang or gcc). > > With Clang LLVM: > .../addons/ofxLua/src/luabind/luabind/handle.hpp:136:5: Expected member name or ';' after declaration specifiers > .../addons/ofxLua/src/luabind/luabind/detail/has_get_pointer.hpp:82:3: Declaration does not declare anything > … > With LLVM GCC: > .../addons/ofxLua/src/luabind/luabind/detail/policy.hpp:534: Macro "check" passed 2 arguments, but takes just 1 > .../addons/ofxLua/src/luabind/luabind/object.hpp:1249: Macro "check" passed 2 arguments, but takes just 1 > … > (and many more) > > As you can see, I'm using a version of luabind in the ofxLua project, but I also tried taking a copy of luabind directly from Git (https://github.com/luabind/luabind), but had a similar pile of compile errors. Anyone else run into something similar? More important, can anyone help me with this? > > Thanks, > Glen. > > On Jul 22, 2013, at 2:02 PM, Glen F <hol...@gm...> wrote: > >> Hi there, I know this is an old thread... Was there no follow-up on this? >> I've run into the same problem with weak references getting garbage >> collected when deriving from C++ classes. >> >> Max's patch hasn't been integrated into luabind, as far as I can tell. I'm >> happy to fork my own luabind and patch it, but wondering why this was not >> put into the main repo -- was it not judged a correct fix? >> >> Thanks, >> Glen. |
From: Christian <cn...@gm...> - 2013-07-22 20:05:10
|
This is not a gcc bug, but one of the few incompatibilities between C++03 and C++11: Destructors are noexcept by default, meaning that std::terminate() is called when an exception is thrown from them. As the documentation of call_function() points out (it's the same with object's operator()): > The return value isn't actually Ret (the template parameter), but a proxy > object that will do the function call. The problem is that when you neither specify policies with operator[] nor use the result (i.e. invoke the proxy's operator Ret()), the proxy's destructor does the call. Workarounds would be to do one of the two things just mentioned, but you could also try my fork[1] where this (together with many other problems) is fixed with commits [2] and [3] by adding BOOST_NOEXCEPT_IF(false) to the destructors. [1]: http://github.com/Oberon00/luabind [2]: http://github.com/Oberon00/luabind/commit/81bdcb72aa6ef7b321e59416b77be65c3944d6a9 [3]: http://github.com/Oberon00/luabind/commit/e10e60244213ad3908aa7f10fe634b7230e42af3 > -----Original Message----- > From: Benjamin Kloster [mailto:ben...@gm...] > Sent: Monday, July 22, 2013 9:33 AM > To: lua...@li... > Subject: Re: [luabind] Cannot catch luabind:error with gcc 4.8 and C++11 > > > > Kai Bernhard <kai.bernhard <at> imail.de> writes: > > > > > Hi Benjamin, > > > > I ran into the same problem. It looks like it is enough to compile the > > executable with -std=c++98 to make it work, lua and luabind libraries > > can be compiled with -std=c++11. After I had seen this, I looked at the > > assembler code generated from luabind_error.cpp in C++11 vs C++98 mode. > > There are a few blocks of code in C++98 mode which seem to be > > suspiciously missing in C++11 mode, each of them including the lines > > call __Unwind_Resume > > and > > .section .gcc_except_table,"w" > > > > So this looks indeed like a problem with gcc's code generation (I tested > > with 4.8.1). Did you find any other information regarding this or > > contact the gcc devs? I did not see any ticket in their bug tracker that > > rang a bell. > > > > Regards, > > Kai > > > Hi Kai, > I haven't contacted the gcc developers yet as I wanted to see whether > someone else has this problem and maybe pinpoint the error in either > luabind > or gcc. You seem to have investigated this much further than I did. Would > you be willing to file a bug report with gcc? > > Best Regards, > Ben > > > > --------------------------------------------------------------------------- > --- > See everything from the browser to the database with AppDynamics > Get end-to-end visibility with application monitoring from AppDynamics > Isolate bottlenecks and diagnose root cause in seconds. > Start your free trial of AppDynamics Pro today! > http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk > _______________________________________________ > luabind-user mailing list > lua...@li... > https://lists.sourceforge.net/lists/listinfo/luabind-user |
From: Glen F. <hol...@gm...> - 2013-07-22 15:43:24
|
Hi there, I've got subclassing working pretty well between Lua and C++. So I have a C++ base class, and can create subclasses in Lua and instantiate them there, add them to my "world", have them traversed and their methods called from C++, etc. What I don't understand how to do is how to create instances of Lua classes from C++. Is this possible? I have the name of the classes, because I call my own "register" method from Lua, so my app knows the names of available subclasses. But how can I create a new instance of one of them from C++? Lua: class 'Derived' (app.Base) function Derived:__init(str) app.Base.__init(self, str .. " (Derived)") end app.registerSubClass('Derived') Later on, in C++, I'd like to do the Lua equivalent of: x = Derived("hello") Then I can do: world = app.getWorld() world:addObject(x) All I can think of is something like: shared_ptr<Base> x = luabind::call_function<shared_ptr<Base> >(luaState, "createObject", "Derived", "hello"); world->addObject(x); // and so on... Any ideas? I can't just call new on my luabind::wrap_base - derived object, then register that with Lua/luabind somehow (and tell it what Lua subclass it should be using)? (that would be nice ;-) Thanks, Glen. |
From: Glen F. <hol...@gm...> - 2013-07-22 14:50:09
|
It turns out that the patch does not fix my problem. After more web-searching, I see I should be using the adopt policy (http://www.rasterbar.com/products/luabind/docs.html#adopt), to pass Lua object ownership to C++. However, whenever I try to include luabind/adopt_policy.hpp, I get tons of errors (on Xcode 4.6.3 with clang or gcc). With Clang LLVM: .../addons/ofxLua/src/luabind/luabind/handle.hpp:136:5: Expected member name or ';' after declaration specifiers .../addons/ofxLua/src/luabind/luabind/detail/has_get_pointer.hpp:82:3: Declaration does not declare anything .../addons/ofxLua/src/luabind/luabind/detail/has_get_pointer.hpp:83:3: Declaration does not declare anything .../addons/ofxLua/src/luabind/luabind/detail/has_get_pointer.hpp:91:71: Expected unqualified-id .../addons/ofxLua/src/luabind/luabind/detail/policy.hpp:534:45: Too many arguments provided to function-like macro invocation .../addons/ofxLua/src/luabind/luabind/nil.hpp:36:40: Expected unqualified-id .../addons/ofxLua/src/luabind/luabind/object.hpp:109:5: Declaration does not declare anything .../addons/ofxLua/src/luabind/luabind/object.hpp:110:5: Declaration does not declare anything .../addons/ofxLua/src/luabind/luabind/object.hpp:116:57: Expected unqualified-id .../addons/ofxLua/src/luabind/luabind/object.hpp:884:5: Expected member name or ';' after declaration specifiers .../addons/ofxLua/src/luabind/luabind/object.hpp:905:5: Expected member name or ';' after declaration specifiers .../addons/ofxLua/src/luabind/luabind/object.hpp:1249:37: Too many arguments provided to function-like macro invocation .../addons/ofxLua/src/luabind/luabind/object.hpp:1249:17: Function definition does not declare parameters .../addons/ofxLua/src/luabind/luabind/object.hpp:1251:53: Too many arguments provided to function-like macro invocation .../addons/ofxLua/src/ofxLua.h:590:20: No member named 'nil' in namespace 'luabind' .../addons/ofxLua/src/luabind/luabind/detail/has_get_pointer.hpp:94:33: Non-type template argument of type 'bool' is not an integral constant expression .../addons/ofxLua/src/luabind/luabind/detail/policy.hpp:195:9: No matching function for call to 'make_pointee_instance' .../addons/ofxLua/src/luabind/luabind/detail/has_get_pointer.hpp:94:33: Non-type template argument of type 'bool' is not an integral constant expression .../addons/ofxLua/src/luabind/luabind/detail/policy.hpp:195:9: No matching function for call to 'make_pointee_instance' .../addons/ofxLua/src/luabind/luabind/detail/policy.hpp:534:36: No member named 'check' in 'luabind::value_wrapper_traits<luabind::adl::argument>' With LLVM GCC: .../addons/ofxLua/src/luabind/luabind/detail/policy.hpp:534: Macro "check" passed 2 arguments, but takes just 1 .../addons/ofxLua/src/luabind/luabind/object.hpp:1249: Macro "check" passed 2 arguments, but takes just 1 .../addons/ofxLua/src/luabind/luabind/object.hpp:1251: Macro "check" passed 2 arguments, but takes just 1 .../addons/ofxLua/src/luabind/luabind/handle.hpp:136: Expected unqualified-id before '{' token .../addons/ofxLua/src/luabind/luabind/detail/has_get_pointer.hpp:82: Expected unqualified-id before ';' token .../addons/ofxLua/src/luabind/luabind/detail/has_get_pointer.hpp:83: Declaration does not declare anything .../addons/ofxLua/src/luabind/luabind/detail/has_get_pointer.hpp:90: Expected unqualified-id before ')' token .../addons/ofxLua/src/luabind/luabind/detail/has_get_pointer.hpp:94: 'luabind::detail::has_get_pointer_::impl<T>::value' is not a valid template argument for type 'bool' because it is a non-constant expression .../addons/ofxLua/src/luabind/luabind/nil.hpp:36: Expected unqualified-id before '__null' .../addons/ofxLua/src/luabind/luabind/object.hpp:109: Expected unqualified-id before ';' token .../addons/ofxLua/src/luabind/luabind/object.hpp:110: Declaration does not declare anything .../addons/ofxLua/src/luabind/luabind/object.hpp:115: Expected unqualified-id before ')' token .../addons/ofxLua/src/luabind/luabind/object.hpp:119: 'luabind::adl::is_object_interface_aux::impl<T>::value' is not a valid template argument for type 'bool' because it is a non-constant expression (and many more) As you can see, I'm using a version of luabind in the ofxLua project, but I also tried taking a copy of luabind directly from Git (https://github.com/luabind/luabind), but had a similar pile of compile errors. Anyone else run into something similar? More important, can anyone help me with this? Thanks, Glen. On Jul 22, 2013, at 2:02 PM, Glen F <hol...@gm...> wrote: > Hi there, I know this is an old thread... Was there no follow-up on this? > I've run into the same problem with weak references getting garbage > collected when deriving from C++ classes. > > Max's patch hasn't been integrated into luabind, as far as I can tell. I'm > happy to fork my own luabind and patch it, but wondering why this was not > put into the main repo -- was it not judged a correct fix? > > Thanks, > Glen. > > > > > -- > View this message in context: http://lua.2524044.n2.nabble.com/weak-ref-issue-patch-tp7581558p7650973.html > Sent from the Lua C++ Bind mailing list archive at Nabble.com. > > ------------------------------------------------------------------------------ > See everything from the browser to the database with AppDynamics > Get end-to-end visibility with application monitoring from AppDynamics > Isolate bottlenecks and diagnose root cause in seconds. > Start your free trial of AppDynamics Pro today! > http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk > _______________________________________________ > luabind-user mailing list > lua...@li... > https://lists.sourceforge.net/lists/listinfo/luabind-user |
From: Glen F <hol...@gm...> - 2013-07-22 12:02:20
|
Hi there, I know this is an old thread... Was there no follow-up on this? I've run into the same problem with weak references getting garbage collected when deriving from C++ classes. Max's patch hasn't been integrated into luabind, as far as I can tell. I'm happy to fork my own luabind and patch it, but wondering why this was not put into the main repo -- was it not judged a correct fix? Thanks, Glen. -- View this message in context: http://lua.2524044.n2.nabble.com/weak-ref-issue-patch-tp7581558p7650973.html Sent from the Lua C++ Bind mailing list archive at Nabble.com. |
From: Benjamin K. <ben...@gm...> - 2013-07-22 07:33:40
|
Kai Bernhard <kai.bernhard <at> imail.de> writes: > > Hi Benjamin, > > I ran into the same problem. It looks like it is enough to compile the > executable with -std=c++98 to make it work, lua and luabind libraries > can be compiled with -std=c++11. After I had seen this, I looked at the > assembler code generated from luabind_error.cpp in C++11 vs C++98 mode. > There are a few blocks of code in C++98 mode which seem to be > suspiciously missing in C++11 mode, each of them including the lines > call __Unwind_Resume > and > .section .gcc_except_table,"w" > > So this looks indeed like a problem with gcc's code generation (I tested > with 4.8.1). Did you find any other information regarding this or > contact the gcc devs? I did not see any ticket in their bug tracker that > rang a bell. > > Regards, > Kai Hi Kai, I haven't contacted the gcc developers yet as I wanted to see whether someone else has this problem and maybe pinpoint the error in either luabind or gcc. You seem to have investigated this much further than I did. Would you be willing to file a bug report with gcc? Best Regards, Ben |
From: Kai B. <kai...@im...> - 2013-07-21 21:10:58
|
Hi Benjamin, I ran into the same problem. It looks like it is enough to compile the executable with -std=c++98 to make it work, lua and luabind libraries can be compiled with -std=c++11. After I had seen this, I looked at the assembler code generated from luabind_error.cpp in C++11 vs C++98 mode. There are a few blocks of code in C++98 mode which seem to be suspiciously missing in C++11 mode, each of them including the lines call __Unwind_Resume and .section .gcc_except_table,"w" So this looks indeed like a problem with gcc's code generation (I tested with 4.8.1). Did you find any other information regarding this or contact the gcc devs? I did not see any ticket in their bug tracker that rang a bell. Regards, Kai |
From: Glen F. <hol...@gm...> - 2013-07-08 13:04:57
|
On Jul 8, 2013, at 2:04 PM, "Christian" <cn...@gm...> wrote: >> The complicating factor (maybe) is that I'd like to use smart pointers in the containing >> STL vector, and I don't see how to use both luabind::wrap_base and a smart pointer at the >> same time, in the class_ binding. > > I think you identified the problem correctly. Have you read > http://www.rasterbar.com/products/luabind/docs.html#smart-pointers ? > You need to specify ofPtr as an template argument when registering your class and make sure > that a get_pointer() function is available in the same namespace as ofPtr (global is only > sufficient if ofPtr is itself global). Yes, I had indeed read it -- but where I went wrong was assuming ofPtr supported get_pointer(). It doesn't. It's not based on boost::shared_ptr but rather std::shared_ptr, which doesn't include a get_pointer() method. Changing my code to use boost::shared_ptr, it all works fine. Otherwise, I could add a get_pointer() function, as in your code. Thanks! Glen. > >> (in the below code, assume [...] ofPtr is just shared_ptr) > > boost::shared_ptr? Then just specify ofPtr as template argument, as said above, and you > should be done. > If not, you additionally need to supply an appropriate get_pointer() function. For > std::shared_ptr, you can use a header I made for this purpose (just include it): > http://github.com/Oberon00/luabind/blob/master/luabind/std_shared_ptr_converter.hpp > > I hope I could help, > Christian |
From: Christian <cn...@gm...> - 2013-07-08 12:05:10
|
On Monday, July 08, 2013 1:08 PM, Glen Fraser [mailto:hol...@gm...] wrote: > The complicating factor (maybe) is that I'd like to use smart pointers in the containing > STL vector, and I don't see how to use both luabind::wrap_base and a smart pointer at the > same time, in the class_ binding. I think you identified the problem correctly. Have you read http://www.rasterbar.com/products/luabind/docs.html#smart-pointers ? You need to specify ofPtr as an template argument when registering your class and make sure that a get_pointer() function is available in the same namespace as ofPtr (global is only sufficient if ofPtr is itself global). > (in the below code, assume [...] ofPtr is just shared_ptr) boost::shared_ptr? Then just specify ofPtr as template argument, as said above, and you should be done. If not, you additionally need to supply an appropriate get_pointer() function. For std::shared_ptr, you can use a header I made for this purpose (just include it): http://github.com/Oberon00/luabind/blob/master/luabind/std_shared_ptr_converter.hpp I hope I could help, Christian |
From: Glen F. <hol...@gm...> - 2013-07-08 11:08:02
|
Hi there, I've been following section 12.1 of the luabind documentation to make Lua classes deriving from a C++ class. I got it all working fine, but I still don't understand how to put Lua-created objects into a C++ container (STL vector, for example). I'd like to iterate over them (in C++) and, calling their overridden (or not) virtual methods. The complicating factor (maybe) is that I'd like to use smart pointers in the containing STL vector, and I don't see how to use both luabind::wrap_base and a smart pointer at the same time, in the class_ binding. (in the below code, assume ofLog() is like cout, and ofPtr is just shared_ptr) C++ code: class MyItem { public: MyItem(const string &s = "MYITEM DEFAULT") : mStr(s) { ofLog() << "MyItem::MyItem(" << mStr << ")"; } virtual void f(int a) { ofLog() << mStr << " -- MyItem::f(" << a << ")"; } protected: string mStr; }; struct MyItem_wrapper : MyItem, luabind::wrap_base { MyItem_wrapper(const string &s) : MyItem(s) {} virtual void f(int a) { call<void>("f", a); } static void default_f(MyItem* ptr, int a) { return ptr->MyItem::f(a); } }; class Holder { public: void addItem(ofPtr<MyItem> inItem) { mObjs.push_back(inItem); } void traverse() { vector<ofPtr<MyItem> >::iterator it; int num = 0; for (it = mObjs.begin(); it != mObjs.end(); it++, num++) { (*it)->f(num); } } protected: vector<ofPtr<MyItem> > mObjs; }; and to register the classes: module(lua, "objects") [ class_<Holder>("Holder") .def(constructor<>()) .def("addItem", &Holder::addItem) .def("traverse", &Holder::traverse), class_<MyItem, MyItem_wrapper>("MyItem") .def(constructor<const string &>()) .def("f", &MyItem::f, &MyItem_wrapper::default_f) ]; Then in Lua, create a derived class and try to add several instances of it to the container class: class 'Derived' (objects.MyItem) function Derived:__init(str) objects.MyItem.__init(self, str .. "(Derived)") self.newParam = 1234.5 end function Derived:f(a) objects.MyItem.f(self, a) print(a + 100, self.newParam) end hold = objects.Holder() x = Derived("hello") x:f(3) -- everything works, up to here hold:addItem(x) -- ka-blooey x = Derived("there") hold:addItem(x) hold:traverse() On the first addItem(), I get the following error: got an error: Runtime error: No matching overload found, candidates: void addItem(Holder&,custom [5ofPtrI6MyItemE]) Any tips on how to do what I'm trying to do? Do I have to make a new wrapper class that's a combination of luabind::wrap_base and shared_ptr? I can skip using smart pointers for the container, if someone can explain how I should manage object lifetime, when the "Holder" container may have a mixture of Lua-created and C++-created objects. Thanks, Glen. |
From: rod h. <reh...@gm...> - 2013-06-18 18:07:47
|
Can you try... void setA(int nVal) { A = &nVal; } int* getA(void) const { return A; } static void registrate(lua_State *pLuaState) { // export our class with LuaBind luabind::module(pLuaState) [ luabind::class_<Foo>("Foo") .property("A", &Foo::getVal, &Foo::setVal) ]; } public: int *A; LUA Script... a = Foo.A Foo.A = 10 On Tue, Jun 18, 2013 at 1:11 PM, Daniel Walter < dan...@he...> wrote: > I think this does not fit my needs. "FooManager" does not have any > public pointers that need to be accessed directly by lua. You are > accessing your pointers through "getComponent" function. > > Can you expose "m_iFooVector" with something like this: > ".def_readonly("iFooVector", &FooManager::m_iFooVector, > luabind::return_stl_iterator)" > > And then iterate and access it in your lua script? > > for foo in fooManager.iFooVector do > print(foo.AnyField) > end > > On 18.06.2013 19:01, rod haxton wrote: > > Take a look at this. I do this and it works with a boost::ref on class, > > see "FooManager". > > > > I know...I know...I hate when folks give you a lot of code to look at > > for an example. But, perhaps you can glean something from looking at the > > "FooManager" class, and see that I assign it as a global. > > > > //The registrate function takes a Class > > // name and lua_State, then calls its registrate method > > template <typename T> > > void registrate(lua_State *pLuaState) { > > T::registrate(pLuaState); > > } > > > > > > class FooManager > > { > > public: > > FooManager() {}; > > ~FooManager() {}; > > > > voidaddComponent(IFoo* pFoo) { m_iFooVector.push_back(pFoo); } > > IFoo*getComponent(int nIndex) { return m_iFooVector[nIndex]; } > > > > static void registrate(lua_State *pLuaState) > > { > > luabind::module(pLuaState) [ > > luabind::class_<FooManager>("FooManager") > > .def(luabind::constructor<>()) > > .def("getComponent", (IFoo*(FooManager::*) (int)) > &FooManager::getComponent) > > ]; > > } > > > > void doAwake(void) > > { > > for(std::vector<IFoo*>::iterator it = m_iFooVector.begin(); it != > > m_iFooVector.end(); it++) > > { > > IFoo *pIFoo = *it; > > pIFoo->Awake(); > > } > > } > > > > void doUpdate(void) > > { > > for(std::vector<IFoo*>::iterator it = m_iFooVector.begin(); it != > > m_iFooVector.end(); it++) > > { > > IFoo *pIFoo = *it; > > pIFoo->update(); > > } > > } > > > > private: > > std::vector<IFoo*> m_iFooVector; > > }; > > > > int main() > > { > > lua_State *myLuaState = luaL_newstate(); > > > > // Connect LuaBind to this lua state > > luabind::open(myLuaState); > > > > // open the lua libraries > > luaL_openlibs(myLuaState); > > > > // register the luaBind classes > > registrate<IFoo>(myLuaState); > > registrate<Foo>(myLuaState); > > registrate<Foo2>(myLuaState); > > registrate<FooManager>(myLuaState); > > > > // create all the objects > > Foo *pFoo = new Foo("Rod's Test: 1-2-3!", myLuaState); > > Foo2 *pFoo2 = new Foo2("Zimba", myLuaState); > > FooManager* pfooManager = new FooManager(); > > > > pfooManager->addComponent(pFoo); > > pfooManager->addComponent(pFoo2); > > // set object manager global > > luabind::globals(myLuaState)["fooManager"] = boost::ref(pfooManager); > > > > //reh 16jun13 the Game Manager will also pass the Instigator to the > > call, i.e., doAwake(theInstigator). This way the object has the object > > interacting with it. > > pfooManager->doAwake(); > > pfooManager->doUpdate(); > > > > lua_close(myLuaState); > > // clean up > > delete pFoo; > > delete pFoo2; > > > > return 0; > > } > > > > > > On Tue, Jun 18, 2013 at 12:42 PM, Daniel Walter > > <dan...@he... <mailto:dan...@he...>> > > wrote: > > > > hi rod, > > thank you for your answer. > > what about the struct "A" in my example? In my project I can not > change > > struct "A" to use boost::ref or any getters. Of course, I could > write a > > wrapper class, but this hurts. > > > > Is there any other way? > > > > > > On 18.06.2013 18:17, rod haxton wrote: > > > give boost:ref a try... > > > > > > luabind::globals(L)["x"] = boost::ref(x); > > > > > > > > > On Tue, Jun 18, 2013 at 10:41 AM, Daniel Walter > > > <dan...@he... > > <mailto:dan...@he...> > > <mailto:dan...@he... > > <mailto:dan...@he...>>> > > > wrote: > > > > > > Hi folks, > > > > > > I have a struct with some pointers to trivial datatypes like > > this: > > > > > > struct A { > > > int* x; > > > int* y; > > > }; > > > > > > I bound it to lua like this: > > > > > > luabind::module(L) > > > [ > > > luabind::class_<A>("A") > > > .def_readonly("x", &A::x) > > > .def_readonly("y", &A::y) > > > ]; > > > > > > If I am using this class in my lua script the runtime throws > this > > > exception: "Trying to use unregistered class" > > > I managed this using a getter function returning the > dereferenced > > > pointer, but there must be a better way. > > > > > > The same exception happens when i am using such an trivial > > pointer > > > directly: > > > > > > int* x = new int(42); > > > luabind::globals(L)["x"] = x; > > > > > > How to handle this? What i am missing? > > > > > > Thanks in advance, > > > Daniel > > > > > > > > > ------------------------------------------------------------------------------ > > > This SF.net email is sponsored by Windows: > > > > > > Build for Windows Store. > > > > > > http://p.sf.net/sfu/windows-dev2dev > > > _______________________________________________ > > > luabind-user mailing list > > > lua...@li... > > <mailto:lua...@li...> > > > <mailto:lua...@li... > > <mailto:lua...@li...>> > > > https://lists.sourceforge.net/lists/listinfo/luabind-user > > > > > > > > > > > > > > > > > > ------------------------------------------------------------------------------ > > > This SF.net email is sponsored by Windows: > > > > > > Build for Windows Store. > > > > > > http://p.sf.net/sfu/windows-dev2dev > > > > > > > > > > > > _______________________________________________ > > > luabind-user mailing list > > > lua...@li... > > <mailto:lua...@li...> > > > https://lists.sourceforge.net/lists/listinfo/luabind-user > > > > > > > > ------------------------------------------------------------------------------ > > This SF.net email is sponsored by Windows: > > > > Build for Windows Store. > > > > http://p.sf.net/sfu/windows-dev2dev > > _______________________________________________ > > luabind-user mailing list > > lua...@li... > > <mailto:lua...@li...> > > https://lists.sourceforge.net/lists/listinfo/luabind-user > > > > > > > > > > > ------------------------------------------------------------------------------ > > This SF.net email is sponsored by Windows: > > > > Build for Windows Store. > > > > http://p.sf.net/sfu/windows-dev2dev > > > > > > > > _______________________________________________ > > luabind-user mailing list > > lua...@li... > > https://lists.sourceforge.net/lists/listinfo/luabind-user > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Windows: > > Build for Windows Store. > > http://p.sf.net/sfu/windows-dev2dev > _______________________________________________ > luabind-user mailing list > lua...@li... > https://lists.sourceforge.net/lists/listinfo/luabind-user > |
From: Daniel W. <dan...@he...> - 2013-06-18 17:12:07
|
I think this does not fit my needs. "FooManager" does not have any public pointers that need to be accessed directly by lua. You are accessing your pointers through "getComponent" function. Can you expose "m_iFooVector" with something like this: ".def_readonly("iFooVector", &FooManager::m_iFooVector, luabind::return_stl_iterator)" And then iterate and access it in your lua script? for foo in fooManager.iFooVector do print(foo.AnyField) end On 18.06.2013 19:01, rod haxton wrote: > Take a look at this. I do this and it works with a boost::ref on class, > see "FooManager". > > I know...I know...I hate when folks give you a lot of code to look at > for an example. But, perhaps you can glean something from looking at the > "FooManager" class, and see that I assign it as a global. > > //The registrate function takes a Class > // name and lua_State, then calls its registrate method > template <typename T> > void registrate(lua_State *pLuaState) { > T::registrate(pLuaState); > } > > > class FooManager > { > public: > FooManager() {}; > ~FooManager() {}; > > voidaddComponent(IFoo* pFoo) { m_iFooVector.push_back(pFoo); } > IFoo*getComponent(int nIndex) { return m_iFooVector[nIndex]; } > > static void registrate(lua_State *pLuaState) > { > luabind::module(pLuaState) [ > luabind::class_<FooManager>("FooManager") > .def(luabind::constructor<>()) > .def("getComponent", (IFoo*(FooManager::*) (int)) &FooManager::getComponent) > ]; > } > > void doAwake(void) > { > for(std::vector<IFoo*>::iterator it = m_iFooVector.begin(); it != > m_iFooVector.end(); it++) > { > IFoo *pIFoo = *it; > pIFoo->Awake(); > } > } > > void doUpdate(void) > { > for(std::vector<IFoo*>::iterator it = m_iFooVector.begin(); it != > m_iFooVector.end(); it++) > { > IFoo *pIFoo = *it; > pIFoo->update(); > } > } > > private: > std::vector<IFoo*> m_iFooVector; > }; > > int main() > { > lua_State *myLuaState = luaL_newstate(); > > // Connect LuaBind to this lua state > luabind::open(myLuaState); > > // open the lua libraries > luaL_openlibs(myLuaState); > > // register the luaBind classes > registrate<IFoo>(myLuaState); > registrate<Foo>(myLuaState); > registrate<Foo2>(myLuaState); > registrate<FooManager>(myLuaState); > > // create all the objects > Foo *pFoo = new Foo("Rod's Test: 1-2-3!", myLuaState); > Foo2 *pFoo2 = new Foo2("Zimba", myLuaState); > FooManager* pfooManager = new FooManager(); > > pfooManager->addComponent(pFoo); > pfooManager->addComponent(pFoo2); > // set object manager global > luabind::globals(myLuaState)["fooManager"] = boost::ref(pfooManager); > > //reh 16jun13 the Game Manager will also pass the Instigator to the > call, i.e., doAwake(theInstigator). This way the object has the object > interacting with it. > pfooManager->doAwake(); > pfooManager->doUpdate(); > > lua_close(myLuaState); > // clean up > delete pFoo; > delete pFoo2; > > return 0; > } > > > On Tue, Jun 18, 2013 at 12:42 PM, Daniel Walter > <dan...@he... <mailto:dan...@he...>> > wrote: > > hi rod, > thank you for your answer. > what about the struct "A" in my example? In my project I can not change > struct "A" to use boost::ref or any getters. Of course, I could write a > wrapper class, but this hurts. > > Is there any other way? > > > On 18.06.2013 18:17, rod haxton wrote: > > give boost:ref a try... > > > > luabind::globals(L)["x"] = boost::ref(x); > > > > > > On Tue, Jun 18, 2013 at 10:41 AM, Daniel Walter > > <dan...@he... > <mailto:dan...@he...> > <mailto:dan...@he... > <mailto:dan...@he...>>> > > wrote: > > > > Hi folks, > > > > I have a struct with some pointers to trivial datatypes like > this: > > > > struct A { > > int* x; > > int* y; > > }; > > > > I bound it to lua like this: > > > > luabind::module(L) > > [ > > luabind::class_<A>("A") > > .def_readonly("x", &A::x) > > .def_readonly("y", &A::y) > > ]; > > > > If I am using this class in my lua script the runtime throws this > > exception: "Trying to use unregistered class" > > I managed this using a getter function returning the dereferenced > > pointer, but there must be a better way. > > > > The same exception happens when i am using such an trivial > pointer > > directly: > > > > int* x = new int(42); > > luabind::globals(L)["x"] = x; > > > > How to handle this? What i am missing? > > > > Thanks in advance, > > Daniel > > > > > ------------------------------------------------------------------------------ > > This SF.net email is sponsored by Windows: > > > > Build for Windows Store. > > > > http://p.sf.net/sfu/windows-dev2dev > > _______________________________________________ > > luabind-user mailing list > > lua...@li... > <mailto:lua...@li...> > > <mailto:lua...@li... > <mailto:lua...@li...>> > > https://lists.sourceforge.net/lists/listinfo/luabind-user > > > > > > > > > > > ------------------------------------------------------------------------------ > > This SF.net email is sponsored by Windows: > > > > Build for Windows Store. > > > > http://p.sf.net/sfu/windows-dev2dev > > > > > > > > _______________________________________________ > > luabind-user mailing list > > lua...@li... > <mailto:lua...@li...> > > https://lists.sourceforge.net/lists/listinfo/luabind-user > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Windows: > > Build for Windows Store. > > http://p.sf.net/sfu/windows-dev2dev > _______________________________________________ > luabind-user mailing list > lua...@li... > <mailto:lua...@li...> > https://lists.sourceforge.net/lists/listinfo/luabind-user > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Windows: > > Build for Windows Store. > > http://p.sf.net/sfu/windows-dev2dev > > > > _______________________________________________ > luabind-user mailing list > lua...@li... > https://lists.sourceforge.net/lists/listinfo/luabind-user > |
From: rod h. <reh...@gm...> - 2013-06-18 17:02:02
|
Take a look at this. I do this and it works with a boost::ref on class, see "FooManager". I know...I know...I hate when folks give you a lot of code to look at for an example. But, perhaps you can glean something from looking at the "FooManager" class, and see that I assign it as a global. //The registrate function takes a Class // name and lua_State, then calls its registrate method template <typename T> void registrate(lua_State *pLuaState) { T::registrate(pLuaState); } class FooManager { public: FooManager() {}; ~FooManager() {}; void addComponent(IFoo* pFoo) { m_iFooVector.push_back(pFoo); } IFoo* getComponent(int nIndex) { return m_iFooVector[nIndex]; } static void registrate(lua_State *pLuaState) { luabind::module(pLuaState) [ luabind::class_<FooManager>("FooManager") .def(luabind::constructor<>()) .def("getComponent", (IFoo*(FooManager::*) (int)) &FooManager::getComponent) ]; } void doAwake(void) { for(std::vector<IFoo*>::iterator it = m_iFooVector.begin(); it != m_iFooVector.end(); it++) { IFoo *pIFoo = *it; pIFoo->Awake(); } } void doUpdate(void) { for(std::vector<IFoo*>::iterator it = m_iFooVector.begin(); it != m_iFooVector.end(); it++) { IFoo *pIFoo = *it; pIFoo->update(); } } private: std::vector<IFoo*> m_iFooVector; }; int main() { lua_State *myLuaState = luaL_newstate(); // Connect LuaBind to this lua state luabind::open(myLuaState); // open the lua libraries luaL_openlibs(myLuaState); // register the luaBind classes registrate<IFoo>(myLuaState); registrate<Foo>(myLuaState); registrate<Foo2>(myLuaState); registrate<FooManager>(myLuaState); // create all the objects Foo *pFoo = new Foo("Rod's Test: 1-2-3!", myLuaState); Foo2 *pFoo2 = new Foo2("Zimba", myLuaState); FooManager* pfooManager = new FooManager(); pfooManager->addComponent(pFoo); pfooManager->addComponent(pFoo2); // set object manager global luabind::globals(myLuaState)["fooManager"] = boost::ref(pfooManager); //reh 16jun13 the Game Manager will also pass the Instigator to the call, i.e., doAwake(theInstigator). This way the object has the object interacting with it. pfooManager->doAwake(); pfooManager->doUpdate(); lua_close(myLuaState); // clean up delete pFoo; delete pFoo2; return 0; } On Tue, Jun 18, 2013 at 12:42 PM, Daniel Walter < dan...@he...> wrote: > hi rod, > thank you for your answer. > what about the struct "A" in my example? In my project I can not change > struct "A" to use boost::ref or any getters. Of course, I could write a > wrapper class, but this hurts. > > Is there any other way? > > > On 18.06.2013 18:17, rod haxton wrote: > > give boost:ref a try... > > > > luabind::globals(L)["x"] = boost::ref(x); > > > > > > On Tue, Jun 18, 2013 at 10:41 AM, Daniel Walter > > <dan...@he... <mailto:dan...@he...>> > > wrote: > > > > Hi folks, > > > > I have a struct with some pointers to trivial datatypes like this: > > > > struct A { > > int* x; > > int* y; > > }; > > > > I bound it to lua like this: > > > > luabind::module(L) > > [ > > luabind::class_<A>("A") > > .def_readonly("x", &A::x) > > .def_readonly("y", &A::y) > > ]; > > > > If I am using this class in my lua script the runtime throws this > > exception: "Trying to use unregistered class" > > I managed this using a getter function returning the dereferenced > > pointer, but there must be a better way. > > > > The same exception happens when i am using such an trivial pointer > > directly: > > > > int* x = new int(42); > > luabind::globals(L)["x"] = x; > > > > How to handle this? What i am missing? > > > > Thanks in advance, > > Daniel > > > > > ------------------------------------------------------------------------------ > > This SF.net email is sponsored by Windows: > > > > Build for Windows Store. > > > > http://p.sf.net/sfu/windows-dev2dev > > _______________________________________________ > > luabind-user mailing list > > lua...@li... > > <mailto:lua...@li...> > > https://lists.sourceforge.net/lists/listinfo/luabind-user > > > > > > > > > > > ------------------------------------------------------------------------------ > > This SF.net email is sponsored by Windows: > > > > Build for Windows Store. > > > > http://p.sf.net/sfu/windows-dev2dev > > > > > > > > _______________________________________________ > > luabind-user mailing list > > lua...@li... > > https://lists.sourceforge.net/lists/listinfo/luabind-user > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Windows: > > Build for Windows Store. > > http://p.sf.net/sfu/windows-dev2dev > _______________________________________________ > luabind-user mailing list > lua...@li... > https://lists.sourceforge.net/lists/listinfo/luabind-user > |
From: Daniel W. <dan...@he...> - 2013-06-18 16:42:48
|
hi rod, thank you for your answer. what about the struct "A" in my example? In my project I can not change struct "A" to use boost::ref or any getters. Of course, I could write a wrapper class, but this hurts. Is there any other way? On 18.06.2013 18:17, rod haxton wrote: > give boost:ref a try... > > luabind::globals(L)["x"] = boost::ref(x); > > > On Tue, Jun 18, 2013 at 10:41 AM, Daniel Walter > <dan...@he... <mailto:dan...@he...>> > wrote: > > Hi folks, > > I have a struct with some pointers to trivial datatypes like this: > > struct A { > int* x; > int* y; > }; > > I bound it to lua like this: > > luabind::module(L) > [ > luabind::class_<A>("A") > .def_readonly("x", &A::x) > .def_readonly("y", &A::y) > ]; > > If I am using this class in my lua script the runtime throws this > exception: "Trying to use unregistered class" > I managed this using a getter function returning the dereferenced > pointer, but there must be a better way. > > The same exception happens when i am using such an trivial pointer > directly: > > int* x = new int(42); > luabind::globals(L)["x"] = x; > > How to handle this? What i am missing? > > Thanks in advance, > Daniel > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Windows: > > Build for Windows Store. > > http://p.sf.net/sfu/windows-dev2dev > _______________________________________________ > luabind-user mailing list > lua...@li... > <mailto:lua...@li...> > https://lists.sourceforge.net/lists/listinfo/luabind-user > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Windows: > > Build for Windows Store. > > http://p.sf.net/sfu/windows-dev2dev > > > > _______________________________________________ > luabind-user mailing list > lua...@li... > https://lists.sourceforge.net/lists/listinfo/luabind-user > |
From: rod h. <reh...@gm...> - 2013-06-18 16:17:30
|
give boost:ref a try... luabind::globals(L)["x"] = boost::ref(x); On Tue, Jun 18, 2013 at 10:41 AM, Daniel Walter < dan...@he...> wrote: > Hi folks, > > I have a struct with some pointers to trivial datatypes like this: > > struct A { > int* x; > int* y; > }; > > I bound it to lua like this: > > luabind::module(L) > [ > luabind::class_<A>("A") > .def_readonly("x", &A::x) > .def_readonly("y", &A::y) > ]; > > If I am using this class in my lua script the runtime throws this > exception: "Trying to use unregistered class" > I managed this using a getter function returning the dereferenced > pointer, but there must be a better way. > > The same exception happens when i am using such an trivial pointer > directly: > > int* x = new int(42); > luabind::globals(L)["x"] = x; > > How to handle this? What i am missing? > > Thanks in advance, > Daniel > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Windows: > > Build for Windows Store. > > http://p.sf.net/sfu/windows-dev2dev > _______________________________________________ > luabind-user mailing list > lua...@li... > https://lists.sourceforge.net/lists/listinfo/luabind-user > |
From: Daniel W. <dan...@he...> - 2013-06-18 14:58:49
|
Hi folks, I have a struct with some pointers to trivial datatypes like this: struct A { int* x; int* y; }; I bound it to lua like this: luabind::module(L) [ luabind::class_<A>("A") .def_readonly("x", &A::x) .def_readonly("y", &A::y) ]; If I am using this class in my lua script the runtime throws this exception: "Trying to use unregistered class" I managed this using a getter function returning the dereferenced pointer, but there must be a better way. The same exception happens when i am using such an trivial pointer directly: int* x = new int(42); luabind::globals(L)["x"] = x; How to handle this? What i am missing? Thanks in advance, Daniel |
From: voodooRod <reh...@gm...> - 2013-06-16 00:01:47
|
I solved my own problem. I needed to first bind my abstract class "IFoo." And, in my class Foo I needed to bind the constructor with the derived IFoo. So now, all works. I will post the working code below in case anyone else needs to know how to do. All the samples online seem to show how to bind C++ to Lua and then construct the objects from Lua. However, if you wish to do "declarative" programming, creating and managing the objects on the C++ side and then allowing Lua to manipulate those objects, I hadn't found any clear samples. So, here's a sample... // C++ CODE template <typename T> void registrate(lua_State *pLuaState) { T::registrate(pLuaState); } class IFoo { public: virtual ~IFoo() {} virtual void sayName(void) = 0; virtual void doAwake(void) = 0; virtual void update(void) = 0; static void registrate(lua_State *pLuaState) { // export our class with LuaBind luabind::module(pLuaState) [ luabind::class_<IFoo>("IFoo") .def("sayName", (void(IFoo::*) (void)) &IFoo::sayName) ]; } }; class Foo : public IFoo { public: Foo() { m_sName = "Blank"; } Foo(std::string sName, lua_State* pLuaState) : m_sName(sName), m_pLuaState(pLuaState) {} void sayName(void) { printf("FOO: the name is: %s\n", m_sName.c_str()); } void changeName(const std::string &sName) { m_sName = sName; } void update(void){}; void doAwake(void) { // do the script if(luaL_dofile(m_pLuaState, "myscript1.lua")) { printf("Lua engine error: %s",lua_tostring(m_pLuaState, 1)); return; } try { // call the lua function luabind::call_function<void>(m_pLuaState, "Awake"); } catch (luabind::error& e) { std::string error = lua_tostring( e.state(), -1 ); std::cout << error << "\n"; } } static void registrate(lua_State *pLuaState) { // export our class with LuaBind luabind::module(pLuaState) [ luabind::class_<Foo, IFoo>("Foo") .def(luabind::constructor<>()) .def(luabind::constructor<std::string, lua_State*>()) .def("sayName", (void(Foo::*) (void)) &Foo::sayName) .def("changeName", (void(Foo::*) (const std::string &)) &Foo::changeName) ]; } private: std::string m_sName; lua_State *m_pLuaState; }; class Foo2 : public Foo { public: Foo2() {} Foo2(std::string sName) : Foo(sName, NULL) { m_sName = sName; } void sayName(void) { printf("FOO2: the name is: %s\n", m_sName.c_str()); } void sayNothing(void) { printf("FOO2: saying nothing %s\n", m_sName.c_str()); } void update(void) {} void doAwake(void) {} void sayFooName(void) { printf("FOO2: saying FOO's name = "); Foo::sayName(); } static void registrate(lua_State *pLuaState) { luabind::module(pLuaState) [ luabind::class_<Foo2, Foo>("Foo2") .def(luabind::constructor<std::string>()) .def("sayName", (void(Foo2::*) (void)) &Foo2::sayName) .def("sayNothing", (void(Foo2::*) (void)) &Foo2::sayNothing) ]; } private: std::string m_sName; }; class FooManager { public: FooManager() {}; ~FooManager() {}; void addComponent(IFoo* pFoo) { m_iFooVector.push_back(pFoo); } IFoo* getComponent(int nIndex) { return m_iFooVector[nIndex]; } static void registrate(lua_State *pLuaState) { luabind::module(pLuaState) [ luabind::class_<FooManager>("FooManager") .def(luabind::constructor<>()) .def("getComponent", (IFoo*(FooManager::*) (int)) &FooManager::getComponent) ]; } private: std::vector<IFoo*> m_iFooVector; }; int main() { lua_State *myLuaState = luaL_newstate(); // Connect LuaBind to this lua state luabind::open(myLuaState); // open the lua libraries luaL_openlibs(myLuaState); // register the luaBind classes registrate<IFoo>(myLuaState); registrate<Foo>(myLuaState); registrate<Foo2>(myLuaState); registrate<FooManager>(myLuaState); // create all the objects Foo *pFoo = new Foo("Test: 1-2-3!", myLuaState); Foo2 *pFoo2 = new Foo2("Zimba"); FooManager* pfooManager = new FooManager(); pfooManager->addComponent(pFoo); pfooManager->addComponent(pFoo2); // set object manager global luabind::globals(myLuaState)["fooManager"] = boost::ref(pfooManager); pFoo->doAwake(); lua_close(myLuaState); // clean up delete pFoo; delete pFoo2; return 0; } // LUA SCRIPT function Awake() print("In Awake!") local pFooObj = fooManager:getComponent(0) pFooObj:sayName(); end Cheers! -- View this message in context: http://lua.2524044.n2.nabble.com/Opps-need-help-on-how-to-manage-c-objects-from-Lua-tp7649956p7650002.html Sent from the Lua C++ Bind mailing list archive at Nabble.com. |