2

Using AluminumLua I have a lua file where I'm setting a function to a variable like below:

local Start = function() print("Inside Start!") end

In .NET I try to load this file but it just hangs on the parse method and never comes back from it.

class Program
{
    static void Main(string[] args)
    {
        var context = new LuaContext();

        context.AddBasicLibrary();
        context.AddIoLibrary();

        var parser = new LuaParser(context, "test.lua");

        parser.Parse();

    }
}

Any ideas why it's hanging?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
user441521
  • 6,942
  • 23
  • 88
  • 160

1 Answers1

2

I haven't tried AluminiumLua yet, But I've used LuaInterface many times. If you want your function to load on startup, Include or DoFile/DoString your file and run function like this:

local Start = function() print("Startup") end

Start()

If you're trying to define hooks from lua, You can use LuaInterface with KopiLua, then following this way:

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
111WARLOCK111
  • 857
  • 2
  • 7
  • 14