lua-users home
lua-l archive

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


Sean Conner:

Is this safe?  I ask because I use the to-be-closed slot in a C module
for use with pairs.

Yes, it only is done in Lua code and if the to-be-closed variable is not used.

To be more precise, for this optimization to trigger the loop setup needs to result in:
pairs: next, table, nil, nil
ipairs: ipairsaux, table, integer, nil

In both cases the to-be-closed variable needs to be nil. If a custome setup function would use the next function but supply a to-be-closed variable the optimisation would not trigger.

The linked function would just use the default path since the iteration function is neither next nor ipairsaux and the to-be-closed variable is also not nil.

Regards,
Xmilia