Search code examples
c#luaintegrationluainterface

mapping C# classes to LUA functions using LuaInterface


Is there a way to map classes directly to C# functions by just loading the class? Instead of making 100+ RegisterFunctions and mapping them?

EX: Something like

this.lua = new LuaInterface.Lua();
RegisterAll(Class1.MainClass);
lua.DoFile(this.filePath);

inside lua:

function Start
    MainClass.MappedPrintFunc("hihi");
end

Solution

  • You can do so by setting a variable in LUA to your function that exports funcs or props.

    EX:

    Class Manager()
    public static GameLocalPlayer LocalPlayer { get; set; }
    
    LuaInterace lua = new LuaInterface;
    lua["variablename"]=Manager.LocalPlayer;  
    
    ---lua----
    variablename.Health;
    variablename:AttackTarget(target);