lua-users home
lua-l archive

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


>>>>> "Philippe" == Philippe Verdy <verdyp@gmail.com> writes:

 Philippe>        if ({false, [1] = true})[1] then
 Philippe>              return 'LuaJIT'

 Philippe> I'm not sure that the evaluation of the table constructor is
 Philippe> documented correctly. Here you assign two different boolean
 Philippe> values to the same index [1], this creates a collision and
 Philippe> the evaluation order matters.

The evaluation order matters, and LuaJIT happens to do it the opposite
way to (all) the reference implementations; the manual explicitly states
that the order of evaluation is undefined:

  The order of the assignments in a constructor is undefined. (This
  order would be relevant only when there are repeated keys.)

Hence using it to distinguish LuaJIT from other implementations.

Note that almost everything in this version detection logic is based on
language features that are left undefined. For example the [f()==f()]
test is seeing whether a closure with no upvalues allocates a new object
or not each time, of which the manual says:

  Functions created at different times but with no detectable
  differences may be classified as equal or not (depending on internal
  caching details).

Even the 1/0 parts rely on the implementation using IEEE floats, or at
least some float implementation that has both +/- infinity and +/- 0,
and that for integers in 5.3/5.4 there is no separate -0; if you build
Lua with only integer support, the code will not work.

-- 
Andrew.