Esempio n. 1
0
            public static ScriptPkg CreateLua(object attvalue)
            {
                ScriptPkg pkg = null;

                if (KObjectPool.mIns != null)
                {
                    pkg = KObjectPool.mIns.Pop <ScriptPkg>();
                }

                if (pkg == null)
                {
                    pkg = new ScriptPkg();
                }

                pkg._script = new LuaScriptLoader();
                if (LuaClient.Instance != null)
                {
                    SimpleParams             InitParams   = SimpleParams.Create(1);
                    Script_LuaLogicAttribute luaAttribute = attvalue as Script_LuaLogicAttribute;
                    InitParams.WriteObject(luaAttribute);
                    pkg.Name = luaAttribute.luapath;
                    pkg.Loader.Init(InitParams);
                }
                else
                {
                    LogMgr.Log("场景中未包含LuaClient,但是程序集中包含了带有lua目标的函数的注册");
                }


                return(pkg);
            }
Esempio n. 2
0
        private void RegisterLua(ScriptCommand cmd, string path, string methodname)
        {
#if TOLUA
            Script_LuaLogicAttribute att = new Script_LuaLogicAttribute(cmd.CMD, path, methodname);
            ScriptPkg pkg = ScriptPkg.CreateLua(att);
            //add
            var dic = new SimpleDictionary <int, ScriptPkg>();
            dic.Add((int)cmd.target, pkg);
            ScriptDic[cmd.CMD] = dic;
#endif
        }
Esempio n. 3
0
        void TryInit(Script_LuaLogicAttribute att)
        {
#if TOLUA
            if (inited)
            {
                return;
            }

            if (att != null)
            {
                this.luafilepath = att.luapath;
                this.methodname  = att.methodName;
                this.Luatable    = TryGetClassLuaFunction(att.luapath);
                if (this.Luatable == null)
                {
                    object[] retObj = LuaClient.GetMainState().DoFile(att.luapath.ToLower());

                    if (retObj != null && retObj.Length > 0)
                    {
                        LuaTable table = retObj[0] as LuaTable;
                        if (table != null)
                        {
                            classFuncDictionary[att.luapath] = new WeakReference(table);
                            this.Luatable = table;
                            this.luafunc  = table[methodname] as LuaFunction;
                        }
                        else
                        {
                            LogMgr.LogErrorFormat("类型不匹配 :{0}", retObj[0]);
                        }
                    }
                    else
                    {
                        this.luafunc = LuaClient.GetMainState().GetFunction(methodname);
                    }
                }
                else
                {
                    this.luafunc = this.Luatable.GetLuaFunction(att.methodName);
                }
            }

            inited = true;
#endif
        }
Esempio n. 4
0
        public void Init(AbstractParams InitParams)
        {
#if TOLUA
            attribute = InitParams.ReadObject() as Script_LuaLogicAttribute;
#endif
        }