Beispiel #1
0
		extern ptrdiff_t overlays_at (int pos, int extend, Shelisp.Object **vec_ptr,
					      ptrdiff_t *len_ptr, int *next_ptr,
					      int *prev_ptr, int change_req);
Beispiel #2
0
        /* }====================================================== */



        /*
        ** The subtraction of two potentially unrelated pointers is
        ** not ISO C, but it should not crash a program; the subsequent
        ** checks are ISO C and ensure a correct result.
        */
        private static int isinstack(CallInfo ci, TValue o)
        {
            ptrdiff_t i = o - ci.u.l.base_;

            return((0 <= i && i < (ci.top - ci.u.l.base_) && ci.u.l.base_ + i == o)?1:0);
        }
Beispiel #3
0
 public static int LuaDPCall(LuaState L, Pfunc func, object u,
                 ptrdiff_t old_top, ptrdiff_t ef)
 {
     int status;
     ushort oldnCcalls = L.nCcalls;
     ptrdiff_t old_ci = SaveCI(L, L.ci);
     LuaByteType old_allowhooks = L.allowhook;
     ptrdiff_t old_errfunc = L.errfunc;
     L.errfunc = ef;
     status = LuaDRawRunProtected(L, func, u);
     if (status != 0)
     {  /* an error occurred? */
         StkId oldtop = RestoreStack(L, old_top);
         LuaFClose(L, oldtop);  /* close eventual pending closures */
         LuaDSetErrorObj(L, status, oldtop);
         L.nCcalls = oldnCcalls;
         L.ci = RestoreCI(L, old_ci);
         L.base_ = L.ci.base_;
         L.savedpc = InstructionPtr.Assign(L.ci.savedpc);
         L.allowhook = old_allowhooks;
         RestoreStackLimit(L);
     }
     L.errfunc = old_errfunc;
     return status;
 }
Beispiel #4
0
 public static int luaD_pcall (lua_State L, Pfunc func, object u,
                               ptrdiff_t old_top, ptrdiff_t ef) {
     int status;
     ushort oldnCcalls = L.nCcalls;
     ptrdiff_t old_ci = saveci(L, L.ci);
     lu_byte old_allowhooks = L.allowhook;
     ptrdiff_t old_errfunc = L.errfunc;
     L.errfunc = ef;
     status = luaD_rawrunprotected(L, func, u);
     if (status != 0) {  /* an error occurred? */
         StkId oldtop = restorestack(L, old_top);
         luaF_close(L, oldtop);  /* close eventual pending closures */
         luaD_seterrorobj(L, status, oldtop);
         L.nCcalls = oldnCcalls;
         L.ci = restoreci(L, old_ci);
         L.base_ = L.ci.base_;
         L.savedpc = InstructionPtr.Assign(L.ci.savedpc);
         L.allowhook = old_allowhooks;
         restore_stack_limit(L);
     }
     L.errfunc = old_errfunc;
     return status;
 }
Beispiel #5
0
        private static int str_find_aux(LuaState L, int find)
        {
            uint      l1, l2;
            CharPtr   s    = luaL_checklstring(L, 1, out l1);
            CharPtr   p    = luaL_checklstring(L, 2, out l2);
            ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1;

            if (init < 0)
            {
                init = 0;
            }
            else if ((uint)(init) > l1)
            {
                init = (ptrdiff_t)l1;
            }
            if ((find != 0) && ((lua_toboolean(L, 4) != 0) ||  /* explicit request? */
                                strpbrk(p, SPECIALS) == null)) /* or no special characters? */
            /* do a plain search */
            {
                CharPtr s2 = lmemfind(s + init, (uint)(l1 - init), p, (uint)(l2));
                if (s2 != null)
                {
                    lua_pushinteger(L, s2 - s + 1);
                    lua_pushinteger(L, (int)(s2 - s + l2));
                    return(2);
                }
            }
            else
            {
                MatchState ms     = new MatchState();
                int        anchor = 0;
                if (p[0] == '^')
                {
                    p      = p.next();
                    anchor = 1;
                }
                CharPtr s1 = s + init;
                ms.L        = L;
                ms.src_init = s;
                ms.src_end  = s + l1;
                do
                {
                    CharPtr res;
                    ms.level = 0;
                    if ((res = match(ms, s1, p)) != null)
                    {
                        if (find != 0)
                        {
                            lua_pushinteger(L, s1 - s + 1); /* start */
                            lua_pushinteger(L, res - s);    /* end */
                            return(push_captures(ms, null, null) + 2);
                        }
                        else
                        {
                            return(push_captures(ms, s1, res));
                        }
                    }
                } while (((s1 = s1.next()) <= ms.src_end) && (anchor == 0));
            }
            lua_pushnil(L);  /* not found */
            return(1);
        }
Beispiel #6
0
 private static ptrdiff_t posrelat(ptrdiff_t pos, uint len)
 {
     /* relative string position: negative means back from end */
     return((pos >= 0) ? pos : (ptrdiff_t)len + pos + 1);
 }
Beispiel #7
0
		private static ptrdiff_t posrelat (ptrdiff_t pos, uint len) {
		  /* relative string position: negative means back from end */
		  if (pos < 0) pos += (ptrdiff_t)len + 1;
		  return (pos >= 0) ? pos : 0;
		}
Beispiel #8
0
        /*
        ** returns true if function has been executed (C function)
        */
        public static int luaD_precall(lua_State L, StkId func, int nresults)
        {
            lua_CFunction f;
            CallInfo      ci;
            int           n; /* number of arguments (Lua) or returns (C) */
            ptrdiff_t     funcr = savestack(L, func);

            switch (ttype(func))
            {
            case LUA_TLCF:          /* light C function */
                f = fvalue(func);
                //goto Cfunc; //FIXME:removed, see below
                luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
                ci          = next_ci(L);         /* now 'enter' new function */
                ci.nresults = (short)nresults;    //FIXME:added, (short)
                ci.func     = restorestack(L, funcr);
                ci.top      = L.top + LUA_MINSTACK;
                lua_assert(ci.top <= L.stack_last);
                ci.callstatus = 0;
                luaC_checkGC(L);            /* stack grow uses memory */
                if ((L.hookmask & LUA_MASKCALL) != 0)
                {
                    luaD_hook(L, LUA_HOOKCALL, -1);
                }
                lua_unlock(L);
                n = f(L);        /* do the actual call */
                lua_lock(L);
                api_checknelems(L, n);
                luaD_poscall(L, L.top - n);
                return(1);

            case LUA_TCCL: {          /* C closure */
                f = clCvalue(func).f;
                //Cfunc: //FIXME:removed, see upper
                luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
                ci          = next_ci(L);         /* now 'enter' new function */
                ci.nresults = (short)nresults;    //FIXME:added, (short)
                ci.func     = restorestack(L, funcr);
                ci.top      = L.top + LUA_MINSTACK;
                lua_assert(ci.top <= L.stack_last);
                ci.callstatus = 0;
                luaC_checkGC(L);            /* stack grow uses memory */
                if ((L.hookmask & LUA_MASKCALL) != 0)
                {
                    luaD_hook(L, LUA_HOOKCALL, -1);
                }
                lua_unlock(L);
                n = f(L);        /* do the actual call */
                lua_lock(L);
                api_checknelems(L, n);
                luaD_poscall(L, L.top - n);
                return(1);
            }

            case LUA_TLCL: {          /* Lua function: prepare its call */
                StkId base_;
                Proto p = clLvalue(func).p;
                n = cast_int(L.top - func) - 1;        /* number of real arguments */
                luaD_checkstack(L, p.maxstacksize);
                for (; n < p.numparams; n++)
                {
                    setnilvalue(lua_TValue.inc(ref L.top));      /* complete missing arguments */
                }
                if (0 == p.is_vararg)
                {
                    func  = restorestack(L, funcr);
                    base_ = func + 1;
                }
                else
                {
                    base_ = adjust_varargs(L, p, n);
                    func  = restorestack(L, funcr); /* previous call can change stack */
                }
                ci           = next_ci(L);          /* now `enter' new function */
                ci.nresults  = (short)nresults;     //FIXME:added, (short)
                ci.func      = func;
                ci.u.l.base_ = base_;
                ci.top       = base_ + p.maxstacksize;
                lua_assert(ci.top <= L.stack_last);
                ci.u.l.savedpc = new InstructionPtr(p.code, 0); /* starting point */            //FIXME:??? //FIXME:???
                ci.callstatus  = CIST_LUA;
                L.top          = ci.top;
                luaC_checkGC(L);            /* stack grow uses memory */
                if ((L.hookmask & LUA_MASKCALL) != 0)
                {
                    callhook(L, ci);
                }
                return(0);
            }

            default: {                                   /* not a function */
                func = tryfuncTM(L, func);               /* retry with 'function' tag method */
                return(luaD_precall(L, func, nresults)); /* now it must be a function */
            }
            }
        }
Beispiel #9
0
 public static extern void THStorage_resize(THStorage_ *storage, ptrdiff_t size);
Beispiel #10
0
 public static extern THStorage_ *THStorage__newWithSize(ptrdiff_t size);
 public static extern void THFloatStorageresize(THFloatStorage *storage, ptrdiff_t size);
 public static extern THFloatStorage *THFloatStorage_newWithSize(ptrdiff_t size);