lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


That implementation is unfriendly toward nil's in ... isn't it?

How about the following for the small case:

// insert at line 248
static int ieachaux (lua_State *L) {
   int i = luaL_checkint(L, 2);
   i++;
   lua_pushinteger(L, i);
   lua_pushvalue(lua_upvalueindex(i));
   return ( lua_tolightuserdata(L, -1) == &ieachaux  ) ? 0 : 2:
}

static int luaB_ieach (lua_State *L) {
   int n = lua_gettop(L);
   if (n + 1 <= LUAI_MAXUPVALUES) {
     lua_pushlightuserdata( L, &ieachaux );
     lua_pushcclosure(L, ieachaux, n+1);
     lua_pushnil(L);
   }
   else {
     // FIX_ME: This needs sentinel logic as well...
     lua_pushvalue(L, lua_upvalueindex(1));
     lua_createtable(L, n, 0);
     do {
       lua_rawseti(L, -1, n);
     } while (--n);
   }
   lua_pushinteger(L, 0);
   return 3;
}

Mark