Esempio n. 1
0
        public static int lua_getinfo(lua_State L, string what, lua_Debug ar)
        {
            lua_lock(L);
            CallInfo ci;
            int      func;
            int      i = 0;

            if (what[i] == '>')
            {
                ci   = null;
                func = L.top - 1;
                imp.api_check(imp.ttisfunction(L, func), "function expected");
                i++;
                L.top--;
            }
            else
            {
                ci   = ar.i_ci;
                func = ci.func;
                imp.lua_assert(imp.ttisfunction(L, ci.func));
            }
            Closure cl     = imp.ttisclosure(L, func) ? imp.clvalue(L, func) : null;
            int     status = imp.auxgetinfo(L, what, i, ar, cl, ci);

            if (what.IndexOf('L') >= 0)
            {
                imp.collectvalidlines(L, cl);
            }
            lua_unlock(L);
            return(status);
        }
Esempio n. 2
0
        public static void funcinfo(lua_Debug ar, Closure cl)
        {
            if (ldebug.noLuaClosure(cl))
            {
                ar.source          = "=[C]";
                ar.linedefined     = -1;
                ar.lastlinedefined = -1;
                ar.what            = "C";
            }
            else
            {
                Proto p = cl.l.p;
                ar.source = p.source == null?getsstr(p.source) : "=?";

                ar.linedefined     = p.linedefined;
                ar.lastlinedefined = p.lastlinedefined;
                ar.what            = ar.linedefined == 0 ? "main" : "Lua";
            }
            luaO_chunkid(ref ar.short_src, ar.source, cc.LUA_IDSIZE);
        }
Esempio n. 3
0
 public static void collectvalidlines(lua_State L, Closure f)
 {
     if (ldebug.noLuaClosure(f))
     {
         setnilvalue(L, L.top);
         api_incr_top(L);
     }
     else
     {
         int[]  lineinfo = f.l.p.lineinfo;
         TValue v        = new TValue();
         Table  t        = luaH_new(L);               /* new table to store active lines */
         sethvalue(L, L.top, t);                      /* push it on stack */
         api_incr_top(L);
         setbvalue(v, 1);                             /* boolean 'true' to be the value of all indices */
         for (int i = 0; i < f.l.p.sizelineinfo; i++) /* for all lines with code */
         {
             luaH_setint(L, t, lineinfo[i], v);       /* table[line] = true */
         }
     }
 }
Esempio n. 4
0
        public static int auxgetinfo(lua_State L, string what, int index, lua_Debug ar, Closure f, CallInfo ci)
        {
            int status = 1;

            for (int i = index; i < what.Length; i++)
            {
                switch (what[i])
                {
                case 'S': {
                    funcinfo(ar, f);
                    break;
                }

                case 'l': {
                    ar.currentline = (ci != null && isLua(ci)) ? currentline(L, ci) : -1;
                    break;
                }

                case 'u': {
                    ar.nups = (byte)((f == null) ? 0 : f.c.nupvalues);
                    if (ldebug.noLuaClosure(f))
                    {
                        ar.isvararg = 1;
                        ar.nparams  = 0;
                    }
                    else
                    {
                        ar.isvararg = f.l.p.is_vararg;
                        ar.nparams  = f.l.p.numparams;
                    }
                    break;
                }

                case 't': {
                    ar.istailcall = (byte)((ci != null) ? (ci.callstatus & CIST_TAIL) : 0);
                    break;
                }

                case 'n': {
                    /* calling function is a known Lua function? */
                    if (ci != null && ((ci.callstatus & CIST_TAIL) != 0) && isLua(ci.previous))
                    {
                        ar.namewhat = getfuncname(L, ci.previous, ref ar.name);
                    }
                    else
                    {
                        ar.namewhat = null;
                    }
                    if (ar.namewhat == null)
                    {
                        ar.namewhat = "";      /* not found */
                        ar.name     = null;
                    }
                    break;
                }

                case 'L': goto case 'f';

                case 'f':      /* handled by lua_getinfo */
                    break;

                default: {
                    status = 0;      /* invalid option */
                    break;
                }
                }
            }
            return(status);
        }
Esempio n. 5
0
 public static bool noLuaClosure(Closure f)
 {
     return(f == null || f.c.tt == LUA_TCCL);
 }