lua-users home
lua-l archive

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




On 06/10/15 09:26 PM, Claire Lewis wrote:
How does order factor in, if the code refers to them by name? I think
I'm overlooking something.

In Rio Lua, the order is as they appear. So if a global access appears before any other upvalue access on a function, _ENV is the first upvalue.

local u2, u3, u4, u5
function()
print(u2, u3, u4, u5) -- _ENV is the first upvalue, because "print" is actually "_ENV.print" (or "_ENV['print']")
end

Unless I'm missing something, I don't think this is reliable, that's an implementation detail, and could change any future version, even a patch release of 5.3.

The Lua 5.3 manual states: "Upvalues have no particular order, as they are active through the whole function. They are numbered in an arbitrary order."

I'd probably recommend finding a different way to achieve this for a public module.

- Claire


But it's resonable to assume they're consistent between dump and reload.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.