private void CheckLuaScript()
        {
            if (expScript == null && !loc.Equals("") && !funcName.Equals(""))
            {
                try
                {
                    expScript = new NLua.Lua();
                    expScript.LoadCLRPackage();
                    expScript.DoFile(Game1.rootContent + loc);

                    bHasProperLua = expScript.GetFunction(funcName) != null;
                }
                catch (Exception e)
                {
                    bHasProperLua = false;
                    expScript     = null;
                    if (Game1.bIsDebug)
                    {
                        Console.WriteLine(e);
                        //throw e;
                    }
                }
            }
            else if (loc.Equals(""))
            {
                bHasProperLua = false;
                expScript     = null;
            }
            else if (!bHasProperLua)
            {
                expScript     = null;
                bHasProperLua = false;
            }
        }
예제 #2
0
 public CozyLuaFunction GetFunction(string fullPath)
 {
     NLua.LuaFunction func = mLua.GetFunction(fullPath);
     if (func != null)
     {
         return(new CozyLuaFunction(func));
     }
     return(null);
 }
예제 #3
0
        protected override void Initialized(object state)
        {
            base.Initialized(state);

            if (_ctx != null)
            {
                _ctx.Dispose();
            }

            _ctx = new NLua.Lua();
            _ctx.LoadCLRPackage();

            _ctx.RegisterFunction("AddCommand", this, this.GetType().GetMethod("AddCommand"));
            _ctx.RegisterFunction("ArraySort", this, this.GetType().GetMethod("ArraySort"));
            //_ctx.RegisterFunction("HookBase", this, this.GetType().GetMethods()
            //    .Where(x => x.Name == "HookBase" && x.GetParameters().Last().ParameterType == typeof(NLua.LuaFunction))
            //    .First());

            _ctx.DoFile(Path);

            CallSelf("Initialized");

            var plg = _ctx["export"] as NLua.LuaTable;

            if (plg != null)
            {
                this.TDSMBuild   = (int)(double)plg["TDSMBuild"];
                this.Author      = plg["Author"] as String;
                this.Description = plg["Description"] as String;
                this.Name        = plg["Name"] as String;
                this.Version     = plg["Version"] as String;

                IsValid = true;

                var hooks = plg["Hooks"] as NLua.LuaTable;
                if (hooks != null)
                {
                    foreach (KeyValuePair <Object, Object> hookTarget in hooks)
                    {
                        var hook      = hookTarget.Key as String;
                        var hookPoint = PluginManager.GetHookPoint(hook);

                        if (hookPoint != null)
                        {
                            var details  = hookTarget.Value as NLua.LuaTable;
                            var priority = (HookOrder)(details["Priority"] ?? HookOrder.NORMAL);
                            //var priority = FindOrder(details["Priority"] as String);

                            var del = _ctx.GetFunction(hookPoint.DelegateType, "export.Hooks." + hook + ".Call");
                            HookBase(hookPoint, priority, del); //TODO maybe fake an actual delegate as this is only used for registering or make a TDSM event info class
                        }
                    }
                }
            }
        }
예제 #4
0
 public void Call(ref HookContext ctx, ref object args, string function)
 {
     if (_ctx != null)
     {
         var fnc = _ctx.GetFunction("export.Hooks." + function + ".Call");
         if (fnc != null)
         {
             var res = fnc.Call(this, ctx, args);
             if (res != null && res.Length > 0)
             {
                 foreach (var x in res)
                 {
                     if (x is HookContext)
                     {
                         ctx = (HookContext)x;
                     }
                 }
             }
         }
     }
 }
예제 #5
0
 /// <summary>
 /// 执行lua脚本文件中的某个函数。
 /// </summary>
 /// <param name="FileName">脚本文件名</param>
 /// <param name="FunctionName">函数名</param>
 /// <param name="Parameters">函数参数</param>
 public void ExecuteFunction(string FileName, string FunctionName, params object[] Parameters)
 {
     if (!ExecutedFiles.Contains(FileName))
     {
         StreamReader SReader = new StreamReader(FileName, Encoding.UTF8);
         LuaState.DoString(SReader.ReadToEnd());
         SReader.Close();
         ExecutedFiles.Add(FileName);
     }
     try { LuaState.GetFunction(FunctionName).Call(Parameters); }
     catch (Exception ex) { throw new Exception("在" + FileName + "中发现异常:" + ex.Message); }
 }
        internal bool CheckScript()
        {
            if (scriptFunction.Equals(""))
            {
                return(false);
            }
            else if (!scriptLoc.Equals(""))
            {
                NLua.Lua state = new NLua.Lua();
                state.LoadCLRPackage();
                try
                {
                    state.DoFile(Game1.rootContent + scriptLoc);
                }
                catch (Exception)
                {
                    script = null;
                    return(false);
                }

                bool bIsCorrectScriptAndFunction = state.GetFunction(scriptFunction) != null;
                if (bIsCorrectScriptAndFunction)
                {
                    script = state;
                    if (!modFunctionName.Equals(""))
                    {
                        modFunction = state.GetFunction(modFunctionName);
                    }
                    else
                    {
                        modFunction = null;
                    }

                    return(true);
                }
                return(false);
            }
            return(false);
        }
예제 #7
0
 /// <summary>
 /// 跑一遍任务池子里的任务
 /// </summary>
 private void runTask()
 {
     lock (taskLock)
         while (toRun.Count > 0)
         {
             try
             {
                 LuaTaskData task;
                 toRun.TryTake(out task);                                             //取出来一个任务
                 lua.GetFunction("sys.tiggerCB").Call(task.id, task.type, task.data); //跑
             }
             catch (Exception e)
             {
                 ErrorEvent?.Invoke(lua, e.Message);
             }
             if (stop)//任务停了
             {
                 return;
             }
         }
 }
        public void CheckScript()
        {
            if (!functionName.Equals("") && levelUpScript == null && !scriptLoc.Equals("") || (bRecheckScript && !scriptLoc.Equals("")))
            {
                try
                {
                    levelUpScript = new NLua.Lua();
                    levelUpScript.LoadCLRPackage();
                    levelUpScript.DoFile(Game1.rootContent + scriptLoc);
                }
                catch (Exception e)
                {
                    levelUpScript = null;
                }
            }

            if (levelUpScript != null)
            {
                bHasProperScript = levelUpScript.GetFunction(functionName) != null;
            }
            bHasProperScript = levelUpScript != null;
        }
예제 #9
0
 internal void Execute(LuaTurnSetInfo ltsi)
 {
     if (state == null)
     {
         state = new NLua.Lua();
         state.LoadCLRPackage();
         if (fileNameLoc.StartsWith(@"\"))
         {
             fileNameLoc = fileNameLoc.Remove(0, 1);
         }
         String comp = System.IO.Path.Combine(TBAGW.Game1.rootContent, fileNameLoc);
         state.DoFile(comp);
     }
     if (state.GetFunction(functionName) != null)
     {
         if (bNoParameter)
         {
             (state[functionName] as NLua.LuaFunction).Call();
         }
         else
         if (!bNoParameter)
         {
             //var temp = ltsi.otherGroups[0].RandomMember();
             if (eventType == EventType.updateEV)
             {
                 (state[functionName] as NLua.LuaFunction).Call(ltsi, msTime);
             }
             else
             {
                 (state[functionName] as NLua.LuaFunction).Call(ltsi);
             }
         }
     }
     else
     {
         Console.WriteLine("Lua error from " + fileNameLoc + " , @function-name " + functionName);
         eventType = EventType.None;
     }
 }
예제 #10
0
 private void Run()
 {
     lock (_lock)
     {
         while (_holdingEvent.Count > 0)
         {
             try
             {
                 _holdingEvent.TryTake(out LuaStateEventData task);
                 lua.GetFunction("EventTrigger").Call(task.Type, task.Data);
             }
             catch (Exception e)
             {
                 Error(e);
             }
             if (m_disposed)
             {
                 return;
             }
         }
     }
 }
예제 #11
0
파일: Screen.cs 프로젝트: jascou/ROTNS
 public Screen(string ScriptName, string LoaderScript, NLua.Lua LuaInstance)
     : this()
 {
     LuaInstance.GetFunction(ScriptName).Call(this);
     _Loader = new LoadingScreen(LoaderScript, LuaInstance);
 }
예제 #12
0
파일: Screen.cs 프로젝트: jascou/ROTNS
 public Screen(string ScriptName, NLua.Lua LuaInstance)
     : this()
 {
     LuaInstance.GetFunction(ScriptName).Call(this);
 }
예제 #13
0
        public object[] CallMethod(string name, params object[] parameters)
        {
            var result = _lua.GetFunction(name).Call(parameters);

            return(result);
        }
예제 #14
0
 public LoadingScreen(string LoaderScript, NLua.Lua LuaInstance)
     : base()
 {
     LuaInstance.GetFunction(LoaderScript).Call(this);
 }