2013-10-20 42 views
2

使用AluminumLua我在那里我设置的功能给一个变量象下面这样的lua文件:AluminumLua定义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(); 

    } 
} 

任何想法,为什么它挂?

回答

2

我还没有试过AluminiumLua,但是我多次使用过LuaInterface。如果你希望你的函数,在启动时加载,包括或dofile处理/ DoString文件并运行功能是这样的:

地方开始=()函数打印(“启动”)结束

开始()

如果你想定义从LUA挂钩,您可以使用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