Beispiel #1
0
        private DynValue Call(string methodName, params object[] args)
        {
            var list = new List <object>();

            list.Add(Instance);
            list.AddRange(args);
            return(_luaHelper.Call(Instance, methodName, list.ToArray()));
        }
        public T Call <T>(string methodName, params object[] args)
        {
            var list = new List <object> {
                Instance
            };

            list.AddRange(args);
            return(_luaHelper.Call(Instance, methodName, list.ToArray()).ToObject <T>());
        }
Beispiel #3
0
        public void AddModuleFromLuaFile(string fileName, string entry, string moduleName = "", string libPath = "./?;./?.lua;./Lua/?;./Lua/?.lua")
        {
            var luaHelper = new LuaHelper();

            LuaGlobals.Init();

            luaHelper.SetSearchPath(libPath);
            luaHelper.RegisterGlobal(nameof(LuaHelper), luaHelper);

            var table = luaHelper.Execute(fileName)?.Table;

            if (table == null)
            {
                return;
            }

            var module = luaHelper.Call(table, nameof(Entry.Main)).Table;

            if (module == null)
            {
                throw new Exception($"{nameof(module)}为空!");
            }

            var dynValue = module.Get(nameof(IModule));

            if (dynValue == null || dynValue == DynValue.Nil)
            {
                throw new Exception($"未找到{nameof(IModule)}!");
            }

            var luaModule = dynValue.ToObject <IModule>();

            if (luaModule == null)
            {
                throw new Exception($"转换{nameof(IModule)}失败!");
            }

            luaModule.ModuleName = moduleName;

            AddModule(luaModule);
        }