Benjamin van der Veen
2008-Nov-16 01:56 UTC
[Ironruby-core] ScriptScope.SetVariable - pass in a function
Hi,
I''d like do something like this:
public void AddFunction() {
aScriptScope.SetVariable("my_function",
(Action<string>)MyFunction);
}
public void MyFunction(string value) {
// do stuff!
}
Currently if I execute a script like "my_function
''hello!''" or
"my_function(''hello!'')" I get:
ArgumentException: wrong number or type of arguments for `my_function''
Ideas? If I can, I''d like to declare the class which contains these
methods ''internal''.
Thanks so much!
benjamin
--
Posted via http://www.ruby-forum.com/.
Tomas Matousek
2008-Nov-16 02:10 UTC
[Ironruby-core] ScriptScope.SetVariable - pass in a function
Try my_function.invoke(''hello!''). Ruby doesn''t have
first class methods.
For convenience we can monkey-patch Delegate to mimic procs (add [], call
methods).
Tomas
-----Original Message-----
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at
rubyforge.org] On Behalf Of Benjamin van der Veen
Sent: Saturday, November 15, 2008 5:56 PM
To: ironruby-core at rubyforge.org
Subject: [Ironruby-core] ScriptScope.SetVariable - pass in a function
Hi,
I''d like do something like this:
public void AddFunction() {
aScriptScope.SetVariable("my_function",
(Action<string>)MyFunction);
}
public void MyFunction(string value) {
// do stuff!
}
Currently if I execute a script like "my_function
''hello!''" or
"my_function(''hello!'')" I get:
ArgumentException: wrong number or type of arguments for `my_function''
Ideas? If I can, I''d like to declare the class which contains these
methods ''internal''.
Thanks so much!
benjamin
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ironruby-core mailing list
Ironruby-core at rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
Jim Deville
2008-Nov-16 05:47 UTC
[Ironruby-core] ScriptScope.SetVariable - pass in a function
Correction: Methods are first-class, they just can''t be invoked from
their objects with ().
JD
-----Original Message-----
From: Tomas Matousek <Tomas.Matousek at microsoft.com>
Sent: November 15, 2008 6:11 PM
To: ironruby-core at rubyforge.org <ironruby-core at rubyforge.org>
Subject: Re: [Ironruby-core] ScriptScope.SetVariable - pass in a function
Try my_function.invoke(''hello!''). Ruby doesn''t have
first class methods.
For convenience we can monkey-patch Delegate to mimic procs (add [], call
methods).
Tomas
-----Original Message-----
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at
rubyforge.org] On Behalf Of Benjamin van der Veen
Sent: Saturday, November 15, 2008 5:56 PM
To: ironruby-core at rubyforge.org
Subject: [Ironruby-core] ScriptScope.SetVariable - pass in a function
Hi,
I''d like do something like this:
public void AddFunction() {
aScriptScope.SetVariable("my_function",
(Action<string>)MyFunction);
}
public void MyFunction(string value) {
// do stuff!
}
Currently if I execute a script like "my_function
''hello!''" or
"my_function(''hello!'')" I get:
ArgumentException: wrong number or type of arguments for `my_function''
Ideas? If I can, I''d like to declare the class which contains these
methods ''internal''.
Thanks so much!
benjamin
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ironruby-core mailing list
Ironruby-core at rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core
_______________________________________________
Ironruby-core mailing list
Ironruby-core at rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core