Inheritance: LuaBaseRef
Example #1
0
    static void Init()
    {
        new LuaFileUtils();

        _state = new LuaState();

        _state.OpenLibs(LuaDLL.luaopen_protobuf_c);
        _state.OpenLibs(LuaDLL.luaopen_struct);

#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
        _state.OpenLibs(LuaDLL.luaopen_bit);
#endif
        _state.LuaSetTop(0);

        LuaBinder.Bind(_state);

        _state.Start();
        _state.AddSearchPath(Application.dataPath + "/LuaSupport");

        _state.DoFile("Main.lua");


        _callMethod       = _state.GetFunction("Class.CallMethod");
        _hasMethod        = _state.GetFunction("Class.HasMethod");
        _decodeRecvMethod = _state.GetFunction("Network.DecodeRecv");

        LuaFunction func = _state.GetFunction("Main");
        func.Call();
        func.Dispose();
        func = null;
    }
        public int Button(
            int formHandle,
            string caption,
            LuaFunction clickEvent,
            int? x = null,
            int? y = null,
            int? width = null,
            int? height = null)
        {
            var form = GetForm(formHandle);
            if (form == null)
            {
                return 0;
            }

            var button = new LuaButton();
            SetText(button, caption);
            form.Controls.Add(button);
            form.ControlEvents.Add(new LuaWinform.LuaEvent(button.Handle, clickEvent));

            if (x.HasValue && y.HasValue)
            {
                SetLocation(button, x.Value, y.Value);
            }

            if (width.HasValue && height.HasValue)
            {
                SetSize(button, width.Value, height.Value);
            }

            return (int)button.Handle;
        }
Example #3
0
        private static void LuaStart()
        {
            lua.Require("GameStart");

            LuaInterface.LuaFunction func = lua.GetFunction("Start");
            CallFunc_VX(func);
        }
Example #4
0
 /// <summary>
 /// 添加单击事件
 /// </summary>
 public void AddClick(GameObject go, LuaFunction luafunc) {
     if (go == null) return;
     UIEventListener.Get(go).onClick = delegate(GameObject o) {
         luafunc.Call(go);
         buttons.Add(luafunc);
     };
 }
Example #5
0
        public void Dispose(bool disposeManagedResources)
        {
            if (!beDisposed)
            {
                beDisposed = true;

                //if (_call != null)
                //{
                //    _call.Dispose(disposeManagedResources);
                //    _call = null;
                //}

                if (_add != null)
                {
                    _add.Dispose(disposeManagedResources);
                    _add = null;
                }

                if (_remove != null)
                {
                    _remove.Dispose(disposeManagedResources);
                    _remove = null;
                }

                if (self != null)
                {
                    self.Dispose(disposeManagedResources);
                }

                Clear();
            }
        }
    public void Request(string route, LuaInterface.LuaTable paramsTable, LuaInterface.LuaFunction func)
    {
        if (pc != null)
        {
            JsonObject msg = new JsonObject();
            IEnumerator <DictionaryEntry> paramList = paramsTable.ToDictTable().GetEnumerator();
            while (paramList.MoveNext())
            {
                DictionaryEntry curr = paramList.Current;
                Debug.Log("key " + curr.Key + " value: " + curr.Value);
                msg[curr.Key.ToString()] = curr.Value;
            }

            pc.request(route, msg, (result) =>
            {
                PomeloPackage pkg = new PomeloPackage();
                if (func == null)
                {
                    Debug.LogError("callback function is null!");
                }

                pkg.luaFunc    = func;
                pkg.ReturnData = result.ToString();
                AddResultPackage(pkg);
            });
        }
        else
        {
            Debug.LogError("Pomelo Client is null");
        }
    }
    void Start()
    {
        #if !TEST_GC
        #if UNITY_5
        Application.logMessageReceived += ShowTips;
        #else
        Application.RegisterLogCallback(ShowTips);
        #endif
        #endif
        lua = new LuaState();
        lua.Start();
        lua.DoString(script);

        //Get the function object
        func = lua.GetFunction("test.luaFunc");

        if (func != null)
        {
            //有gc alloc
            object[] r = func.Call(123456);
            Debugger.Log("generic call return: {0}", r[0]);

            // no gc alloc
            int num = CallFunc();
            Debugger.Log("expansion call return: {0}", num);
        }

        lua.CheckTop();
    }
Example #8
0
 /*
  * Calls the provided function with the provided parameters
  */
 public static object callFunction(LuaFunction function,object[] args,Type[] returnTypes,object[] inArgs,int[] outArgs)
 {
     // args is the return array of arguments, inArgs is the actual array
     // of arguments passed to the function (with in parameters only), outArgs
     // has the positions of out parameters
     object returnValue;
     int iRefArgs;
     object[] returnValues=function.call(inArgs,returnTypes);
     if(returnTypes[0] == typeof(void))
     {
         returnValue=null;
         iRefArgs=0;
     }
     else
     {
         returnValue=returnValues[0];
         iRefArgs=1;
     }
     for(int i=0;i<outArgs.Length;i++)
     {
         args[outArgs[i]]=returnValues[iRefArgs];
         iRefArgs++;
     }
     return returnValue;
 }
Example #9
0
    // UniLua.ILuaState uniLua = LuaAPI.NewState();
    // NLua.Lua nlua = new NLua.Lua();

    // Use this for initialization
    void Start()
    {
        // GameObject labelas = GameObject.Find ("Label1");
        GameObject label1 = this.transform.FindChild("Label1").gameObject;

        label1.AddComponent <TestClick>();

        UIEventListener com = this.transform.FindChild("Label4").GetComponent <UIEventListener> ();

        com.onClick = OnClick;

        uLua.RegisterLuaDelegateType(typeof(UIEventListener.VoidDelegate), typeof(LuaEventArgsHandler));


        object[] aa = uLua.DoFile("TestLua");

        LuaInterface.LuaFunction fun = uLua.GetFunction("TB.TB1.Start");
        uLua.callFunction(fun, new object[] { this.gameObject });

        // uniLua.L_OpenLibs();

        // var status = uniLua.L_DoFile("TestUniLua.lua");
        // if( status != ThreadStatus.LUA_OK )
        // {
        //  Debug.Log(uniLua.ToString(-1));
        // }


        // TextAsset file = Resources.Load<TextAsset>("TestNLua");
        // object[] aa1 = nlua.DoString(file.text, "TestNLua");
        // NLua.LuaFunction fun1 = nlua.GetFunction ("TB.TB1.Start");
        // nlua.CallFunction (fun1, new object[]{this.gameObject});
    }
Example #10
0
    public virtual void Destroy()
    {
        if (luaState != null)
        {
        #if UNITY_5_4_OR_NEWER
        SceneManager.sceneLoaded -= OnSceneLoaded;
        #endif
            LuaState state = luaState;
            luaState = null;

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

            if (loop != null)
            {
                loop.Destroy();
                loop = null;
            }

            state.Dispose();
            Instance = null;
        }
    }
Example #11
0
    public override void OnDistanceChanged(float dt)
    {
        if (_CamCtrlMode == CTRL_MODE.FIX25D)
        {
            return;
        }

        _IsModeChangeRecover = false;
        _IsSkillRecover      = false;
        _IsMoveToDest        = false;

        float dist = _DistOffset + dt * CamConfig.CamRollSensitivity;

        if (!InputManager.Instance.IsMultiDragingStarted && dist < CamConfig.CamMinOffsetDist && Mathf.Abs(dt) >= 0.25f)
        {
            if (_Enter_Near_Cam_Lua_Func == null)
            {
                _Enter_Near_Cam_Lua_Func = LuaScriptMgr.Instance.GetLuaFunction("TryEnterNearCam");
            }

            if (_Enter_Near_Cam_Lua_Func != null)
            {
                _Enter_Near_Cam_Lua_Func.Call();    //尝试进入近景模式
                return;
            }
        }

        _IsDistChangeByForce = true;
        _DistOffset          = _DistOffsetDest = Mathf.Clamp(dist, CamConfig.CamMinOffsetDist, _CurMaxDistOffset);
        _CurHeightOffset     = GetHeightOffsetByDistOffset(_DistOffset);
    }
Example #12
0
    static int GetLuaFunction(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        Type[] types0 = { typeof(IntPtr), typeof(int) };
        Type[] types1 = { typeof(LuaScriptMgr), typeof(string) };

        if (count == 2 && LuaScriptMgr.CheckTypes(L, types0, 1))
        {
            IntPtr arg0 = (IntPtr)LuaScriptMgr.GetNumber(L, 1);
            int    arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
            LuaInterface.LuaFunction o = LuaScriptMgr.GetLuaFunction(arg0, arg1);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 2 && LuaScriptMgr.CheckTypes(L, types1, 1))
        {
            LuaScriptMgr             obj  = LuaScriptMgr.GetNetObject <LuaScriptMgr>(L, 1);
            string                   arg0 = LuaScriptMgr.GetString(L, 2);
            LuaInterface.LuaFunction o    = obj.GetLuaFunction(arg0);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: LuaScriptMgr.GetLuaFunction");
        }

        return(0);
    }
    public static Delegate CreateDelegate(Type t, LuaFunction func, LuaTable self)
    {
        DelegateValue Create = null;

        if (!dict.TryGetValue(t, out Create))
        {
            throw new LuaException(string.Format("Delegate {0} not register", LuaMisc.GetTypeName(t)));
        }

        if (func != null)
        {
            LuaState state = func.GetLuaState();
            LuaDelegate target = state.GetLuaDelegate(func, self);

            if (target != null)
            {
                return Delegate.CreateDelegate(t, target, target.method);
            }
            else
            {
                Delegate d = Create(func, self, true);
                target = d.Target as LuaDelegate;
                state.AddLuaDelegate(target, func, self);
                return d;
            }
        }

        return Create(func, self, true);
    }
Example #14
0
 /// <summary>
 /// 添加lua单机事件
 /// </summary>
 public static void AddClick(GameObject go, System.Object luafuc)
 {
     UIEventListener.Get(go).onClick += delegate(GameObject o) {
         LuaInterface.LuaFunction func = (LuaInterface.LuaFunction)luafuc;
         func.Call();
     };
 }
Example #15
0
    private void SetAwards(Dictionary <uint, uint> awards)
    {
        while (_bonus_grid.transform.childCount > 0)
        {
            NGUITools.Destroy(_bonus_grid.transform.GetChild(0).gameObject);
        }
        if (awards.Count <= 0)
        {
            return;
        }
        foreach (KeyValuePair <uint, uint> award in awards)
        {
            GameObject   item   = GameSystem.Instance.mClient.mUIManager.CreateUI("Prefab/GUI/GoodsIconConsume", _bonus_grid.transform);
            LuaComponent luacom = item.GetComponent <LuaComponent>();
            //UIAtlas _atlas = ResourceLoadManager.Instance.GetResources("Atlas/icon/iconGoods") as UIAtlas;
            //UISprite sprite = item.transform.FindChild("Icon").GetComponent<UISprite>();
            //sprite.atlas = _atlas;
            //string spriteName = string.Empty;
            //if (award.Key == GlobalConst.DIAMOND_ID)
            //    sprite.spriteName = "com_property_diamond2";
            //else if (award.Key == GlobalConst.GOLD_ID)
            //    sprite.spriteName = "com_property_gold2";
            //else if (award.Key == GlobalConst.TEAM_EXP_ID)
            //    sprite.spriteName = "com_property_exp";

            //sprite.spriteName += "_edged";
            LuaInterface.LuaFunction func = luacom.table["SetData"] as LuaInterface.LuaFunction;
            func.Call(new object[] { luacom.table, (int)(award.Key), (int)(award.Value), false });
            //item.GetComponentInChildren<UISprite>().spriteName = sprite.spriteName;
            item.GetComponentInChildren <UISprite>().depth = 10;
            //item.GetComponentInChildren<UILabel>().text = "+" + award.Value;
            item.GetComponentInChildren <UILabel>().depth = 10;
        }
        _bonus_grid.Reposition();
    }
 public Delegate Add(LuaFunction function)
 {
     Delegate handler = CodeGeneration.Instance.GetDelegate(this.eventInfo.EventHandlerType, function);
     this.eventInfo.AddEventHandler(this.target, handler);
     this.pendingEvents.Add(handler, this);
     return handler;
 }
    void Start()
    {
        lua = new LuaState();
        lua.Start();
        lua.DoString(script, "AccessingArray.cs");

        int[] array = { 1, 2, 3, 4, 5};
        func = lua.GetFunction("TestArray");

        func.BeginPCall();
        func.Push(array);
        func.PCall();
        double arg1 = func.CheckNumber();
        string arg2 = func.CheckString();
        bool arg3 = func.CheckBoolean();
        Debugger.Log("return is {0} {1} {2}", arg1, arg2, arg3);
        func.EndPCall();

        //转换一下类型,避免可变参数拆成多个参数传递
        object[] objs = func.Call((object)array);

        if (objs != null)
        {
            Debugger.Log("return is {0} {1} {2}", objs[0], objs[1], objs[2]);
        }

        lua.CheckTop();
    }
Example #18
0
    public static KeyValuePair <bool, object> InjectMethod(string name, params object[] args)
    {
        if (notHave.ContainsKey(name))
        {
            return(notHaveFix);
        }
        DynamicScript.lua.DoFile("hotFix");
        string selectFName = name;

        if (DynamicScript.lua.IsFuncExists(selectFName))
        {
            LuaInterface.LuaFunction selectF = DynamicScript.lua.GetLuaFunction(selectFName);
            object[] result = selectF.Call(args);
            object   ret    = null;
            if (result != null && result.Length > 0)
            {
                ret = (object)result[0];
            }
            return(new KeyValuePair <bool, object>(true, ret));
        }
        else
        {
            notHave.Add(name, true);
        }
        return(notHaveFix);
    }
        IEnumerator OnCreatePanel(string name, LuaFunction func = null)
        {
            yield return StartCoroutine(Initialize());

            string assetName = name + "Panel";
            // Load asset from assetBundle.
            string abName = name.ToLower() + AppConst.ExtName;
            AssetBundleAssetOperation request = ResourceManager.LoadAssetAsync(abName, assetName, typeof(GameObject));
            if (request == null) yield break;
            yield return StartCoroutine(request);

            // Get the asset.
            GameObject prefab = request.GetAsset<GameObject>();

            if (Parent.FindChild(name) != null || prefab == null) {
                yield break;
            }
            GameObject go = Instantiate(prefab) as GameObject;
            go.name = assetName;
            go.layer = LayerMask.NameToLayer("Default");
            go.transform.SetParent(Parent);
            go.transform.localScale = Vector3.one;
            go.transform.localPosition = Vector3.zero;
            go.AddComponent<LuaBehaviour>();

            if (func != null) func.Call(go);
            Debug.LogWarning("CreatePanel::>> " + name + " " + prefab);
        }
Example #20
0
        /// <summary>
        /// ������壬������Դ������
        /// </summary>
        /// <param name="type"></param>
        public void CreatePanel(string name, LuaFunction func = null)
        {
            string assetName = name + "Panel";
            string abName = name.ToLower() + AppConst.ExtName;

            ResManager.LoadPrefab(abName, assetName, delegate(UnityEngine.Object[] objs) {
                if (objs.Length == 0) return;
                // Get the asset.
                GameObject prefab = objs[0] as GameObject;

                if (Parent.FindChild(name) != null || prefab == null) {
                    return;
                }
                GameObject go = Instantiate(prefab) as GameObject;
                go.name = assetName;
                go.layer = LayerMask.NameToLayer("Default");
                go.transform.SetParent(Parent);
                go.transform.localScale = Vector3.one;
                go.transform.localPosition = Vector3.zero;
                go.AddComponent<LuaBehaviour>();

                if (func != null) func.Call(go);
                Debug.LogWarning("CreatePanel::>> " + name + " " + prefab);
            });
        }
Example #21
0
	public static Delegate UnityEngine_Events_UnityAction(LuaFunction func)
	{
		UnityEngine.Events.UnityAction d = () =>
		{
			func.Call();
		};
		return d;
	}
Example #22
0
    public static void AddSpineEvent(GameObject go, LuaInterface.LuaFunction func)
    {
        SkeletonGraphic com = go.GetComponent <SkeletonGraphic>();

        com.AnimationState.Complete += delegate {
            func.Call();
        };
    }
 public static Delegate Action(LuaFunction func)
 {
     Action d = () =>
     {
         func.Call();
     };
     return d;
 }
Example #24
0
 public static STimer CreateTimer(int end, LuaFunction funct)
 {
     STimer newTimer = new STimer();
     newTimer.currentTime = 0;
     newTimer.endTime = end;
     newTimer.funct = funct;
     return newTimer;
 }
Example #25
0
 private void SafeRelease(ref LuaFunction func)
 {
     if (func != null)
     {
         func.Dispose();
         func = null;
     }
 }
Example #26
0
    void OnDestroy()
    {
        func.Dispose();
        func = null;

        state.Dispose();
        state = null;
    }
Example #27
0
 public static void add(string name, string uni, LuaFunction funct)
 {
     if (!table.ContainsKey(name))
     {
         table.Add(name, new Dictionary<string, LuaFunction>());
     }
     table[name].Add(uni, funct);
 }
Example #28
0
 void Clear()
 {
     //_call = null;
     _add = null;
     _remove = null;
     self = null;            
     luaState = null;
 }
Example #29
0
 public void InitLua()
 {
     LuaScriptMgr.Instance.DoFile(PathMod.LuaUI + this.gameObject.name);
     m_AwakeFunc = GetLuaFunction("Awake");
     m_UpdateFunc = GetLuaFunction("Update");
     m_LateUpdateFunc = GetLuaFunction("LateUpdate");
     m_FixedUpdateFunc = GetLuaFunction("FixedUpdate");
     m_LevelLoaded = GetLuaFunction("OnLevelLoaded");
 }
Example #30
0
	void Start () 
    {
        state = new LuaState();
        state.Start();
        LuaBinder.Bind(state);
        state.DoString(script);

        func = state.GetFunction("TestPick");
	}
Example #31
0
 /// <summary>
 /// 添加单击事件
 /// </summary>
 public void AddClick(GameObject go, LuaFunction luafunc) {
     if (go == null) return;
     buttons.Add(luafunc);
     go.GetComponent<Button>().onClick.AddListener(
         delegate() {
             luafunc.Call(go);
         }
     );
 }
 /// <summary>
 /// 添加单击事件
 /// </summary>
 public void AddClick(string button, LuaFunction luafunc) {
     Transform to = trans.Find(button);
     if (to == null) return;
     GameObject go = to.gameObject;
     UIEventListener.Get(go).onClick = delegate(GameObject o) {
         luafunc.Call(go);
         buttons.Add(luafunc);
     };
 }
Example #33
0
    public void GetUIPrefab(string assetName, Transform parent, LuaTable luaTable, LuaFunction luaCallBack)
    {
        if (mResManager == null) return;

        string tmpAssetName = assetName;
        if (GameSetting.DevelopMode)
        {
            tmpAssetName = "UIPrefab/" + assetName;
        }
        mResManager.LoadPrefab(assetName + GameSetting.ExtName, tmpAssetName, delegate(UnityEngine.Object[] objs)
        {
            if (objs.Length == 0) return;
            GameObject prefab = objs[0] as GameObject;
            if (prefab == null)
            {
                return;
            }
            GameObject go = UnityEngine.GameObject.Instantiate(prefab) as GameObject;
            go.name = assetName;
            go.layer = LayerMask.NameToLayer("UI");

            Vector3 anchorPos = Vector3.zero;
            Vector2 sizeDel = Vector2.zero;
            Vector3 scale = Vector3.one;

            RectTransform rtTr = go.GetComponent<RectTransform>();
            if (rtTr != null)
            {
                anchorPos = rtTr.anchoredPosition;
                sizeDel = rtTr.sizeDelta;
                scale = rtTr.localScale;
            }

            go.transform.SetParent(parent, false);

            if (rtTr != null)
            {
                rtTr.anchoredPosition = anchorPos;
                rtTr.sizeDelta = sizeDel;
                rtTr.localScale = scale;
            }

            LuaBehaviour tmpBehaviour = go.AddComponent<LuaBehaviour>();
            tmpBehaviour.Init(luaTable);

            if (luaCallBack != null)
            {
                luaCallBack.BeginPCall();
                luaCallBack.Push(go);
                luaCallBack.PCall();
                luaCallBack.EndPCall();
            }
            Debug.Log("CreatePanel::>> " + assetName + " " + prefab);
            //mUIList.Add(go);
        });
    }
Example #34
0
 /// <summary>
 /// pbc/pblua函数回调
 /// </summary>
 /// <param name="func"></param>
 public static void OnCallLuaFunc(LuaStringBuffer data, LuaFunction func) {
     byte[] buffer = data.buffer;
     if (func != null) {
         LuaScriptMgr mgr = AppFacade.Instance.GetManager<LuaScriptMgr>(ManagerName.Lua);
         int oldTop = func.BeginPCall();
         LuaDLL.lua_pushlstring(mgr.lua.L, buffer, buffer.Length);
         if (func.PCall(oldTop, 1)) func.EndPCall(oldTop);
     }
     Debug.LogWarning("OnCallLuaFunc buffer:>>" + buffer + " lenght:>>" + buffer.Length);
 }
Example #35
0
        public GUIAddon(string a_filePath)
        {
            m_lua = new Lua();
            ((GameState)Game.getInstance().getCurrentState()).getGUI().registerFunctions(m_lua);
            m_lua.DoFile(a_filePath);

            m_onLoad = m_lua.GetFunction("OnLoad");
            m_onUpdate = m_lua.GetFunction("OnUpdate");
            m_onDraw = m_lua.GetFunction("OnDraw");
        }
Example #36
0
        //LuaFunction _call = null;

        public LuaEvent(LuaTable table)            
        {
            self = table;
            luaState = table.GetLuaState();
            self.AddRef();

            _add = self.RawGetLuaFunction("Add");
            _remove = self.RawGetLuaFunction("Remove");
            //_call = self.RawGetLuaFunction("__call");            
        }
Example #37
0
    static int GetFunction(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        IntPtr arg0 = (IntPtr)LuaScriptMgr.GetNumber(L, 1);
        int    arg1 = (int)LuaScriptMgr.GetNumber(L, 2);

        LuaInterface.LuaFunction o = LuaScriptMgr.GetFunction(arg0, arg1);
        LuaScriptMgr.Push(L, o);
        return(1);
    }
Example #38
0
        public static void RemoveHook(string _Event, LuaFunction _Function)
        {
            if (Events.ContainsKey(_Event.ToString()))
            {
                Events[_Event.ToString()].Remove(_Function);
            }

            if (debugHooks)
                Console.WriteLine("[LuaManager] Removed hook: " + _Event);
        }
Example #39
0
 private void InitNetClient()
 {
     m_client = new NetClient(Channel.Normal, new NetReader(), new NetSender());
     m_client.eventSendFailed     += SendFailed;
     m_client.eventConnectFailed  += ConnectFailed;
     m_client.eventConnectTimeOut += ConnectTimeOut;
     m_client.eventConnectClose   += ConnectClose;
     m_client.eventConnectSucceed += ConnectSucceed;
     readFunc = LuaManager.instance.Lua.GetFunction("Network.OnRead");
 }
Example #40
0
    void Start()
    {
        new LuaResLoader();
        state = new LuaState();
        state.Start();
        LuaBinder.Bind(state);
        state.DoString(script, "TestOutArg.cs");

        func = state.GetFunction("TestPick");
    }
Example #41
0
 public void Receive_lua_fun(string path, LuaInterface.LuaFunction onReceiveAction, LuaInterface.LuaFunction onErrorAction)
 {
     if (onReceiveAction != null)
     {
         m_SocketRequest_Lua_Map[path] = onReceiveAction;
     }
     if (onErrorAction != null)
     {
         m_SocketRequestError_Lua_Map[path] = onErrorAction;
     }
 }
Example #42
0
    public static Delegate CreateDelegate(Type t, LuaFunction func = null)
    {
        DelegateValue create = null;

        if (!dict.TryGetValue(t, out create))
        {
            throw new LuaException(string.Format("Delegate {0} not register", LuaMisc.GetTypeName(t)));
        }

        return create(func);
    }
Example #43
0
	public static Delegate CreateDelegate(Type t, LuaFunction func)
	{
		DelegateValue create = null;

		if (!dict.TryGetValue(t, out create))
		{
			Debugger.LogError("Delegate {0} not register", t.FullName);
			return null;
		}
		return create(func);
	}
Example #44
0
    void ShowAwardsAcquire(List <KeyValueData> awards)
    {
        LuaComponent luaCom = UIManager.Instance.CreateUI("Prefab/GUI/GoodsAcquirePopup").GetComponent <LuaComponent>();

        LuaInterface.LuaFunction setGoodsData = luaCom.table["SetGoodsData"] as LuaInterface.LuaFunction;
        foreach (KeyValueData award in awards)
        {
            setGoodsData.Call(new object[] { luaCom.table, award.id, award.value });
        }
        UIManager.Instance.BringPanelForward(luaCom.gameObject);
    }
Example #45
0
 public void Send(int actionId, int actionRespId, LuaInterface.LuaFunction callback, LuaFramework.ByteBuffer param)
 {
     if (NetWriter.IsSocket())
     {
         SocketRequest(actionId, actionRespId, param, callback, HeadFormater, false);
     }
     else
     {
         //HttpRequest(gameAction, actionParam, HeadFormater, bShowLoading);
     }
 }
Example #46
0
    public static void CallLuaFunction(string name)
    {
        LuaManager manager = MainGame.GetManager <LuaManager>();

        LuaInterface.LuaFunction func = manager.GetFunction(name);
        if (func != null)
        {
            func.Call();
            func.Dispose();
            func = null;
        }
    }
Example #47
0
    public static void CallLuaFunction <T1, T2, T3>(string name, T1 arg1, T2 arg2, T3 arg3)
    {
        LuaManager manager = MainGame.GetManager <LuaManager>();

        LuaInterface.LuaFunction func = manager.GetFunction(name);
        if (func != null)
        {
            func.Call <T1, T2, T3>(arg1, arg2, arg3);
            func.Dispose();
            func = null;
        }
    }
Example #48
0
        public static CharacterBaseInfo CreateCharacterBaseInfo(HeroInfo heroInfo)
        {
            CharacterBaseInfo characterInfo = new CharacterBaseInfo()
            {
                baseId   = (uint)heroInfo.heroData.id,
                hitId    = heroInfo.heroData.hitId,
                skillId1 = heroInfo.heroData.skillId1,
                skillId2 = heroInfo.heroData.skillId2,
                //passiveId1 = heroInfo.heroData.passiveId1,
                passiveIdDic = new Dictionary <int, int>(),
                passiveId2   = heroInfo.heroData.passiveId2,
                instanceID   = heroInfo.instanceID,
                HP           = (int)heroInfo.heroData.HP,
                maxHP        = heroInfo.heroData.HP,
                floatable    = heroInfo.heroData.floatable,
                speed        = (int)heroInfo.heroData.speed,
                roleType     = heroInfo.heroData.roleType,
                roleInfo     = heroInfo
            };

            if (characterInfo.hitId != 0)
            {
                characterInfo.hitSkillInfo = new SkillInfo(characterInfo.hitId);
                characterInfo.hitSkillInfo.characterInstanceId = heroInfo.instanceID;
            }
            if (characterInfo.skillId1 != 0)
            {
                characterInfo.skillInfo1 = new SkillInfo(characterInfo.skillId1);
                characterInfo.skillInfo1.characterInstanceId = heroInfo.instanceID;
            }
            if (characterInfo.skillId2 != 0)
            {
                characterInfo.skillInfo2 = new SkillInfo(characterInfo.skillId2);
                characterInfo.skillInfo2.characterInstanceId = heroInfo.instanceID;
            }
            if (characterInfo.roleInfo.advanceLevel > characterInfo.roleInfo.heroData.starMin)
            {
                characterInfo.dlevel = (uint)characterInfo.roleInfo.advanceLevel - characterInfo.roleInfo.heroData.starMin;
            }
            if (heroInfo.heroData.passiveId1 > 0)
            {
                characterInfo.passiveIdDic.Add((int)heroInfo.heroData.passiveId1, 1);
                string luaFile = "user/skill/passive_skill_" + heroInfo.heroData.passiveId1;
                //if (Lua.Model.LuaData.ExistLuaFile(luaFile))
                LuaScriptMgr.Instance.DoFile(luaFile);
            }
            LuaInterface.LuaFunction initFunc = PassiveSkillController.instance.GetPassiveSkillLuaFunction(PassiveSkillController.INIT_CHARACTER_DATAS, (int)characterInfo.baseId);
            if (initFunc != null)
            {
                initFunc.Call(characterInfo.instanceID);
            }
            return(characterInfo);
        }
Example #49
0
 public void ShowSpecifiedUI(string strUIName, uint param)
 {
     if (UICallList.ContainsKey(strUIName))
     {
         UICallList[strUIName](param);
     }
     else
     {
         LuaInterface.LuaTable    topPanelMgr   = LuaScriptMgr.Instance.GetLuaTable("TopPanelManager");
         LuaInterface.LuaFunction funcShowPanel = topPanelMgr["ShowPanel"] as LuaInterface.LuaFunction;
         funcShowPanel.Call(new object[] { topPanelMgr, strUIName, param });
     }
 }
Example #50
0
    /// <summary>
    /// 请求socket接口,直接处理string格式数据, onReceiveAction 直接处理body内容
    /// 主要考虑lua中的使用string 比较方便
    /// </summary>
    /// <param name="path"></param>
    /// <param name="bodyJsonStr">如果body为空,那么该项填空字符串, 如果该项为null,那么只会进行Receive操作</param>
    /// <param name="onReceiveAction">请求成功的回调,该值为空则不会添加该接受action</param>
    /// <param name="onErrorAction">请求出错的回调,该值为空则不会添加该接受action</param>
    public void Request_lua_fun(string path, string bodyJsonStr, LuaInterface.LuaFunction onReceiveAction, LuaFunction onErrorAction)
    {
        if (bodyJsonStr != null)
        {
            ProtocolHelper.Send(path, new JSONObject(bodyJsonStr));
        }
        Receive_lua_fun(path, onReceiveAction, onErrorAction);

        if (bodyJsonStr != null && (onReceiveAction != null || onErrorAction != null))
        {
            m_SocketReSendMap[path] = bodyJsonStr;
        }
    }
Example #51
0
 public bool CallFunction(int index)
 {
     if (index < dataList.Count)
     {
         if (dataList[index].GetType() == typeof(LuaInterface.LuaFunction))
         {
             LuaInterface.LuaFunction f = (LuaInterface.LuaFunction)dataList[index];
             f.Call();
             return(true);
         }
     }
     return(false);
 }
Example #52
0
 /// <summary>
 /// 执行Lua函数
 /// </summary>
 /// <param name="fun">函数名</param>
 /// <param name="pa">参数列表</param>
 /// <returns></returns>
 public object ExecuteFunc(string fun, params object[] pa)
 {
     LuaInterface.LuaFunction fff = pLuaVM.GetFunction(fun);
     object[] obj = fff.Call(pa);
     if (obj != null)
     {
         return(obj[0]);
     }
     else
     {
         return(null);
     }
 }
Example #53
0
    private void OnDestroy()
    {
        if (_OnCreateLuaCB != null)
        {
            _OnCreateLuaCB.Release();
            _OnCreateLuaCB = null;
        }

        _AllCreatedList.Remove(this);

        _Target      = null;
        _CachedTrans = null;
    }
Example #54
0
    void OnDestroy()
    {
        if (info.funcOnDestroy != null)
        {
            info.funcOnDestroy.Call(table);
        }

        table.Release();
        table = null;

        LuaInterface.LuaTable    topPanelMgr  = LuaScriptMgr.Instance.GetLuaTable("TopPanelManager");
        LuaInterface.LuaFunction SetLuaComNil = topPanelMgr["SetLuaComNil"] as LuaInterface.LuaFunction;
        SetLuaComNil.Call(new object[] { topPanelMgr, info.scriptName });
    }
Example #55
0
    public static R InvokeLuaFunction <T, R>(string name, T arg)
    {
        LuaManager manager = MainGame.GetManager <LuaManager>();

        LuaInterface.LuaFunction func = manager.GetFunction(name);
        if (func != null)
        {
            R ret = func.Invoke <T, R>(arg);
            func.Dispose();
            func = null;
            return(ret);
        }
        return(default(R));
    }
    public void Connect(string host, int port, LuaInterface.LuaFunction func)
    {
        pc = new PomeloClient();
        pc.initClient(host, port);
        pc.connect(null, (data) => {
            JsonObject msg  = new JsonObject();
            msg["deviceId"] = deviceId;
            msg["id"]       = 1;
            pc.request("gate.gateHandler.queryEntry", msg, (result) => {
                Debug.Log("--------------------------------------");
                Debug.Log(result.ToString());
                Debug.Log("--------------------------------------");
                if (Convert.ToInt32(result["code"]) == 200)
                {
                    pc.disconnect();

                    string h = (string)result["host"];
                    int p    = Convert.ToInt32(result["port"]);
                    pc       = new PomeloClient();
                    pc.initClient(h, p);
                    pc.connect(null, (dd) =>
                    {
                        JsonObject conectorMessage = new JsonObject();
                        conectorMessage.Add("deviceId", deviceId);
                        pc.request("connector.entryHandler.entry", conectorMessage, (ret) =>
                        {
                            Debug.Log("--------------------------------------");
                            Debug.Log(ret.ToString());
                            Debug.Log("--------------------------------------");
                            if (Convert.ToInt32(ret["code"]) == 200)
                            {
                                isConnected = true;
                                EventsListen();
                            }

                            if (func != null)
                            {
                                PomeloPackage pkg = new PomeloPackage();
                                pkg.luaFunc       = func;
                                pkg.ReturnData    = ret.ToString();
                                Debug.Log("!!!!!!!!!!!!!!!!!!!! " + pkg.ReturnData);
                                AddResultPackage(pkg);
                            }
                        });
                    });
                }
            });
        });
    }
Example #57
0
    static int QPYX_get_onReceivedKeyCode_YXQP(IntPtr L_YXQP)
    {
        object QPYX_o_YXQP = null;

        try
        {
            QPYX_o_YXQP = ToLua.ToObject(L_YXQP, 1);                        UniWebViewEx QPYX_obj_YXQP = (UniWebViewEx)QPYX_o_YXQP;
            LuaInterface.LuaFunction QPYX_ret_YXQP = QPYX_obj_YXQP.onReceivedKeyCode;
            ToLua.Push(L_YXQP, QPYX_ret_YXQP);
            return(1);
        }
        catch (Exception QPYX_e_YXQP)            {
            return(LuaDLL.toluaL_exception(L_YXQP, QPYX_e_YXQP, QPYX_o_YXQP, "attempt to index onReceivedKeyCode on a nil value"));
        }
    }
    static int QPYX_get_onReceiveTextMessageFn_YXQP(IntPtr L_YXQP)
    {
        object QPYX_o_YXQP = null;

        try
        {
            QPYX_o_YXQP = ToLua.ToObject(L_YXQP, 1);                        DNet.GameWebSocketClient QPYX_obj_YXQP = (DNet.GameWebSocketClient)QPYX_o_YXQP;
            LuaInterface.LuaFunction QPYX_ret_YXQP = QPYX_obj_YXQP.onReceiveTextMessageFn;
            ToLua.Push(L_YXQP, QPYX_ret_YXQP);
            return(1);
        }
        catch (Exception QPYX_e_YXQP)            {
            return(LuaDLL.toluaL_exception(L_YXQP, QPYX_e_YXQP, QPYX_o_YXQP, "attempt to index onReceiveTextMessageFn on a nil value"));
        }
    }
    static int QPYX_get_onEventFn_YXQP(IntPtr L_YXQP)
    {
        object QPYX_o_YXQP = null;

        try
        {
            QPYX_o_YXQP = ToLua.ToObject(L_YXQP, 1);                        GameAsset.AssetBundleManager QPYX_obj_YXQP = (GameAsset.AssetBundleManager)QPYX_o_YXQP;
            LuaInterface.LuaFunction QPYX_ret_YXQP = QPYX_obj_YXQP.onEventFn;
            ToLua.Push(L_YXQP, QPYX_ret_YXQP);
            return(1);
        }
        catch (Exception QPYX_e_YXQP)            {
            return(LuaDLL.toluaL_exception(L_YXQP, QPYX_e_YXQP, QPYX_o_YXQP, "attempt to index onEventFn on a nil value"));
        }
    }
Example #60
0
    static int QPYX_get_gameSdkCallback_YXQP(IntPtr L_YXQP)
    {
        object QPYX_o_YXQP = null;

        try
        {
            QPYX_o_YXQP = ToLua.ToObject(L_YXQP, 1);                        GameSDKCallback QPYX_obj_YXQP = (GameSDKCallback)QPYX_o_YXQP;
            LuaInterface.LuaFunction QPYX_ret_YXQP = QPYX_obj_YXQP.gameSdkCallback;
            ToLua.Push(L_YXQP, QPYX_ret_YXQP);
            return(1);
        }
        catch (Exception QPYX_e_YXQP)            {
            return(LuaDLL.toluaL_exception(L_YXQP, QPYX_e_YXQP, QPYX_o_YXQP, "attempt to index gameSdkCallback on a nil value"));
        }
    }