Beispiel #1
0
        private static int LinyeeBError(LinyeeState L)
        {
            int level = LinyeeLOptInt(L, 2, 1);

            LinyeeSetTop(L, 1);
            if ((LinyeeIsString(L, 1) != 0) && (level > 0))        /* add extra information? */
            {
                LinyeeLWhere(L, level);
                LinyeePushValue(L, 1);
                LinyeeConcat(L, 2);
            }
            return(LinyeeError(L));
        }
Beispiel #2
0
 private static int LoadAux(LinyeeState L, int status)
 {
     if (status == 0)        /* OK? */
     {
         return(1);
     }
     else
     {
         LinyeePushNil(L);
         LinyeeInsert(L, -2); /* put before error message */
         return(2);           /* return nil plus error message */
     }
 }
Beispiel #3
0
        public static void LinyeeRawSet(LinyeeState L, int idx)
        {
            StkId t;

            LinyeeLock(L);
            CheckNElements(L, 2);
            t = Index2Address(L, idx);
            ApiCheck(L, TTIsTable(t));
            SetObj2T(L, luaH_set(L, HValue(t), L.top - 2), L.top - 1);
            LinyeeCBarrierT(L, HValue(t), L.top - 1);
            L.top -= 2;
            LinyeeUnlock(L);
        }
Beispiel #4
0
        private static int sort(LinyeeState L)
        {
            int n = aux_getn(L, 1);

            LinyeeLCheckStack(L, 40, "");        /* assume array is smaller than 2^40 */
            if (!LinyeeIsNoneOrNil(L, 2))        /* is there a 2nd argument? */
            {
                LinyeeLCheckType(L, 2, LINYEE_TFUNCTION);
            }
            LinyeeSetTop(L, 2);        /* make sure there is two arguments */
            auxsort(L, 1, n);
            return(0);
        }
Beispiel #5
0
        public static ly_Alloc LinyeeGetAllocF(LinyeeState L, ref object ud)
        {
            ly_Alloc f;

            LinyeeLock(L);
            if (ud != null)
            {
                ud = G(L).ud;
            }
            f = G(L).frealloc;
            LinyeeUnlock(L);
            return(f);
        }
Beispiel #6
0
        public static LinyeeState LinyeeNewThread(LinyeeState L)
        {
            LinyeeState L1;

            LinyeeLock(L);
            LinyeeCCheckGC(L);
            L1 = luaE_newthread(L);
            SetTTHValue(L, L.top, L1);
            IncrementTop(L);
            LinyeeUnlock(L);
            luai_userstatethread(L, L1);
            return(L1);
        }
Beispiel #7
0
 /*
 ** Open math library
 */
 public static int LinyeeOpenMath(LinyeeState L)
 {
     LinyeeLRegister(L, LINYEE_MATHLIBNAME, mathlib);
     LinyeePushNumber(L, PI);
     LinyeeSetField(L, -2, "pi");
     LinyeePushNumber(L, HUGE_VAL);
     LinyeeSetField(L, -2, "huge");
         #if LINYEE_COMPAT_MOD
     LinyeeGetField(L, -1, "fmod");
     LinyeeSetField(L, -2, "mod");
         #endif
     return(1);
 }
Beispiel #8
0
        public static void LinyeeRawSetI(LinyeeState L, int idx, int n)
        {
            StkId o;

            LinyeeLock(L);
            CheckNElements(L, 1);
            o = Index2Address(L, idx);
            ApiCheck(L, TTIsTable(o));
            SetObj2T(L, luaH_setnum(L, HValue(o), n), L.top - 1);
            LinyeeCBarrierT(L, HValue(o), L.top - 1);
            StkId.Dec(ref L.top);
            LinyeeUnlock(L);
        }
Beispiel #9
0
        static void FunctionCCall(LinyeeState L, object ud)
        {
            CCallS  c = ud as CCallS;
            Closure cl;

            cl     = LinyeeFNewCclosure(L, 0, GetCurrentEnv(L));
            cl.c.f = c.func;
            SetCLValue(L, L.top, cl);      /* push function */
            IncrementTop(L);
            SetPValue(L.top, c.ud);        /* push only argument */
            IncrementTop(L);
            LinyeeDCall(L, L.top - 2, 0);
        }
Beispiel #10
0
        public static int LinyeeLessThan(LinyeeState L, int index1, int index2)
        {
            StkId o1, o2;
            int   i;

            LinyeeLock(L);        /* may call tag method */
            o1 = Index2Address(L, index1);
            o2 = Index2Address(L, index2);
            i  = (o1 == LinyeeONilObject || o2 == LinyeeONilObject) ? 0
                           : luaV_lessthan(L, o1, o2);
            LinyeeUnlock(L);
            return(i);
        }
Beispiel #11
0
        private static int OSExit(LinyeeState L)
        {
#if XBOX
            LinyeeLError(L, "os_exit not supported on XBox360");
#else
#if SILVERLIGHT
            throw new SystemException();
#else
            Environment.Exit(EXIT_SUCCESS);
#endif
#endif
            return(0);
        }
Beispiel #12
0
 private static void TreatStackOption(LinyeeState L, LinyeeState L1, CharPtr fname)
 {
     if (L == L1)
     {
         LinyeePushValue(L, -2);
         LinyeeRemove(L, -3);
     }
     else
     {
         LinyeeXMove(L1, L, 1);
     }
     LinyeeSetField(L, -2, fname);
 }
Beispiel #13
0
 public static void LinyeeDCheckStack(LinyeeState L, int n)
 {
     if ((L.stack_last - L.top) <= n)
     {
         LinyeeDGrowStack(L, n);
     }
     else
     {
                         #if HARDSTACKTESTS
         luaD_reallocstack(L, L.stacksize - EXTRA_STACK - 1);
                         #endif
     }
 }
Beispiel #14
0
 private static int LinyeeBGetFEnv(LinyeeState L)
 {
     GetFunc(L, 1);
     if (LinyeeIsCFunction(L, -1))                /* is a C function? */
     {
         LinyeePushValue(L, LINYEE_GLOBALSINDEX); /* return the thread's global env. */
     }
     else
     {
         LinyeeGetFEnv(L, -1);
     }
     return(1);
 }
Beispiel #15
0
        public static void LinyeeGetField(LinyeeState L, int idx, CharPtr k)
        {
            StkId  t;
            TValue key = new LinyeeTypeValue();

            LinyeeLock(L);
            t = Index2Address(L, idx);
            CheckValidIndex(L, t);
            SetSValue(L, key, luaS_new(L, k));
            luaV_gettable(L, t, key, L.top);
            IncrementTop(L);
            LinyeeUnlock(L);
        }
Beispiel #16
0
        public static object LinyeeToUserData(LinyeeState L, int idx)
        {
            StkId o = Index2Address(L, idx);

            switch (TType(o))
            {
            case LINYEE_TUSERDATA: return(RawUValue(o).user_data);

            case LINYEE_TLIGHTUSERDATA: return(PValue(o));

            default: return(null);
            }
        }
Beispiel #17
0
 public static int LinyeeYield(LinyeeState L, int nresults)
 {
     luai_userstateyield(L, nresults);
     LinyeeLock(L);
     if (L.nCcalls > L.baseCcalls)
     {
         LinyeeGRunError(L, "attempt to yield across metamethod/C-call boundary");
     }
     L.base_  = L.top - nresults;       /* protect stack slots below */
     L.status = LINYEE_YIELD;
     LinyeeUnlock(L);
     return(-1);
 }
Beispiel #18
0
 private static LinyeeState GetThread(LinyeeState L, out int arg)
 {
     if (LinyeeIsThread(L, 1))
     {
         arg = 1;
         return(LinyeeToThread(L, 1));
     }
     else
     {
         arg = 0;
         return(L);
     }
 }
Beispiel #19
0
 private static void GetHookTable(LinyeeState L)
 {
     LinyeePushLightUserData(L, KEY_HOOK);
     LinyeeRawGet(L, LINYEE_REGISTRYINDEX);
     if (!LinyeeIsTable(L, -1))
     {
         LinyeePop(L, 1);
         LinyeeCreateTable(L, 0, 1);
         LinyeePushLightUserData(L, KEY_HOOK);
         LinyeePushValue(L, -2);
         LinyeeRawSet(L, LINYEE_REGISTRYINDEX);
     }
 }
Beispiel #20
0
 public static void luaV_concat(LinyeeState L, int total, int last)
 {
     do
     {
         StkId top = L.base_ + last + 1;
         int   n   = 2;      /* number of elements handled in this pass (at least 2) */
         if (!(TTIsString(top - 2) || TTIsNumber(top - 2)) || (tostring(L, top - 1) == 0))
         {
             if (call_binTM(L, top - 2, top - 1, top - 2, TMS.TM_CONCAT) == 0)
             {
                 LinyeeGConcatError(L, top - 2, top - 1);
             }
         }
         else if (TSValue(top - 1).len == 0) /* second op is empty? */
         {
             tostring(L, top - 2);           /* result is first op (as string) */
         }
         else
         {
             /* at least two string values; get as many as possible */
             uint    tl = TSValue(top - 1).len;
             CharPtr buffer;
             int     i;
             /* collect total length */
             for (n = 1; n < total && (tostring(L, top - n - 1) != 0); n++)
             {
                 uint l = TSValue(top - n - 1).len;
                 if (l >= MAXSIZET - tl)
                 {
                     LinyeeGRunError(L, "string length overflow");
                 }
                 tl += l;
             }
             buffer = luaZ_openspace(L, G(L).buff, tl);
             if (mybuff == null)
             {
                 mybuff = buffer;
             }
             tl = 0;
             for (i = n; i > 0; i--)      /* concat all strings */
             {
                 uint l = TSValue(top - i).len;
                 memcpy(buffer.chars, (int)tl, SValue(top - i).chars, (int)l);
                 tl += l;
             }
             SetSValue2S(L, top - n, luaS_newlstr(L, buffer, tl));
         }
         total -= n - 1;        /* got `n' strings to create 1 new */
         last  -= n - 1;
     } while (total > 1);       /* repeat until only 1 result left */
 }
Beispiel #21
0
        /* mark root set */
        private static void MarkRoot(LinyeeState L)
        {
            GlobalState g = G(L);

            g.gray      = null;
            g.grayagain = null;
            g.weak      = null;
            MarkObject(g, g.mainthread);
            /* make global table be traversed before main stack */
            MarkValue(g, Gt(g.mainthread));
            MarkValue(g, Registry(L));
            MarkMT(g);
            g.gcstate = GCSpropagate;
        }
Beispiel #22
0
        public static ly_Number LinyeeToNumber(LinyeeState L, int idx)
        {
            TValue n = new LinyeeTypeValue();
            TValue o = Index2Address(L, idx);

            if (tonumber(ref o, n) != 0)
            {
                return(NValue(o));
            }
            else
            {
                return(0);
            }
        }
Beispiel #23
0
        private static StkId CallRetHooks(LinyeeState L, StkId firstResult)
        {
            ptrdiff_t fr = SaveStack(L, firstResult);        /* next call may change stack */

            LinyeeDCallHook(L, LINYEE_HOOKRET, -1);
            if (FIsLinyee(L.ci))                                                        /* Linyee function? */
            {
                while (((L.hookmask & LINYEE_MASKRET) != 0) && (L.ci.tailcalls-- != 0)) /* tail calls */
                {
                    LinyeeDCallHook(L, LINYEE_HOOKTAILRET, -1);
                }
            }
            return(RestoreStack(L, fr));
        }
Beispiel #24
0
        public static void LinyeeSetField(LinyeeState L, int idx, CharPtr k)
        {
            StkId  t;
            TValue key = new LinyeeTypeValue();

            LinyeeLock(L);
            CheckNElements(L, 1);
            t = Index2Address(L, idx);
            CheckValidIndex(L, t);
            SetSValue(L, key, luaS_new(L, k));
            luaV_settable(L, t, key, L.top - 1);
            StkId.Dec(ref L.top);        /* pop value */
            LinyeeUnlock(L);
        }
Beispiel #25
0
        private static int IoToString(LinyeeState L)
        {
            Stream f = ToFilePointer(L).file;

            if (f == null)
            {
                LinyeePushLiteral(L, "file (closed)");
            }
            else
            {
                LinyeePushFString(L, "file (%p)", f);
            }
            return(1);
        }
Beispiel #26
0
 public static int luaV_tostring(LinyeeState L, StkId obj)
 {
     if (!TTIsNumber(obj))
     {
         return(0);
     }
     else
     {
         ly_Number n = NValue(obj);
         CharPtr   s = ly_number2str(n);
         SetSValue2S(L, obj, luaS_new(L, s));
         return(1);
     }
 }
Beispiel #27
0
 static int report(LinyeeState L, int status)
 {
     if ((status != 0) && !Linyee.LinyeeIsNil(L, -1))
     {
         CharPtr msg = Linyee.LinyeeToString(L, -1);
         if (msg == null)
         {
             msg = "(error object is not a string)";
         }
         l_message(progname, msg);
         Linyee.LinyeePop(L, 1);
     }
     return(status);
 }
Beispiel #28
0
        public static void LinyeeRemove(LinyeeState L, int idx)
        {
            StkId p;

            LinyeeLock(L);
            p = Index2Address(L, idx);
            CheckValidIndex(L, p);
            while ((p = p[1]) < L.top)
            {
                SetObj2S(L, p - 1, p);
            }
            StkId.Dec(ref L.top);
            LinyeeUnlock(L);
        }
Beispiel #29
0
        public static CharPtr LinyeeSetLocal(LinyeeState L, LinyeeDebug ar, int n)
        {
            CallInfo ci   = L.base_ci[ar.i_ci];
            CharPtr  name = FindLocal(L, ci, n);

            LinyeeLock(L);
            if (name != null)
            {
                SetObj2S(L, ci.base_[n - 1], L.top - 1);
            }
            StkId.Dec(ref L.top);        /* pop value */
            LinyeeUnlock(L);
            return(name);
        }
Beispiel #30
0
        private static int str_reverse(LinyeeState L)
        {
            uint          l;
            LinyeeLBuffer b = new LinyeeLBuffer();
            CharPtr       s = LinyeeLCheckLString(L, 1, out l);

            LinyeeLBuffInit(L, b);
            while ((l--) != 0)
            {
                LinyeeLAddChar(b, s[l]);
            }
            LinyeeLPushResult(b);
            return(1);
        }