lua-users home
lua-l archive

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


在 2015/5/19 16:50, Philipp Janda 写道:
Hi!

Am 19.05.2015 um 10:33 schröbte Philipp Janda:

Thanks very much! I can confirm that a single explicit return value
fixes the behavior of the test script on Lua 5.1, 5.2, and 5.3 (an empty
`return` is insufficient). Unfortunately, in my original code where I
encountered the problem I already had an explicit return value (and it
still doesn't work except on LuaJIT). I'll try to come up with an
updated test case.

As promised here the updated test case. Interestingly, which local variables get garbled depends on which local variable I return (unfortunately the original code is primarily used on module chunks where I often return the first local I define (`local M = {}`)) ...


as Roberto said, it is due to an optimization in the opcode generator.
before Lua changes(or should I say fixes?) this inconsistent hook behavior,
you can use a simple workaround: just reserve a new stack slot and copy the
to-be-returned local variable there, then return the new one.

in your test script, it is something like:

-------------------------------------
  local function func ()
    local a, b, c, d, e = <...>
    <...>
    local __ret = b
    return __ret
  end
-------------------------------------

--
the nerdy Peng / 书呆彭 / Sent from Thunderbird