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.
7f064c6157df91df3efc93bdd6687fe2?d=identicon&s=25 Dudu Baião (Guest)
on 2008-11-26 03: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!
A120eb09d383829bfa210bf656fcde4e?d=identicon&s=25 John Lam (IRONRUBY) (Guest)
on 2008-11-26 05: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
F983f0c990cba2fe743ef62a975ec99c?d=identicon&s=25 Curt Hagenlocher (Guest)
on 2008-11-26 16:46
(Received via mailing list)
For the first problem, does it work if you just use "super" without any
arguments?
7f064c6157df91df3efc93bdd6687fe2?d=identicon&s=25 Dudu Baião (Guest)
on 2008-11-26 19: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 Lam (IRONRUBY) <jflam@microsoft.com>:
7f064c6157df91df3efc93bdd6687fe2?d=identicon&s=25 Dudu Baião (Guest)
on 2008-11-26 19:53
(Received via mailing list)
Hi Curt!

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

2008/11/26 Curt Hagenlocher <curth@microsoft.com>:
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2008-11-26 20: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
D91500918a07bfae5b38b8943fd42fbe?d=identicon&s=25 Mike Moore (Guest)
on 2008-11-26 21:02
(Received via mailing list)
On Wed, Nov 26, 2008 at 12:04 PM, Tomas Matousek <
Tomas.Matousek@microsoft.com> 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
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2008-11-26 21: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: ironruby-core-bounces@rubyforge.org
[mailto:ironruby-core-bounces@rubyforge.org] On Behalf Of Mike Moore
Sent: Wednesday, November 26, 2008 12:02 PM
To: ironruby-core@rubyforge.org
Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics

On Wed, Nov 26, 2008 at 12:04 PM, Tomas Matousek
<Tomas.Matousek@microsoft.com<mailto:Tomas.Matousek@microsoft.com>>
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
D66f1026934d7b379ecf51556a4b41cf?d=identicon&s=25 Orion Edwards (Guest)
on 2008-11-26 21:38
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2008-11-27 00:22
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
D66f1026934d7b379ecf51556a4b41cf?d=identicon&s=25 Orion Edwards (Guest)
on 2008-11-27 00:27
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2008-11-27 00:37
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
D66f1026934d7b379ecf51556a4b41cf?d=identicon&s=25 Orion Edwards (Guest)
on 2008-11-27 01:10
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
Ade8632553a9243ae05fc920f68644c1?d=identicon&s=25 Jim Deville (Guest)
on 2008-11-27 01:13
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
Aea6cfe04952626ab630bde47ff82f89?d=identicon&s=25 Shri Borde (Guest)
on 2009-01-09 08:46
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2009-01-09 09:26
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
Aea6cfe04952626ab630bde47ff82f89?d=identicon&s=25 Shri Borde (Guest)
on 2009-01-09 19:02
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
E1deaac6561498a0e7472e6268ea9ccc?d=identicon&s=25 Jimmy Schementi (Guest)
on 2009-01-09 22:16
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2009-01-09 23:01
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
Aea6cfe04952626ab630bde47ff82f89?d=identicon&s=25 Shri Borde (Guest)
on 2009-01-09 23:08
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
E1deaac6561498a0e7472e6268ea9ccc?d=identicon&s=25 Jimmy Schementi (Guest)
on 2009-01-09 23:20
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
99b1f0c67bec23747d007e27d000487b?d=identicon&s=25 Ryan Riley (Guest)
on 2009-01-09 23: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 Schementi <
E1deaac6561498a0e7472e6268ea9ccc?d=identicon&s=25 Jimmy Schementi (Guest)
on 2009-01-10 00: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: ironruby-core-bounces@rubyforge.org
[mailto:ironruby-core-bounces@rubyforge.org] On Behalf Of Ryan Riley
Sent: Friday, January 09, 2009 1:51 PM
To: ironruby-core@rubyforge.org
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 Schementi
<Jimmy.Schementi@microsoft.com<mailto:Jimmy.Schementi@microsoft.com>>
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 Riley
ryan.riley@panesofglass.org<mailto:ryan.riley@panesofglass.org>
http://panesofglass.org/
http://wizardsofsmart.net/
Ade8632553a9243ae05fc920f68644c1?d=identicon&s=25 Jim Deville (Guest)
on 2009-01-10 00:10
(Received via mailing list)
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
99b1f0c67bec23747d007e27d000487b?d=identicon&s=25 Ryan Riley (Guest)
on 2009-01-10 00: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 Matousek
<Tomas.Matousek@microsoft.com
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2009-01-10 01:21
(Received via mailing list)
Generic types already work:

List = List.of(Object).new

Tomas

From: ironruby-core-bounces@rubyforge.org
[mailto:ironruby-core-bounces@rubyforge.org] On Behalf Of Ryan Riley
Sent: Friday, January 09, 2009 2:33 PM
To: ironruby-core@rubyforge.org
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 Matousek
<Tomas.Matousek@microsoft.com<mailto:Tomas.Matousek@microsoft.com>>
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
E1deaac6561498a0e7472e6268ea9ccc?d=identicon&s=25 Jimmy Schementi (Guest)
on 2009-01-10 01: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: ironruby-core-bounces@rubyforge.org
[mailto:ironruby-core-bounces@rubyforge.org] On Behalf Of Ryan Riley
Sent: Friday, January 09, 2009 2:33 PM
To: ironruby-core@rubyforge.org
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 Matousek
<Tomas.Matousek@microsoft.com<mailto:Tomas.Matousek@microsoft.com>>
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
99b1f0c67bec23747d007e27d000487b?d=identicon&s=25 Ryan Riley (Guest)
on 2009-01-10 04:41
(Received via mailing list)
Oops! Sorry for being a bit behind!

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