Beispiel #1
0
static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
	int nparams = clLvalue(ci->func)->p->numparams;
	if (n >= ci->u.l.base - ci->func - nparams)
	return NULL;  /* no such vararg */
	else {
	*pos = ci->func + nparams + n;
	return "(*vararg)";  /* generic name for any vararg */
	}
}
Beispiel #2
0
LUA_API const void *lua_topointer (lua_State *L, int idx) {
  StkId o = index2addr(L, idx);
  switch (ttype(o)) {
    case LUA_TTABLE: return hvalue(o);
    case LUA_TLCL: return clLvalue(o);
    case LUA_TCCL: return clCvalue(o);
    case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o)));
    case LUA_TTHREAD: return thvalue(o);
    case LUA_TUSERDATA: return getudatamem(uvalue(o));
    case LUA_TLIGHTUSERDATA: return pvalue(o);
    default: return NULL;
  }
}
Beispiel #3
0
void luaV_execute (lua_State *L) {
  CallInfo *ci = L->ci;
  LClosure *cl;
  TValue *k;
  StkId base;
 newframe:  /* reentry point when frame changes (call/return) */
  lua_assert(ci == L->ci);
  cl = clLvalue(ci->func);
  k = cl->p->k;
  base = ci->u.l.base;

  //printf( "s:%p\n", ci->u.l.savedpc );
  /* main loop of interpreter */
  for (;;) {

    Instruction i = *(ci->u.l.savedpc++);
    StkId ra;
    if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
        (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
      Protect(traceexec(L));
    }
    /* warning!! several calls may realloc the stack and invalidate `ra' */
    ra = RA(i);
    lua_assert(base == ci->u.l.base);
    lua_assert(base <= L->top && L->top < L->stack + L->stacksize);


    // 命令出力
    //printInst( ci->u.l.savedpc - 1 );


    vmdispatch (GET_OPCODE(i)) {
      vmcase(OP_MOVE,
        setobjs2s(L, ra, RB(i));
      )
      vmcase(OP_LOADK,
        TValue *rb = k + GETARG_Bx(i);
        setobj2s(L, ra, rb);
      )
      vmcase(OP_LOADKX,
        TValue *rb;
        lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);
        rb = k + GETARG_Ax(*ci->u.l.savedpc++);
        setobj2s(L, ra, rb);
      )
Beispiel #4
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 #5
0
LUA_API LClosure *lua_tolclosure (lua_State *L, int idx) {
  StkId o = index2addr(L, idx);
  return (!ttisLclosure(o)) ? NULL : (LClosure *) clLvalue(o);
}