如何将 ExpandoObject 从 C# 传递到 IronRuby?
执行下面的代码在最后一行给出以下异常:
InvalidOperationException: "unbound variable: value"
var rubyRuntime = Ruby.CreateRuntime();
rubyRuntime.UseFile("HandleMoveRequested.rb");
var engine = rubyRuntime.GetEngine("rb");
dynamic ruby = engine.Runtime.Globals;
var handler = ruby.HandleMoveRequested.@new();
dynamic msg = new ExpandoObject();
msg.x = 1;
msg.y = 2;
handler.handle(msg);
HandleMoveRequested.rb 的内容是:
class HandleMoveRequested
def handle(msg)
System::Console.WriteLine msg.x
System::Console.WriteLine msg.y
end
end
基本上我只是希望能够传递一个完全动态的对象进入该 Ruby 对象的“handle”方法,并使其能够访问该对象上的“x”和“y”属性。我是不是找错了树?
Executing the below code gives me the following exception on the last line:
InvalidOperationException: "unbound variable: value"
var rubyRuntime = Ruby.CreateRuntime();
rubyRuntime.UseFile("HandleMoveRequested.rb");
var engine = rubyRuntime.GetEngine("rb");
dynamic ruby = engine.Runtime.Globals;
var handler = ruby.HandleMoveRequested.@new();
dynamic msg = new ExpandoObject();
msg.x = 1;
msg.y = 2;
handler.handle(msg);
The contents of HandleMoveRequested.rb are:
class HandleMoveRequested
def handle(msg)
System::Console.WriteLine msg.x
System::Console.WriteLine msg.y
end
end
Basically I just want to be able to pass a fully dynamic object into that Ruby object's "handle" method and have it be able to access the "x" and "y" properties on that object. Am I barking up the wrong tree?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在从源代码构建最新版本后,我测试了您的代码(按原样):
http://github.com/ironruby/ironruby
请尝试一下。我想该修复将包含在下一个 RC 版本(RC3?)及更高版本中。
当您从源代码构建时,确保使用 Ruby4.sln 构建“V4 Release”版本
编辑:我自己测试过,这在最新版本中没有问题
I tested your code (as-is) after building the latest from source:
http://github.com/ironruby/ironruby
Please try this. I'd imagine the fix will be included in the next RC Build (RC3?) and later.
When you build from source, make sure you build the "V4 Release" build using Ruby4.sln
Edit: Tested myself, this works without issue in latest