Пример #1
0
        public static int lua_pcallk(lua_State L, int nargs, int nresults, int errfunc, long ctx, lua_KFunction k)
        {
            lua_lock(L);
            imp.api_check(k == null || imp.isLua(L.ci) == false, "cannot use continuations inside hooks");
            imp.api_checknelems(L, nargs + 1);
            imp.api_check(L.status == LUA_OK, "cannot do calls on non-normal thread");
            imp.checkresults(L, nargs, nresults);
            int func = 0;

            if (errfunc == 0)
            {
                func = 0;
            }
            else
            {
                TValue o = imp.index2addr(L, errfunc);
                imp.api_checkstackindex(errfunc, o);
                func = imp.savestack(L, errfunc);
            }
            CallS c = new CallS();

            c.func = L.top - (nargs + 1);  /* function to be called */
            int status = 0;

            if (k == null && L.nny > 0) /* no continuation or no yieldable? */
            {
                c.nresults = nresults;  /* do a 'conventional' protected call */
                status     = imp.luaD_pcall(L, imp.f_call, c, imp.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           = imp.savestack(L, c.func);
                ci.u.c.old_errfunc = L.errfunc;
                L.errfunc          = func;
                imp.setoah(ref ci.callstatus, L.allowhook); /* save value of 'allowhook' */
                ci.callstatus |= imp.CIST_YPCALL;           /* function can do error recovery */
                imp.luaD_call(L, c.func, nresults, 1);      /* do the call */
                ci.callstatus = (byte)(ci.callstatus & (~imp.CIST_YPCALL));
                L.errfunc     = ci.u.c.old_errfunc;
                status        = LUA_OK; /* if it is here, there were no errors */
            }
            imp.adjustresults(L, nresults);
            lua_unlock(L);
            return(status);
        }
Пример #2
0
        public static void f_call(lua_State L, object ud)
        {
            CallS c = (CallS)ud;

            luaD_call(L, c.func, c.nresults, 0);
        }