lua-users home
lua-l archive

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




On 2018-12-20 10:19 p.m., Jonathan Goble wrote:
On Thu, Dec 20, 2018 at 6:56 PM Gabriel Bertilson <arboreous.philologist@gmail.com <mailto:arboreous.philologist@gmail.com>> wrote:

    I went with

    if (0 < i && i <= 256 && !lua_isnone(L, lua_upvalueindex(i))) { ... }


But is this even necessary? i originates from the third return value from the generator function, which starts at 0 and only increments from there. Additionally, MAXUPVAL is 255, so itervarargs cannot be called with a second argument greater than 255, which means that i cannot be greater than 256 in the first place. In short, i is already guaranteed to be between 1 and 256 inclusive, and therefore guaranteed to be an acceptable argument to lua_upvalueindex, in the first place.

So unless I'm missing something here (I admit my Lua/C API skills are rusty), the if condition can be reduced back to just the original !lua_isnone call.

local a,b,c = generator_fn()
a(b,-1)
a(b,1024)

?