Beispiel #1
0
static int auxgetinfo(lua_State* L, const char* what, lua_Debug* ar,
		      Closure* f, CallInfo* ci)
{
	int status = 1;
	if (f == NULL)
	{
		info_tailcall(ar);
		return status;
	}
	for (; *what; what++)
	{
		switch (*what)
		{
			case 'S':
			{
				funcinfo(ar, f);
				break;
			}
			case 'l':
			{
				ar->currentline = (ci) ? currentline(L, ci) : -1;
				break;
			}
			case 'u':
			{
				ar->nups = f->c.nupvalues;
				break;
			}
			case 'n':
			{
				ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL;
				if (ar->namewhat == NULL)
				{
					ar->namewhat = "";  /* not found */
					ar->name = NULL;
				}
				break;
			}
			case 'L':
			case 'f':	 /* handled by lua_getinfo */
				break;
			default:
				status = 0;  /* invalid option */
		}
	}
	return status;
}
Beispiel #2
0
LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
  int status = 1;
  lua_lock(L);
  if (*what == '>') {
    StkId f = L->top - 1;
    if (!ttisfunction(f))
      luaG_runerror(L, "value for `lua_getinfo' is not a function");
    status = auxgetinfo(L, what + 1, ar, f, NULL);
    L->top--;  /* pop function */
  }
  else if (ar->i_ci != 0) {  /* no tail call? */
    CallInfo *ci = L->base_ci + ar->i_ci;
    lua_assert(ttisfunction(ci->base - 1));
    status = auxgetinfo(L, what, ar, ci->base - 1, ci);
  }
  else
    info_tailcall(L, ar);
  if (strchr(what, 'f')) incr_top(L);
  lua_unlock(L);
  return status;
}