使用 AluminiumLua 我有一个 lua 文件,其中我将函数设置为变量,如下所示:
local Start = function() print("Inside Start!") end
在 .NET 中,我尝试加载此文件,但它只是卡在解析方法上并且永远不会从中返回。
class Program
{
static void Main(string[] args)
{
var context = new LuaContext();
context.AddBasicLibrary();
context.AddIoLibrary();
var parser = new LuaParser(context, "test.lua");
parser.Parse();
}
}
知道它为何挂起吗?
最佳答案
我还没有尝试过AluminiumLua,但是我已经使用过LuaInterface很多次了。如果您希望函数在启动时加载,请包含或 DoFile/DoString 您的文件并运行函数,如下所示:
本地 Start = function() print("Startup") end
开始()
如果您尝试从 lua 定义钩子(Hook),您可以将 LuaInterface 与 KopiLua 一起使用,然后按照以下方式操作:
C#:
static List<LuaFunction> hooks = new List<LuaFunction>();
// Register this void
public void HookIt(LuaFunction func)
{
hooks.Add(func);
}
public static void WhenEntityCreates(Entity ent)
{
// We want to delete entity If we're returning true as first arg on lua
// And hide it If second arg is true on lua
foreach (var run in hooks)
{
var obj = run.Call(ent);
if (obj.Length > 0)
{
if ((bool)obj[0] == true) ent.Remove();
if ((bool)obj[1] == true) ent.Hide();
}
}
}
lua:
function enthascreated(ent)
if ent.Name == "Chest" then
return true, true
elseif ent.Name == "Ninja" then
return false, true
end
return false, false
end
关于c# - AluminiumLua定义lua函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19480326/