Esempio n. 1
0
    public static bool BeginCall(this LuaTable curTable, string name, int top)
    {
        LuaState curLuaState = curTable.GetLuaState();

        curLuaState.Push(curTable);
        curLuaState.ToLuaPushTraceback();
        curLuaState.Push(name);
        curLuaState.LuaGetTable(top + 1);
        return(curLuaState.LuaType(top + 3) == LuaTypes.LUA_TFUNCTION);
    }
Esempio n. 2
0
        public Bean(Table table)
        {
            luaTable = (LuaTable)LuaGame.it.StrToLuaTable("{}");

            this.reference = luaTable.GetReference();
            this.luaState  = luaTable.GetLuaState();

            this.table = table;
            luaTable ["_tableName"] = table.name;
            _data = new object[table.cols];
        }
Esempio n. 3
0
        public static void CallMemberOnceWithUnity(LuaTable self, string funcName, Object obj)
        {
            LuaFunction func   = self.GetLuaFunction(funcName);
            int         oldTop = self.GetLuaState().LuaGetTop();

            func.BeginPCall();
            //func.Push(self);
            func.Push(obj);
            func.PCall();
            func.EndPCall();
            func.Dispose();
        }
Esempio n. 4
0
        // 调用多参数
        public static object[] CallMemberOnce(LuaTable self, string funcName, params object[] args)
        {
            LuaFunction func   = self.GetLuaFunction(funcName);
            int         oldTop = self.GetLuaState().LuaGetTop();

            func.BeginPCall();
            func.Push(self);
            func.PushArgs(args);
            func.PCall();
            object[] rets = func.GetLuaState().CheckObjects(oldTop);
            func.EndPCall();

            func.Dispose();
            return(rets);
        }
Esempio n. 5
0
        override protected void OnButtonClick(GameObject go, Button button)
        {
            base.OnButtonClick(go, button);
            //HS_CallLuaFace.CallMemberOnceWithUnity(_LuaTable, "OnButtonClick",go);
            LuaFunction func   = _LuaTable.GetLuaFunction("OnButtonClick");
            int         oldTop = _LuaTable.GetLuaState().LuaGetTop();

            func.BeginPCall();
            func.Push(go);
            func.Push(button);
            func.PCall();
            func.EndPCall();
            func.Dispose();
        }
Esempio n. 6
0
    public static object[] CallTableFunc(this LuaTable curTable, string strFuncName, params object[] pParams)
    {
        LuaState curLuaState = curTable.GetLuaState();
        int      dwTop       = curLuaState.LuaGetTop();

        object[] pRtnObjs = null;

        try
        {
            if (curTable.BeginCall(strFuncName, dwTop))
            {
                int dwParamNum = 0;

                //压入self
                {
                    curLuaState.PushGeneric(curTable);
                    ++dwParamNum;
                }
                //压入参数
                if (pParams != null)
                {
                    for (int i = 0; i < pParams.Length; ++i)
                    {
                        curLuaState.PushGeneric(pParams[i]);
                        ++dwParamNum;
                    }
                }

                curLuaState.Call(dwParamNum, dwTop + 2, dwTop);
                //由于beginCall压入了一个table和trace,所以起始偏移+2
                pRtnObjs = curLuaState.CheckObjects(dwTop + 2);
            }
            else
            {
                curLuaState.LuaSetTop(dwTop);
                throw new LuaException("call fail");
            }
            curLuaState.LuaSetTop(dwTop);
        }
        catch (Exception e)
        {
            curLuaState.LuaSetTop(dwTop);
            throw e;
        }

        return(pRtnObjs);
    }