Beispiel #1
0
static const char *getobjname (Proto *p, int lastpc, int reg,
                               const char **name) {
    int pc;
    *name = luaF_getlocalname(p, reg + 1, lastpc);
    if (*name)  /* is a local? */
        return "local";
    /* else try symbolic execution */
    pc = findsetreg(p, lastpc, reg);
    if (pc != -1) {  /* could find instruction? */
        Instruction i = p->code[pc];
        OpCode op = GET_OPCODE(i);
        switch (op) {
        case OP_MOVE: {
            int b = GETARG_B(i);  /* move from 'b' to 'a' */
            if (b < GETARG_A(i))
                return getobjname(p, pc, b, name);  /* get name for 'b' */
            break;
        }
        case OP_GETTABUP:
        case OP_GETTABLE: {
            int k = GETARG_C(i);  /* key index */
            int t = GETARG_B(i);  /* table index */
            const char *vn = (op == OP_GETTABLE)  /* name of indexed variable */
                             ? luaF_getlocalname(p, t + 1, pc)
                             : upvalname(p, t);
            kname(p, pc, k, name);
            return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
        }
        case OP_GETUPVAL: {
            *name = upvalname(p, GETARG_B(i));
            return "upvalue";
        }
        case OP_LOADK:
        case OP_LOADKX: {
            int b = (op == OP_LOADK) ? GETARG_Bx(i)
                    : GETARG_Ax(p->code[pc + 1]);
            if (ttisstring(&p->k[b])) {
                *name = svalue(&p->k[b]);
                return "constant";
            }
            break;
        }
        case OP_SELF: {
            int k = GETARG_C(i);  /* key index */
            kname(p, pc, k, name);
            return "method";
        }
        default:
            break;  /* go through to return NULL */
        }
    }
    return NULL;  /* could not find reasonable name */
}
Beispiel #2
0
int CScriptSystem::GetFunctionParamName(HSCRIPTFUNCTION hFunc, XmlNodeRef& funcNode)
{
    lua_getref(m_pLS, (int)hFunc);
    StkId func = m_pLS->top - 1;
    Closure* cl;

    if (ttype(func) != LUA_TFUNCTION)
    {
        lua_pop(m_pLS, 1);
        return -1;
    }

    cl = clvalue(func);
    int numParams = cl->l.p->numparams;
    int validParams = numParams;

    for (int j = 0, i = 0 ; j < numParams; j++)
    {
        const char* name = luaF_getlocalname(cl->l.p, j + 1, 0);
        BEHAVIAC_ASSERT(name);

        if (!string_icmp(name, "self"))
        {
            validParams--;
            continue;
        }

        // There is no value for now, so store the index as the value
        funcNode->setAttr(name, i);
        ++i;
    }

    lua_pop(m_pLS, 1); // lua_getref pop
    return validParams;
}
Beispiel #3
0
static const char *getobjname (lua_State *L, StkId obj, const char **name) {
  StkId func = aux_stackedfunction(L, 0, obj);
  if (!isLmark(func))
    return NULL;  /* not an active Lua function */
  else {
    Proto *p = infovalue(func)->func->f.l;
    int pc = currentpc(func);
    int stackpos = obj - (func+1);  /* func+1 == function base */
    Instruction i = luaG_symbexec(p, pc, stackpos);
    LUA_ASSERT(pc != -1, "function must be active");
    switch (GET_OPCODE(i)) {
      case OP_GETGLOBAL: {
        *name = p->kstr[GETARG_U(i)]->str;
        return "global";
      }
      case OP_GETLOCAL: {
        *name = luaF_getlocalname(p, GETARG_U(i)+1, pc);
        LUA_ASSERT(*name, "local must exist");
        return "local";
      }
      case OP_PUSHSELF:
      case OP_GETDOTTED: {
        *name = p->kstr[GETARG_U(i)]->str;
        return "field";
      }
      default:
        return NULL;  /* no useful name found */
    }
  }
}
Beispiel #4
0
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
  const char *name;
  StkId f = ar->_func;
  Proto *fp = getluaproto(f);
  if (!fp) return NULL;  /* `f' is not a Lua function? */
  name = luaF_getlocalname(fp, n, currentpc(f));
  if (!name) return NULL;
  luaA_pushobject(L, (f+1)+(n-1));  /* push value */
  return name;
}
Beispiel #5
0
static const char* getobjname(lua_State* L, CallInfo* ci, int stackpos,
			      const char** name)
{
	if (isLua(ci))    /* a Lua function? */
	{
		Proto* p = ci_func(ci)->l.p;
		int pc = currentpc(L, ci);
		Instruction i;
		*name = luaF_getlocalname(p, stackpos + 1, pc);
		if (*name)	/* is a local? */
			return "local";
		i = symbexec(p, pc, stackpos);  /* try symbolic execution */
		lua_assert(pc != -1);
		switch (GET_OPCODE(i))
		{
			case OP_GETGLOBAL:
			{
				int g = GETARG_Bx(i);  /* global index */
				lua_assert(ttisstring(&p->k[g]));
				*name = svalue(&p->k[g]);
				return "global";
			}
			case OP_MOVE:
			{
				int a = GETARG_A(i);
				int b = GETARG_B(i);  /* move from `b' to `a' */
				if (b < a)
					return getobjname(L, ci, b, name);  /* get name for `b' */
				break;
			}
			case OP_GETTABLE:
			{
				int k = GETARG_C(i);  /* key index */
				*name = kname(p, k);
				return "field";
			}
			case OP_GETUPVAL:
			{
				int u = GETARG_B(i);  /* upvalue index */
				*name = p->upvalues ? getstr(p->upvalues[u]) : "?";
				return "upvalue";
			}
			case OP_SELF:
			{
				int k = GETARG_C(i);  /* key index */
				*name = kname(p, k);
				return "method";
			}
			default:
				break;
		}
	}
	return NULL;	/* no useful name found */
}
Beispiel #6
0
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
  const char *name;
  StkId f = ar->_func;
  Proto *fp = getluaproto(f);
  L->top--;  /* pop new value */
  if (!fp) return NULL;  /* `f' is not a Lua function? */
  name = luaF_getlocalname(fp, n, currentpc(f));
  if (!name || name[0] == '(') return NULL;  /* `(' starts private locals */
  *((f+1)+(n-1)) = *L->top;
  return name;
}
Beispiel #7
0
static const char *findlocal (lua_State *L, CallInfo *ci, int n) {
  const char *name;
  Proto *fp = getluaproto(ci);
  if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL)
    return name;  /* is a local variable in a Lua function */
  else {
    StkId limit = (ci == L->ci) ? L->top : (ci+1)->func;
    if (limit - ci->base >= n && n > 0)  /* is 'n' inside 'ci' stack? */
      return "(*temporary)";
    else
      return NULL;
  }
}
Beispiel #8
0
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
  const char *name;
  CallInfo *ci;
  Proto *fp;
  lua_lock(L);
  name = NULL;
  ci = L->base_ci + ar->i_ci;
  fp = getluaproto(ci);
  if (fp) {  /* is a Lua function? */
    name = luaF_getlocalname(fp, n, currentpc(ci));
    if (name)
      luaA_pushobject(L, ci->base+(n-1));  /* push value */
  }
  lua_unlock(L);
  return name;
}
Beispiel #9
0
lua_Object lua_getlocal(lua_Function func, int32 local_number, char **name) {
	// check whether func is a Lua function
	if (lua_tag(func) != LUA_T_PROTO)
		return LUA_NOOBJECT;
	else {
		TObject *f = Address(func);
		TProtoFunc *fp = luaA_protovalue(f)->value.tf;
		*name = luaF_getlocalname(fp, local_number, lua_currentline(func));
		if (*name) {
			// if "*name", there must be a LUA_T_LINE
			// therefore, f + 2 points to function base
			return Ref((f + 2) + (local_number - 1));
		} else
			return LUA_NOOBJECT;
	}
}
Beispiel #10
0
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
  const char *name;
  CallInfo *ci;
  Proto *fp;
  lua_lock(L);
  name = NULL;
  ci = L->base_ci + ar->i_ci;
  fp = getluaproto(ci);
  L->top--;  /* pop new value */
  if (fp) {  /* is a Lua function? */
    name = luaF_getlocalname(fp, n, currentpc(ci));
    if (!name || name[0] == '(')  /* `(' starts private locals */
      name = NULL;
    else
      setobjs2s(ci->base+(n-1), L->top);
  }
  lua_unlock(L);
  return name;
}
Beispiel #11
0
int32 lua_setlocal(lua_Function func, int32 local_number) {
	// check whether func is a Lua function
	if (lua_tag(func) != LUA_T_PROTO)
		return 0;
	else {
		TObject *f = Address(func);
		TProtoFunc *fp = luaA_protovalue(f)->value.tf;
		char *name = luaF_getlocalname(fp, local_number, lua_currentline(func));
		checkCparams(1);
		--lua_state->stack.top;
		if (name) {
			// if "name", there must be a LUA_T_LINE
			// therefore, f+2 points to function base
			*((f + 2) + (local_number - 1)) = *lua_state->stack.top;
			return 1;
		} else
			return 0;
	}
}
Beispiel #12
0
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
	const char *name;
	lua_lock(L);
	if (ar == NULL) {  /* information about non-active function? */
	if (!isLfunction(L->top - 1))  /* not a Lua function? */
		name = NULL;
	else  /* consider live variables at function start (parameters) */
		name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0);
	}
	else {  /* active function; get information through 'ar' */
	StkId pos = 0;  /* to avoid warnings */
	name = findlocal(L, ar->i_ci, n, &pos);
	if (name) {
		setobj2s(L, L->top, pos);
		api_incr_top(L);
	}
	}
	lua_unlock(L);
	return name;
}
Beispiel #13
0
static const char *findlocal (lua_State *L, CallInfo *ci, int n,
								StkId *pos) {
	const char *name = NULL;
	StkId base;
	if (isLua(ci)) {
	if (n < 0)  /* access to vararg values? */
		return findvararg(ci, -n, pos);
	else {
		base = ci->u.l.base;
		name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));
	}
	}
	else
	base = ci->func + 1;
	if (name == NULL) {  /* no 'standard' name? */
	StkId limit = (ci == L->ci) ? L->top : ci->next->func;
	if (limit - base >= n && n > 0)  /* is 'n' inside 'ci' stack? */
		name = "(*temporary)";  /* generic name for any valid slot */
	else
		return NULL;  /* no name */
	}
	*pos = base + (n - 1);
	return name;
}
Beispiel #14
0
static void PrintLocal(const Proto* tf, int n, int pc)
{
 const char* s=luaF_getlocalname(tf,n+1,pc); 
 printf("%u",n);
 if (s!=NULL) printf("\t; %s",s);
}