如何将Lua与.Net集成 [英] How to Integrate Lua with .Net
本文介绍了如何将Lua与.Net集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要求是用户应该能够在文本框中添加 Lua 脚本,然后我需要检查用户是否添加了正确的 Lua 脚本,如果脚本正确,那么我需要运行该脚本.谁能建议我一些代码?我尝试了以下操作:
Requirement is user should be able to add Lua script in text box, and then I need to check user has added proper Lua script and if script is correct then I need to run that script. Can anyone suggest me some code? I tried following:
using (Lua state = new Lua())
{
state.DoString(txt.Text);
var scriptFunc = state["ScriptFunc"] as LuaFunction;
var res = scriptFunc.Call(2,3);
Response.Write(res);
}
推荐答案
您正在寻找的是 Moon#
( http://www.moonsharp.org/).因此,您的示例将如下所示:
What you are looking for is Moon#
(http://www.moonsharp.org/). So your example will look like this:
double MoonSharpFactorial2()
{
string scriptCode = @"
-- defines a factorial function
function fact (n)
if (n == 0) then
return 1
else
return n*fact(n - 1)
end
end";
Script script = new Script();
script.DoString(scriptCode);
DynValue res = script.Call(script.Globals["fact"], 4);
return res.Number;
}
这篇关于如何将Lua与.Net集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文