Esempio n. 1
0
        public static int lua_pcall(lua_State L, int nargs, int nresults, int errfunc)
        {
            CallS     c = new CallS();
            int       status;
            ptrdiff_t func;

            lua_lock(L);
            api_checknelems(L, nargs + 1);
            checkresults(L, nargs, nresults);
            if (errfunc == 0)
            {
                func = 0;
            }
            else
            {
                StkId o = index2adr(L, errfunc);
                api_checkvalidindex(L, o);
                func = savestack(L, o);
            }
            c.func     = L.top - (nargs + 1);  /* function to be called */
            c.nresults = nresults;
            status     = luaD_pcall(L, f_call, c, savestack(L, c.func), func);
            adjustresults(L, nresults);
            lua_unlock(L);
            return(status);
        }
Esempio n. 2
0
        public static int LuaPCall(LuaState L, int nargs, int nresults, int errfunc)
        {
            CallS     c = new CallS();
            int       status;
            ptrdiff_t func;

            LuaLock(L);
            CheckNElements(L, nargs + 1);
            CheckResults(L, nargs, nresults);
            if (errfunc == 0)
            {
                func = 0;
            }
            else
            {
                StkId o = Index2Address(L, errfunc);
                CheckValidIndex(L, o);
                func = SaveStack(L, o);
            }
            c.func     = L.top - (nargs + 1);  /* function to be called */
            c.nresults = nresults;
            status     = LuaDPCall(L, FunctionCall, c, SaveStack(L, c.func), func);
            AdjustResults(L, nresults);
            LuaUnlock(L);
            return(status);
        }
Esempio n. 3
0
        ThreadStatus ILuaAPI.PCallK(int numArgs, int numResults, int errFunc,
                                    int context, CSharpFunctionDelegate continueFunc)
        {
            Utl.ApiCheck(continueFunc == null || !CI.IsLua,
                         "cannot use continuations inside hooks");
            Utl.ApiCheckNumElems(this, numArgs + 1);
            Utl.ApiCheck(Status == ThreadStatus.LUA_OK,
                         "cannot do calls on non-normal thread");
            CheckResults(numArgs, numResults);

            int func;

            if (errFunc == 0)
            {
                func = 0;
            }
            else
            {
                StkId addr;
                if (!Index2Addr(errFunc, out addr))
                {
                    Utl.InvalidIndex();
                }

                func = addr.Index;
            }

            ThreadStatus status;
            CallS        c = new CallS();

            c.L         = this;
            c.FuncIndex = Top.Index - (numArgs + 1);
            if (continueFunc == null || NumNonYieldable > 0) // no continuation or no yieldable?
            {
                c.NumResults = numResults;
                status       = D_PCall(DG_F_Call, ref c, c.FuncIndex, func);
            }
            else
            {
                int ciIndex = CI.Index;
                CI.ContinueFunc = continueFunc;
                CI.Context      = context;
                CI.ExtraIndex   = c.FuncIndex;
                CI.OldAllowHook = AllowHook;
                CI.OldErrFunc   = ErrFunc;
                ErrFunc         = func;
                CI.CallStatus  |= CallStatus.CIST_YPCALL;

                D_Call(Stack[c.FuncIndex], numResults, true);

                CallInfo ci = BaseCI[ciIndex];
                ci.CallStatus &= ~CallStatus.CIST_YPCALL;
                ErrFunc        = ci.OldErrFunc;
                status         = ThreadStatus.LUA_OK;
            }
            AdjustResults(numResults);
            return(status);
        }
Esempio n. 4
0
        public static int lua_pcallk(lua_State L, int nargs, int nresults, int errfunc,
                                     int ctx, lua_CFunction k)
        {
            CallS     c = new CallS();
            int       status;
            ptrdiff_t func;

            lua_lock(L);
            api_check(L, k == null || isLua(L.ci) == 0,
                      "cannot use continuations inside hooks");
            api_checknelems(L, nargs + 1);
            api_check(L, L.status == LUA_OK, "cannot do calls on non-normal thread");
            checkresults(L, nargs, nresults);
            if (errfunc == 0)
            {
                func = 0;
            }
            else
            {
                StkId o = index2addr(L, errfunc);
                api_checkstackindex(L, errfunc, o);
                func = savestack(L, o);
            }
            c.func = L.top - (nargs + 1);   /* function to be called */
            if (k == null || L.nny > 0)     /* no continuation or no yieldable? */
            {
                c.nresults = nresults;      /* do a 'conventional' protected call */
                status     = luaD_pcall(L, f_call, c, savestack(L, c.func), func);
            }
            else          /* prepare continuation (call is already protected by 'resume') */
            {
                CallInfo ci = L.ci;
                ci.u.c.k   = k;    /* save continuation */
                ci.u.c.ctx = ctx;  /* save context */
                /* save information for error recovery */
                ci.extra             = savestack(L, c.func);
                ci.u.c.old_allowhook = L.allowhook;
                ci.u.c.old_errfunc   = L.errfunc;
                L.errfunc            = func;
                /* mark that function may do error recovery */
                ci.callstatus |= CIST_YPCALL;
                luaD_call(L, c.func, nresults, 1);      /* do the call */
                ci.callstatus &= (byte)((~CIST_YPCALL) & 0xff);
                L.errfunc      = ci.u.c.old_errfunc;
                status         = LUA_OK; /* if it is here, there were no errors */
            }

            adjustresults(L, nresults);
            lua_unlock(L);
            return(status);
        }
Esempio n. 5
0
 public static int lua_pcall(lua_State L, int nargs, int nresults, int errfunc)
 {
     CallS c = new CallS();
       int status;
       ptrdiff_t func;
       lua_lock(L);
       api_checknelems(L, nargs+1);
       checkresults(L, nargs, nresults);
       if (errfunc == 0)
     func = 0;
       else {
     StkId o = index2adr(L, errfunc);
     api_checkvalidindex(L, o);
     func = savestack(L, o);
       }
       c.func = L.top - (nargs+1);  /* function to be called */
       c.nresults = nresults;
       status = luaD_pcall(L, f_call, c, savestack(L, c.func), func);
       adjustresults(L, nresults);
       lua_unlock(L);
       return status;
 }
Esempio n. 6
0
        static void f_call(lua_State L, object ud)
        {
            CallS c = ud as CallS;

            luaD_call(L, c.func, c.nresults, 0);
        }
Esempio n. 7
0
        private static void F_Call(ref CallS ud)
        {
            CallS c = (CallS)ud;

            c.L.D_Call(c.L.Stack[c.FuncIndex], c.NumResults, false);
        }
Esempio n. 8
0
        ThreadStatus ILuaAPI.PCallK( int numArgs, int numResults, int errFunc,
			int context, CSharpFunctionDelegate continueFunc )
        {
            Utl.ApiCheck( continueFunc == null || !CI.IsLua,
                "cannot use continuations inside hooks" );
            Utl.ApiCheckNumElems( this, numArgs + 1 );
            Utl.ApiCheck( Status == ThreadStatus.LUA_OK,
                "cannot do calls on non-normal thread" );
            CheckResults( numArgs, numResults );

            int func;
            if( errFunc == 0 )
                func = 0;
            else
            {
                StkId addr;
                if( !Index2Addr( errFunc, out addr ) )
                    Utl.InvalidIndex();

                func = addr.Index;
            }

            ThreadStatus status;
            CallS c = new CallS();
            c.L = this;
            c.FuncIndex = Top.Index - (numArgs + 1);
            if( continueFunc == null || NumNonYieldable > 0 ) // no continuation or no yieldable?
            {
                c.NumResults = numResults;
                status = D_PCall( DG_F_Call, ref c, c.FuncIndex, func );
            }
            else
            {
                int ciIndex = CI.Index;
                CI.ContinueFunc = continueFunc;
                CI.Context		= context;
                CI.ExtraIndex	= c.FuncIndex;
                CI.OldAllowHook	= AllowHook;
                CI.OldErrFunc	= ErrFunc;
                ErrFunc = func;
                CI.CallStatus |= CallStatus.CIST_YPCALL;

                D_Call( Stack[c.FuncIndex], numResults, true );

                CallInfo ci = BaseCI[ciIndex];
                ci.CallStatus &= ~CallStatus.CIST_YPCALL;
                ErrFunc = ci.OldErrFunc;
                status = ThreadStatus.LUA_OK;
            }
            AdjustResults( numResults );
            return status;
        }
Esempio n. 9
0
 private static void F_Call(ref CallS ud)
 {
     CallS c = (CallS)ud;
     c.L.D_Call(c.L.Stack[c.FuncIndex], c.NumResults, false);
 }
Esempio n. 10
0
 public static int LuaPCall(LuaState L, int nargs, int nresults, int errfunc)
 {
     CallS c = new CallS();
     int status;
     ptrdiff_t func;
     LuaLock(L);
     CheckNElements(L, nargs + 1);
     CheckResults(L, nargs, nresults);
     if (errfunc == 0)
         func = 0;
     else
     {
         StkId o = Index2Address(L, errfunc);
         CheckValidIndex(L, o);
         func = SaveStack(L, o);
     }
     c.func = L.top - (nargs + 1);  /* function to be called */
     c.nresults = nresults;
     status = LuaDPCall(L, FunctionCall, c, SaveStack(L, c.func), func);
     AdjustResults(L, nresults);
     LuaUnlock(L);
     return status;
 }
Esempio n. 11
0
        static void FunctionCall(LuaState L, object ud)
        {
            CallS c = ud as CallS;

            LuaDCall(L, c.func, c.nresults);
        }