Beispiel #1
0
static void foreach (void)
{
  TObject t = *luaA_Address(luaL_tablearg(1));
  TObject f = *luaA_Address(luaL_functionarg(2));
  int32 i;
  for (i=0; i<avalue(&t)->nhash; i++) {
    Node *nd = &(avalue(&t)->node[i]);
    if (ttype(ref(nd)) != LUA_T_NIL && ttype(val(nd)) != LUA_T_NIL) {
      luaA_pushobject(&f);
      luaA_pushobject(ref(nd));
      luaA_pushobject(val(nd));
      luaD_call((L->stack.top-L->stack.stack)-2, 1);
      if (ttype(L->stack.top-1) != LUA_T_NIL)
        return;
      L->stack.top--;
    }
  }
}
Beispiel #2
0
static void luaB_foreach (void) {
  Hash *a = gethash(1);
  int i;
  TObject f;  /* see comment in 'foreachi' */
  f = *luaA_Address(luaL_functionarg(2));
  luaD_checkstack(3);  /* for f, ref, and val */
  for (i=0; i<a->nhash; i++) {
    Node *nd = &(a->node[i]);
    if (ttype(val(nd)) != LUA_T_NIL) {
      *(L->stack.top++) = f;
      *(L->stack.top++) = *ref(nd);
      *(L->stack.top++) = *val(nd);
      luaD_calln(2, 1);
      if (ttype(L->stack.top-1) != LUA_T_NIL)
        return;
      L->stack.top--;  /* remove result */
    }
  }
}
Beispiel #3
0
static void luaB_foreachi (void) {
  Hash *t = gethash(1);
  int i;
  int n = (int)getnarg(t);
  TObject f;
  /* 'f' cannot be a pointer to TObject, because it is on the stack, and the
     stack may be reallocated by the call. Moreover, some C compilers do not
     initialize structs, so we must do the assignment after the declaration */
  f = *luaA_Address(luaL_functionarg(2));
  luaD_checkstack(3);  /* for f, ref, and val */
  for (i=1; i<=n; i++) {
    *(L->stack.top++) = f;
    ttype(L->stack.top) = LUA_T_NUMBER; nvalue(L->stack.top++) = i;
    *(L->stack.top++) = *luaH_getint(t, i);
    luaD_calln(2, 1);
    if (ttype(L->stack.top-1) != LUA_T_NIL)
      return;
    L->stack.top--;
  }
}
Beispiel #4
0
static void foreachvar (void)
{
  TObject f = *luaA_Address(luaL_functionarg(1));
  GCnode *g;
  StkId name = L->Cstack.base++;  /* place to keep var name (to avoid GC) */
  ttype(L->stack.stack+name) = LUA_T_NIL;
  L->stack.top++;
  for (g = L->rootglobal.next; g; g = g->next) {
    TaggedString *s = (TaggedString *)g;
    if (s->u.s.globalval.ttype != LUA_T_NIL) {
      ttype(L->stack.stack+name) = LUA_T_STRING;
      tsvalue(L->stack.stack+name) = s;  /* keep s on stack to avoid GC */
      luaA_pushobject(&f);
      pushstring(s);
      luaA_pushobject(&s->u.s.globalval);
      luaD_call((L->stack.top-L->stack.stack)-2, 1);
      if (ttype(L->stack.top-1) != LUA_T_NIL)
        return;
      L->stack.top--;
    }
  }
}
Beispiel #5
0
static void luaB_foreachvar (void) {
  GCnode *g;
  TObject f;  /* see comment in 'foreachi' */
  f = *luaA_Address(luaL_functionarg(1));
  luaD_checkstack(4);  /* for extra var name, f, var name, and globalval */
  for (g = L->rootglobal.next; g; g = g->next) {
    TaggedString *s = (TaggedString *)g;
    if (s->u.s.globalval.ttype != LUA_T_NIL) {
      pushtagstring(s);  /* keep (extra) s on stack to avoid GC */
      *(L->stack.top++) = f;
      pushtagstring(s);
      *(L->stack.top++) = s->u.s.globalval;
      luaD_calln(2, 1);
      if (ttype(L->stack.top-1) != LUA_T_NIL) {
        L->stack.top--;
        *(L->stack.top-1) = *L->stack.top;  /* remove extra s */
        return;
      }
      L->stack.top-=2;  /* remove result and extra s */
    }
  }
}
Beispiel #6
0
static void foreachvar() {
	TObject f = *luaA_Address(luaL_functionarg(1));
	GCnode *g;
	StkId name = lua_state->Cstack.base++;  // place to keep var name (to avoid GC)
	ttype(lua_state->stack.stack + name) = LUA_T_NIL;
	lua_state->stack.top++;
	for (g = rootglobal.next; g; g = g->next) {
		TaggedString *s = (TaggedString *)g;
		if (s->globalval.ttype != LUA_T_NIL) {
			ttype(lua_state->stack.stack + name) = LUA_T_STRING;
			tsvalue(lua_state->stack.stack + name) = s;  // keep s on stack to avoid GC
			luaA_pushobject(&f);
			pushstring(s);
			luaA_pushobject(&s->globalval);
			lua_state->state_counter1++;
			luaD_call((lua_state->stack.top - lua_state->stack.stack) - 2, 1);
			lua_state->state_counter1--;
			if (ttype(lua_state->stack.top - 1) != LUA_T_NIL)
				return;
			lua_state->stack.top--;
		}
	}
}
Beispiel #7
0
static void seterrormethod() {
	lua_Object nf = luaL_functionarg(1);
	lua_pushobject(nf);
	lua_pushobject(lua_seterrormethod());
}
Beispiel #8
0
static void funcinfo (void) {
  lua_pushobject(getfuncinfo(luaL_functionarg(1)));
}