lua-users home
lua-l archive

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



Quoting Dirk Laurie <dirk.laurie@gmail.com>:

2018-07-19 1:52 GMT+02:00  <tobias@justdreams.de>:


I guess I can shorten it to the minimum but it's still clumsy:

local t = setmetatable( {},{__ipairs=function(tbl) return function() return
nil,nil,true end,tbl,0 end})

local a,b,c = ipairs(t)
local _,_,_isCompat = a(b,c)

I replied to the first post before reading this one. Here you do have an
example. This example runs perfectly for me in both Lua 5.3 and 5.4.

But maybe it is a simpler case than the one on which you observed
the offending behaviour.

When running that code in 5.4, _isCompat==true for you? For me it's only in
5.3.

the implementation in lua-5.4:
static int luaB_ipairs (lua_State *L) {
  luaL_checkany(L, 1);
  lua_pushcfunction(L, ipairsaux);  /* iteration function */
  lua_pushvalue(L, 1);  /* state */
  lua_pushinteger(L, 0);  /* initial value */
  return 3;
}

in Lua-5.3:
static int luaB_ipairs (lua_State *L) {
#if defined(LUA_COMPAT_IPAIRS)
  return pairsmeta(L, "__ipairs", 1, ipairsaux);
#else
  luaL_checkany(L, 1);
  lua_pushcfunction(L, ipairsaux);  /* iteration function */
  lua_pushvalue(L, 1);  /* state */
  lua_pushinteger(L, 0);  /* initial value */
  return 3;
#endif
}

This is by design. It's not an error. In 5.3, LUA_COMPAT_IPAIRS is default.
I'm just trying to detect the new behavior.