FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Binding overloaded methods

 
Post new topic   Reply to topic     Forum Index -> MiniD
View previous topic :: View next topic  
Author Message
LeoD



Joined: 14 Feb 2007
Posts: 6

PostPosted: Sat Nov 24, 2007 6:29 pm    Post subject: Binding overloaded methods Reply with quote

Hey,

I'm trying to bind overloaded methods, but it somehow doesn't seem to work.

Code:

module minid_test;

import tango.io.Stdout;

import minid.minid;
import minid.types;
import minid.bind;

class Foo
{
   void bar()
   {
      Stdout("Hello World!").newline;
   }
   
   void bar(int)
   {
      Stdout("Bye World!").newline;
   }
}

void main()
{
   auto context = NewContext();
   
   WrapClass!(Foo)().method!(Foo.bar, "bar", void function())().
                     method!(Foo.bar, "barInt", void function(int))().
                     makeGlobal(context);
   
   loadStatementString(context.mainThread,
                       "local f = Foo();
                        f.bar();
                        f.barInt();");
}


The output is "Hello World! Hello World", I'm expecting "Hello World! Bye World!" though.

What am I doing wrong there? Smile
Back to top
View user's profile Send private message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Sat Nov 24, 2007 6:43 pm    Post subject: Reply with quote

You're not calling barInt with a parameter.

That this doesn't fail and instead calls the other overload is an odd side effect of the way the binding library determines the minimum number of parameters that a function can be called with. Since you can actually call the native method with no parameters, it works.

I've been thinking of making it so that if you specify a type for the function/method, it'll accept that as the minimum number of parameters and not try to figure it out for itself. That probably wouldn't mess anything up and would make things behave more like you'd expect.
Back to top
View user's profile Send private message
LeoD



Joined: 14 Feb 2007
Posts: 6

PostPosted: Sat Nov 24, 2007 6:50 pm    Post subject: Reply with quote

Thanks for your quick answer!

That makes sense, I actually only forgot to put a parameter there. Embarassed
Back to top
View user's profile Send private message
LeoD



Joined: 14 Feb 2007
Posts: 6

PostPosted: Sat Nov 24, 2007 7:22 pm    Post subject: Reply with quote

Some more questions:

- Can I bind abstract classes?
- Can I bind methods, which have arguments like Object[]?

EDIT:
Okay, found something about Object[]..
"Arrays of wrapped structs/classes are not yet supported."
Back to top
View user's profile Send private message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Sat Nov 24, 2007 9:43 pm    Post subject: Reply with quote

Abstract classes... I honestly hadn't taken that into account Smile It'll complain that it can't be instantiated and ask you to bind a constructor, won't it? Hm. Wonder if it's possible to check if a class is abstract in D1, and if so, make it so that check happens at runtime instead of compile time..

I'd like to add support arrays of wrapped classes and structs, but that might involve integrating the binding library into the native API a little more tightly, and I'm not sure how far I want to take that.
Back to top
View user's profile Send private message
LeoD



Joined: 14 Feb 2007
Posts: 6

PostPosted: Sun Nov 25, 2007 8:31 am    Post subject: Reply with quote

JarrettBillingsley wrote:
I'd like to add support arrays of wrapped classes and structs, but that might involve integrating the binding library into the native API a little more tightly, and I'm not sure how far I want to take that.

Hm, ok.. is there any workaround for that? I'd really need to pass arrays of wrapped classes... Sad
Back to top
View user's profile Send private message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Sun Nov 25, 2007 9:19 am    Post subject: Reply with quote

You'd have to modify the ToDType and ToMiniDType functions in minid.bind, and they're private. But to add support for arrays of wrapped classes, I'll be modifying that anyway, so you might as well not mess with it XD Unless you can figure it out and want to contribute some code!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> MiniD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group