This project is read-only.

calling IronPython function from IronRuby

Jun 23, 2010 at 7:13 AM

I'm able to call an IronRuby function from IronPython but not the other way around. My IronPython function looks like this:

def myadd(x, y): return x + y

In the IronRuby code, if I do 'puts myadd', it prints 'IronPython.Runtime.PythonFunction', which is as expected. However, in the IronRuby code, if I do 'myadd(2, 3)', I get an ArgumentException. The error message is "wrong number of arguments (2 for 0)". And the stack trace is this: 

at Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   at IronRuby.Runtime.RubyScriptCode.Run(Scope scope, Boolean bindGlobals)
   at IronRuby.Runtime.RubyScriptCode.Run(Scope scope)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope)
   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
Does anyone know why the exception? Thanks!


Jun 23, 2010 at 5:26 PM
IpronPython functions are first-class objects, something like Procs in Ruby. You need to use "call" method to call them: puts,2)