Build LuaJIT w/ table.pack support#1535
Conversation
And also, enable table.pack in our build.
Note that it stores the full length in a "n" field, like old timey Lua, but the # syntactic sugar transparently handles it, and won't return a length truncated at the first nil ;).
|
e.g., (Although, generally, when you pack it's because you want to consume it unpacked as list of arguments, not walk it as a table. If you need to iterate over varargs and you're able to pass them along as-is, select is the way to do that). |
|
LifeHack: there's nothing magical about the Which is why this is often implemented in pure-Lua as: table.pack = function(...)
return { n = select("#", ...), ... }
end |
Should we just enable that? The stuff with break statements and whatnot sounds useful. |
A few of the other things are mildly annoying and would break existing code, though, so, ultimately, maybe, but not right now ;). |
NiLuJe
left a comment
There was a problem hiding this comment.
Reviewed 4 of 4 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @NiLuJe)
c.f., koreader/koreader-base#1535 Note that I left a couple of `{...}` constructs alone in android.lua, because some were then passing the table to `table.concat`, which *will* choke on a nil (and it gets to iterate over it in a packed vararg table).
Well, there is a bit of weird Lua clunk involved nonetheless ;p. |
* Iterate over varargs directly via select if possible * Use table.pack otherwise (koreader/koreader-base#1535). * This allows us to simplify a few Logger calls, as logger now handles nil values.
|
As discovered in koreader/koreader#10346, shit gets interesting when you throw more Sooo, yeah, better rely on the |
Turns out we can't rely on the len operator in all cases, as it may get confused depending on where the `nil`s are, so always use the `n` field instead, as that *is* reliable. Re: koreader#1535
Turns out we can't rely on the len operator in all cases, as it may get confused depending on where the `nil`s are, so always use the `n` field instead, as that *is* reliable. Re: #1535
* Iterate over varargs directly via select if possible * Use table.pack otherwise (koreader/koreader-base#1535). * This allows us to simplify a few Logger calls, as logger now handles nil values.
It's unfortunately behind the Lua 5.2 extensions ifdef in a standard build (possibly because it's so common that it's usually implemented in Lua and monkey-patched over the table metatable?).
But it's trivial and doesn't actually poses an API issue, and it's helpful for a number of our use-cases.
This change is