【发布时间】:2010-05-27 13:05:09
【问题描述】:
我想在我的 .NET 项目中使用 IronRuby 作为脚本语言(例如 Lua)。 例如,我希望能够从 Ruby 脚本订阅特定事件,在宿主应用程序中触发,并从中调用 Ruby 方法。
我正在使用这段代码来实例化 IronRuby 引擎:
Dim engine = Ruby.CreateEngine()
Dim source = engine.CreateScriptSourceFromFile("index.rb").Compile()
' Execute it
source.Execute()
假设 index.rb 包含:
subscribe("ButtonClick", handler)
def handler
puts "Hello there"
end
我该怎么做:
- 让 C# 方法 Subscribe(在宿主应用程序中定义)在 index.rb 中可见?
- 稍后从宿主应用程序调用 handler 方法?
【问题讨论】:
标签: c# .net ruby ironruby scripting-interface