Forum: IronRuby IronRuby and XNA. Super and Generics

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dudu Baião (Guest)
on 2008-11-26 04:26
(Received via mailing list)
Hi guys!

Im playing with XNA trying to run the simplest xna example: To show a
SpriteBatch on screen.

After some tests I found some problems:

1- The "Microsoft::Xna::Framework::Game" expects that we implement
some methods like "Update", "Drawn" etc, and inside the method we have
to call the base class (super) actual method passing some parameters.

If I try to do this:

    def update(game_time)
      super(game_time)
    end

I get this error:

my_game.rb:23:in `update': wrong number or type of arguments for
`update' (ArgumentError)
    from Snippets.scripting:0:in `Update'
    from Microsoft.Xna.Framework.Game:0:in `Run'
    from program.rb:23:in `main'
    from :0

2- XNA uses generic functions to load the game contents. How can I
convert the code above to IronRuby?

// This is a texture we can render.
Texture2D myTexture;

protected override void LoadContent()
{
    myTexture = Content.Load<Texture2D>("mytexture");
}

Can IronRuby consume generics?

Thanks!
John L. (IRONRUBY) (Guest)
on 2008-11-26 06:12
(Received via mailing list)
We can't consume generic methods today. It's on the list of things to do
though.

You can work around this by defining a concrete method in C# that calls
the appropriate generic method and call the concrete method from
IronRuby.

Thanks,
-John
Curt H. (Guest)
on 2008-11-26 17:46
(Received via mailing list)
For the first problem, does it work if you just use "super" without any
arguments?
Dudu Baião (Guest)
on 2008-11-26 20:48
(Received via mailing list)
Thanks John!

I will do that.

Just for curiosity, what will be the syntax to call generic methods? :)


2008/11/26 John L. (IRONRUBY) <removed_email_address@domain.invalid>:
Dudu Baião (Guest)
on 2008-11-26 20:53
(Received via mailing list)
Hi Curt!

Unfortunatelly it does not work. The error returned is the same. :(

2008/11/26 Curt H. <removed_email_address@domain.invalid>:
Tomas M. (Guest)
on 2008-11-26 21:06
(Received via mailing list)
I'm thinking of something like:

myTexture = content.load of(Texture2D), "mytexture"

I.e. we would add Kernel#of method that takes a list of classes/modules
and returns a special object representing generic parameters that binder
would use for selecting the right method.

We are open for more ideas.

Tomas
Mike M. (Guest)
on 2008-11-26 22:02
(Received via mailing list)
On Wed, Nov 26, 2008 at 12:04 PM, Tomas M. <
removed_email_address@domain.invalid> wrote:

> I'm thinking of something like:
>
> myTexture = content.load of(Texture2D), "mytexture"
>
> I.e. we would add Kernel#of method that takes a list of classes/modules and
> returns a special object representing generic parameters that binder would
> use for selecting the right method.
>
> We are open for more ideas.
>

Couldn't you just send in the constant? What would the Kernel#of method
do
for you?

myTexture = content.load Texture2D, "mytexture"

Or, could you use method_missing?

myTexture = content.load_Texture2D "mytexture"

Tomas
Tomas M. (Guest)
on 2008-11-26 22:13
(Received via mailing list)
What if the method has signature m<T>(object x, ... T...). How do we
know you don't want to pass the value of constant Texture2D as x? "of"
would wrap it into an internal class that would be known as carrying
generic parameter types and always unwrapped.

load_Texture2D clashes with name mangling and is not composable. What if
you want to call method with parameter Dictionary<string, List<object>>?
With "of" you would do:

load of(Dictionary.of(System::String, List.of(Object))

Tomas

From: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] On Behalf Of Mike M.
Sent: Wednesday, November 26, 2008 12:02 PM
To: removed_email_address@domain.invalid
Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics

On Wed, Nov 26, 2008 at 12:04 PM, Tomas M.
<removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>>
wrote:
I'm thinking of something like:

myTexture = content.load of(Texture2D), "mytexture"

I.e. we would add Kernel#of method that takes a list of classes/modules
and returns a special object representing generic parameters that binder
would use for selecting the right method.

We are open for more ideas.

Couldn't you just send in the constant? What would the Kernel#of method
do for you?

myTexture = content.load Texture2D, "mytexture"

Or, could you use method_missing?

myTexture = content.load_Texture2D "mytexture"

Tomas
Orion E. (Guest)
on 2008-11-26 22:38
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Tomas M. (Guest)
on 2008-11-27 01:22
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Orion E. (Guest)
on 2008-11-27 01:27
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Tomas M. (Guest)
on 2008-11-27 01:37
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Orion E. (Guest)
on 2008-11-27 02:10
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Jim D. (Guest)
on 2008-11-27 02:13
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Shri B. (Guest)
on 2009-01-09 09:46
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Tomas M. (Guest)
on 2009-01-09 10:26
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Shri B. (Guest)
on 2009-01-09 20:02
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Jimmy S. (Guest)
on 2009-01-09 23:16
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Tomas M. (Guest)
on 2009-01-10 00:01
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Shri B. (Guest)
on 2009-01-10 00:08
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Jimmy S. (Guest)
on 2009-01-10 00:20
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Ryan R. (Guest)
on 2009-01-10 00:43
(Received via mailing list)
I like Tomas's idea the best. Generics are not native to Ruby, so most
people using them will likely have a C#/VB background, which means
Tomas's
syntax would be more familiar.

The "_of" syntax isn't bad, but forcing a ".do" or ".call" at the end
isn't
ideal, even if it does have a bit of a Ruby flavor.

Adding a ".of()" to the class is okay, but many classes may have generic
methods even when the class itself is not a generic. (I'm thinking
primarily
of static and extension method classes here.)

Passing the generic types as the first parameters seems the most
explicit
and understandable translation to me.

~ Ryan

On Fri, Jan 9, 2009 at 3:12 PM, Jimmy S. <
Jimmy S. (Guest)
on 2009-01-10 01:02
(Received via mailing list)
Let's let Tomas implement
content.method(:load).of(Texture2D).call(“mytexture”) ... and then we
can play around with the different syntax in context. Then it's
pick-the-syntax-you-want =)

From: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] On Behalf Of Ryan R.
Sent: Friday, January 09, 2009 1:51 PM
To: removed_email_address@domain.invalid
Subject: Re: [Ironruby-core] Generic method synxtax

I like Tomas's idea the best. Generics are not native to Ruby, so most
people using them will likely have a C#/VB background, which means
Tomas's syntax would be more familiar.

The "_of" syntax isn't bad, but forcing a ".do" or ".call" at the end
isn't ideal, even if it does have a bit of a Ruby flavor.

Adding a ".of()" to the class is okay, but many classes may have generic
methods even when the class itself is not a generic. (I'm thinking
primarily of static and extension method classes here.)

Passing the generic types as the first parameters seems the most
explicit and understandable translation to me.

~ Ryan
On Fri, Jan 9, 2009 at 3:12 PM, Jimmy S.
<removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>>
wrote:

Here are the ideas that stand out to me:



I like Tomas's idea, since it reads like C#/VB, but adding an argument
to the front urks me:



content.load of(Texture2D), "mytexture"



Shri, having the "_of" appended to a generic method name and requiring a
".do" after it is how you would work with lambdas (except you do
".call"), but since we're talking about .NET methods, not .NET
delegates. So, I'd like the syntax to look more like a method call.
Also, as Tomas says, mangling gets more complicated ...



content.load_of(Texture2D).call "mytexture"



How about adding an "of" method to the class/object, to put the class in
a generic "mode"? The method probably shouldn't be called "of", but you
get the idea. It reads different than C#, but seems the most Rubyesk
without changing the arguments.



content.of(Texture2D).load "mytexture"



Thoughts? If no one likes my idea, I think Tomas's is a fine compromise.

~js

--
Ryan R.
removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>
http://panesofglass.org/
http://wizardsofsmart.net/
Jim D. (Guest)
on 2009-01-10 01:10
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/ironruby-core
Ryan R. (Guest)
on 2009-01-10 01:34
(Received via mailing list)
How would this look for instantiating a generic object?

my_object = Foo.method(:new).of(Bar).call

That seems strange. Perhaps we need to possibilities: the above for
generic
methods and the following for generic classes:

my_object = Foo.of(Bar).new
# where Foo would be defined as Foo<T> in C#

my_clone = my_object.clone
# where clone would have a C# signature of T Clone<T>()

or should that be:

my_clone = my_object.method(:clone).of(Bar).call?
# and allow my_object.clone to have an overloaded
# C# signature of object Clone()?

~Ryan

On Fri, Jan 9, 2009 at 3:45 PM, Tomas M.
<removed_email_address@domain.invalid
Tomas M. (Guest)
on 2009-01-10 02:21
(Received via mailing list)
Generic types already work:

List = List.of(Object).new

Tomas

From: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] On Behalf Of Ryan R.
Sent: Friday, January 09, 2009 2:33 PM
To: removed_email_address@domain.invalid
Subject: Re: [Ironruby-core] Generic method synxtax

How would this look for instantiating a generic object?

my_object = Foo.method(:new).of(Bar).call

That seems strange. Perhaps we need to possibilities: the above for
generic methods and the following for generic classes:

my_object = Foo.of(Bar).new
# where Foo would be defined as Foo<T> in C#

my_clone = my_object.clone
# where clone would have a C# signature of T Clone<T>()

or should that be:

my_clone = my_object.method(:clone).of(Bar).call?
# and allow my_object.clone to have an overloaded
# C# signature of object Clone()?

~Ryan
On Fri, Jan 9, 2009 at 3:45 PM, Tomas M.
<removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>>
wrote:

Mine has also an issue that just occurred to me. If you do:



class C

  content.load of(Texture2D), "foo"

end



"of" resolves to Module#of which would return a C<Texture2D> if C was a
generic type or throws an exception.

So that's not good either. We would need a different method name for
generic method constructor than for generic type. Maybe "method_of"?



As for your idea:

content.of(T).load



is looks backwards. The content is not of T… the load is. I think this
would be confusing.



Until we figure out some nice clean solution that works in 100% cases, I
would implement the following as the first step for generic method
support:



content.method(:load).of(Texture2D).call("mytexture")



(Note, you can do the same in Ruby for regular methods:
"foo".method(:center).call(100))



anything else is just a convenience and anyone could define it via
standard Ruby means.



Tomas
Jimmy S. (Guest)
on 2009-01-10 02:29
(Received via mailing list)
Foo.of(Bar).new works today … since it's about instantiating generic
types … this discussion was only about generic methods.

From: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] On Behalf Of Ryan R.
Sent: Friday, January 09, 2009 2:33 PM
To: removed_email_address@domain.invalid
Subject: Re: [Ironruby-core] Generic method synxtax

How would this look for instantiating a generic object?

my_object = Foo.method(:new).of(Bar).call

That seems strange. Perhaps we need to possibilities: the above for
generic methods and the following for generic classes:

my_object = Foo.of(Bar).new
# where Foo would be defined as Foo<T> in C#

my_clone = my_object.clone
# where clone would have a C# signature of T Clone<T>()

or should that be:

my_clone = my_object.method(:clone).of(Bar).call?
# and allow my_object.clone to have an overloaded
# C# signature of object Clone()?

~Ryan
On Fri, Jan 9, 2009 at 3:45 PM, Tomas M.
<removed_email_address@domain.invalid<mailto:removed_email_address@domain.invalid>>
wrote:

Mine has also an issue that just occurred to me. If you do:



class C

  content.load of(Texture2D), "foo"

end



"of" resolves to Module#of which would return a C<Texture2D> if C was a
generic type or throws an exception.

So that's not good either. We would need a different method name for
generic method constructor than for generic type. Maybe "method_of"?



As for your idea:

content.of(T).load



is looks backwards. The content is not of T… the load is. I think this
would be confusing.



Until we figure out some nice clean solution that works in 100% cases, I
would implement the following as the first step for generic method
support:



content.method(:load).of(Texture2D).call("mytexture")



(Note, you can do the same in Ruby for regular methods:
"foo".method(:center).call(100))



anything else is just a convenience and anyone could define it via
standard Ruby means.



Tomas
Ryan R. (Guest)
on 2009-01-10 05:41
(Received via mailing list)
Oops! Sorry for being a bit behind!

On Fri, Jan 9, 2009 at 5:37 PM, Jimmy S. <
This topic is locked and can not be replied to.