How to extend builtin classes?

Hi

How do we extend inbuilt classes. For example Float doesn’t have *
method implemented. I tried adding this method:
[RubyMethodAttribute("*", RubyMethodAttributes.PublicInstance)]
public static object Multiply(double self, double value)
{
// TODO: overflow
return self * value;
}
but did not work after compilation. It still complains that * method
is not implemented on Float.

Thank you.

On 10/6/07, Krishna K. [email protected] wrote:

How do we extend inbuilt classes. For example Float doesn’t have *
method implemented. I tried adding this method:

It’s not sufficient to add the method to the class definition. You also
have to force the method information to be initialized by updating the
file
Initializer.Generated.cs. As its name suggests, this file is
automatically
generated from the source code by running the “ClassInitGenerator”
program
– a batch file that does this is at Builtins\GenerateInitializers.cmd.

Unfortunately, the version of the source that’s checked into RubyForge
has a
bunch of broken paths for this purpose – at least when not using Visual
Studio. I tried to use msbuild directly to build
ClassInitGenerator.exe,
and found that I had to make the following edits for things to work
correctly:

utils\ironruby.classinitgenerator\ClassInitGenerator.csproj
add reference to …..\build\debug\Microsoft.Scripting.dll
add reference to …..\build\debug\Ruby.dll
fix the reference path for Microsoft.Scripting.csproj
fix the reference path for Ruby.csproj
src\ironruby\Ruby.csproj
fix the reference path for Microsoft.Scripting.csproj
src\ironruby\Builtins\GenerateInitializers.cmd
fix the path to ClassInitGenerator.exe

After making these changes, I ran GenerateInitializers.cmd and rebuilt
IronRuby using the Rakefile. Your change then worked:

F:\IronRuby>build\release\rbx.exe
IronRuby Pre-Alpha (1.0.0.0) on .NET 2.0.50727.312
Copyright (c) Microsoft Corporation. All rights reserved.

1.2 + 1.2
=> 2.4
1.2 * 1.2
=> 1.44

Curt,

Thank you for the reply. Looks like this is something that should be
commited. Can you commit your changes to the SVN repository so that
every one can get the changes? Thanks a lot.

On 10/7/07, Krishna K. [email protected] wrote:

Thank you for the reply. Looks like this is something that should be
commited. Can you commit your changes to the SVN repository so that
every one can get the changes? Thanks a lot.

I’m not sure what’s required to be able to do that; a patchfile with the
changes can be downloaded from
http://hagenlocher.org/software/classinitgen.patch.txt

Thanks for making the patch, Curt!

For folks on the outside, please use Curt’s patch until I get around to
fixing the Rakefile. I need to add some code to transform paths within
the .csproj files so that they recognize the difference in layouts
between our internal environment and the external subversion layout.

Thanks,
-John

I’m not sure what’s required to be able to do that; a patchfile with the
changes can be downloaded from
http://hagenlocher.org/software/classinitgen.patch.txt

Thanks for the patch.

Hi,

I’m playing with IronRuby and love it.
Playing around I obviously did something that’s not yet implemented and
got the exception “Common Language Runtime detected an invalid program”
The code is:
result = (Proc.new { |value| value.to_s*2 }).call value

I understand that IronRuby still has a way to go and that not
everything’s
fully implemented. However, I would expect another kind of exception…
something along “Ruby syntax error” or the like…

btw - it would be awesome to get a few pointers on the differences
between
the various methods/modes of execution (Exectue, ExecuteCommand etc)

cheers
Florian


Florian
Krüschhttp://www.planet-xaml.net

On 10/8/07, Florian Krüsch [email protected] wrote:

I’m playing with IronRuby and love it.
Playing around I obviously did something that’s not yet implemented and
got the exception “Common Language Runtime detected an invalid program”
The code is:
result = (Proc.new { |value| value.to_s*2 }).call value

This looks very much like a bug and not an unimplemented feature. The
error
message suggests that there’s some invalid IL being emitted. If you
split
the code into two lines
p = Proc.new{ |value| value.to_s*2}
result = p.call value
it works correctly.

You can submit this as a bug here:
http://rubyforge.org/tracker/?atid=16798&group_id=4359&func=browse

Hi,

I’m playing with IronRuby and love it.
Playing around I obviously did something that’s not yet implemented and
got the exception “Common Language Runtime detected an invalid program”
The code is:
result = (Proc.new { |value| value.to_s*2 }).call value

I understand that IronRuby still has a way to go and that not
everything’s
fully implemented. However, I would expect another kind of exception…
something along “Ruby syntax error” or the like…

btw - it would be awesome to get a few pointers on the differences
between
the various methods/modes of execution (Exectue, ExecuteCommand etc)

cheers
Florian


Florian
Krüschhttp://www.planet-xaml.net

This is a known bug (IL stack needs to be empty when entering
try-catch). All “invalid programs” exception are due to this bug.
The bug will take some time to fix. Until then, store values to locals
if you combine calls with a block with other calls.

Tomas