Luabind and function objects

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Luabind and function objects

boldt
Hi

In the previous version of luabind I used the luabind/functor object,
but as I understand for version 0.7 it has been removed and you should
use luabind::object instead. However, from the documentation I has not
been able to figure out how this should/could be done

eg my old code looked like

void foo( luabind::functor<C*>& f ){
 C* = f();
}

I guess that in the new version of luabind it should look something like

void foo( luabind::object& f ){
 ....
}

But how do I do the function call on the luabind object?

Thanks,
Niels


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
<a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

luabind and gcc 4.1

Bugzilla from edb@sigluy.net
Since i have some issue with luabind and gcc 4.1 pre release, i've told about
it on #gcc. here the conversation

[19:55] <EdB> does this code seem correct ?
[19:56] <EdB> template<class A>
[19:56] <EdB>     Ark::Ptr<const A>* get_const_holder(Ark::Ptr<A> *p)
[19:56] <EdB>     {
[19:56] <EdB>         return 0;
[19:56] <EdB>     }
[20:01] <DieMumiee> no, not at all.
[20:01] <EdB> ?
[20:02] <DieMumiee> whats the purpose of get_const_holder?
[20:02] <DieMumiee> and what is ark::ptr good for?
[20:02] <DieMumiee> maybe Ark::Ptr<const A> get_const_holder(Ark::Ptr<A> *p) {
return 0; } makes more sense
[20:03] <EdB> it's axplain here
[20:03] <EdB>
http://www.rasterbar.com/products/luabind/docs.html#smart-pointers
[20:03] <EdB> Ark::Ptr for smart_ptr
[20:04] <EdB> but that don't work with gcc 4.1
[20:04] <DieMumiee> then i dont see why they pass pointers on smart pointers
around
[20:06] <DieMumiee> oh just read the statement below
[20:07] <DieMumiee> +I
[20:07] <EdB> so it's seem good ?
[20:08] <DieMumiee> well it looks like that they never use that function
during runtime, only for compiletime stuff to get the type of the pointer
[20:08] <DieMumiee> but i dont see why they use that, instead of just writing
a metafunction
[20:09] <EdB> there is a strange behavior with 4.1
[20:10] <EdB> DieMumiee: I'm not a great coder, what is you idea ?
[20:11] <DieMumiee> i would have writen something like template<typename T>
struct const_holder{}; template<typename T> struct
const_holder<boost::shared_ptr<T>*> {typedef boost::shared_ptr<const T>*
type; };
[20:12] <-- Jeaton has left this server.
[20:12] <DieMumiee> i dont know how they use get_const_holder in luabind
[20:12] <DieMumiee> but i heard a lot about luabinds problems with gcc,
recently.
[20:12] --> Jeaton has joined this channel
(i=[hidden email]).
[20:12] <DieMumiee> Do you have source code of luabind showing calls to
get_const_holder?
[20:16] <EdB> but here, you depend on boost::shared_ptr
[20:17] <DieMumiee> well you could write Ark::Ptr instead of shared_ptr
[20:20] <EdB> implementation are here
http://www.rafb.net./paste/results/k054uB76.html
[20:20] <EdB> but it's a bit long
[20:22] <DieMumiee> so your problem is that gcc does not find that overload?
[20:22] <EdB> yes
[20:22] <-- Jeaton has left this server.
[20:23] <DieMumiee> luabind has a bug there, it assumes that overloaded
function are bound at instantiation time of templates,
[20:23] <DieMumiee> but overloaded functions are already bound at definition
time,
[20:23] <DieMumiee> so the luabind structures only see the
get_const_holder(...)
[20:24] <DieMumiee> you can "fix" that by ensuring that your overloads are
visible to the compiler befor it parses any luabind code
[20:29] --> Jeaton has joined this channel
(i=[hidden email]).
[20:33] <-- brainiac_ghost has left this channel ("Leaving").
[20:43] <EdB> DieMumiee: ok, i look for that
[20:47] <-- Jeaton has left this server.
[20:48] --> sharkk has joined this channel
(n=[hidden email]).
[20:54] <-- azi_ has left this server ("Leaving").
[20:58] <EdB> DieMumiee: thank for your attention


note that, during this talk, i've upgrade gcc 4.1 to another pre release
version and the "fix" is no more needed.
may be this is not usefull for you, but if it can be

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: luabind and gcc 4.1

Daniel Wallin-2
EdB wrote:

> Since i have some issue with luabind and gcc 4.1 pre release, i've told about
> it on #gcc. here the conversation
>
> [19:55] <EdB> does this code seem correct ?
> [19:56] <EdB> template<class A>
> [19:56] <EdB>     Ark::Ptr<const A>* get_const_holder(Ark::Ptr<A> *p)
> [19:56] <EdB>     {
> [19:56] <EdB>         return 0;
> [19:56] <EdB>     }
> [20:01] <DieMumiee> no, not at all.
> [20:01] <EdB> ?
[snip]
> [20:08] <DieMumiee> well it looks like that they never use that function
> during runtime, only for compiletime stuff to get the type of the pointer
> [20:08] <DieMumiee> but i dont see why they use that, instead of just writing
> a metafunction

It was done this way to support legacy compilers that doesn't support
partial template specialization. At that time this was important to us.

I have a private branch where I rewrite large parts of luabind for a
future release. This is one thing that will be changed then.

> [20:22] <DieMumiee> so your problem is that gcc does not find that overload?
> [20:22] <EdB> yes
> [20:22] <-- Jeaton has left this server.
> [20:23] <DieMumiee> luabind has a bug there, it assumes that overloaded
> function are bound at instantiation time of templates,
> [20:23] <DieMumiee> but overloaded functions are already bound at definition
> time,
> [20:23] <DieMumiee> so the luabind structures only see the
> get_const_holder(...)

FWIW, I don't think this is technically correct. get_const_holder() is a
dependent name, and will trigger 2-phase lookup on conforming compilers.
The actual reason that GCC fails to find the overload is that it can't
be found in an associated namespace with ADL during the second lookup
phase (at the instantiation point), and therefore only the
get_const_holder(...) from the first phase is found.

> [20:24] <DieMumiee> you can "fix" that by ensuring that your overloads are
> visible to the compiler befor it parses any luabind code

The proper "fix" would be to put the get_const_holder() inside the Ark
namespace.

I agree that this is a bug though -- if nothing else at least a doc bug.

--
Daniel Wallin



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Re: luabind and gcc 4.1

Bugzilla from edb@sigluy.net
Great thank for you reponse.

What is the state of your private branch ?

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Luabind and function objects

Daniel Wallin-2
In reply to this post by boldt
Niels Boldt wrote:
> But how do I do the function call on the luabind object?

  void foo(luabind::object const& f)
  {
      C* c = luabind::object_cast<C*>(f());
  }

Should work.

--
Daniel Wallin



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user