示例#1
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
                        }
                    }
                }
            }
        }
示例#2
0
 protected virtual void Dispose(bool disposing)
 {
     if (!m_disposed)
     {
         if (disposing)
         {
         }
         lua?.Dispose();
         m_disposed = true;
     }
 }
示例#3
0
 /// <summary>
 /// 销毁
 /// </summary>
 public void Dispose()
 {
     stop = true;   //停止待运行任务
     lua.Dispose(); //释放lua虚拟机
     foreach (var v in timerPool)
     {
         v.Value.Cancel(); //取消所有timer
     }
     timerPool.Clear();    //清空timer信息池子
     while (toRun.TryTake(out _))
     {
         ;                         //清空待运行池子
     }
 }