lua-users home
lua-l archive

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

于 2012-6-9 3:20, Luiz Henrique de Figueiredo 写道:
Lua 5.2.1 (rc4) is now available at

MD5	ae08f641b45d737d12d30291a5e5f6e3  -
SHA1	6bb1b0a39b6a5484b71a83323c690154f86b2021  -

Lua 5.2.1 fixes all bugs listed in .

Lua 5.2.1 also fixes several other minors glitches and includes
a revised reference manual.

The complete diffs from rc3 to rc4 are available at

We thank everyone for their feedback on Lua 5.2 till now.

All feedback welcome. Thanks.

Thank you all the Lua team.

I noticed the yielding hook problem is fixed, by marking the last yielding in hook and
not to call the hook if the hook yielded last time.

I just thought on this problem yesterday too, and have figured out some way to fix it.
I would share my idea here.

I suppose the key point is how to check the condition whether should the hook be called.

current implementation checks a downward counter as the condition of LUA_MASKCOUNT hook,
and checks the line numbers of the `npc' and `oldpc' for the consition of LUA_MASKLINE hook.

while my method is just remember the position where the last hook is called.

for the LUA_MASKCOUNT, I use an upward counter (without reset/wraparound) to recored
how many instructions has already been executed, initiated to 0. and I use another field to record
where the hook is called last time, initiated to some value describe below.

every time the hook get called, the instruction counter is copied to the last hook position. and this makes
the condition checking quite simple: just substract the last hook position from the current instruction counter,
to see if it is equal to (or maybe greater or equal to?) the *step* (or base hook count).

then we can adjust the initial value of the last hook position to have different hook semantics.
setting it to the negated base hook count makes the hook get count *before* every step instructions;
or setting it to 0 makes the hook get count *after* every step instructions. (or maybe some other value?)

the LUA_MASKLINE situation is almostly the same, with the differences where,
1) we record the line number (instead of the instruction counter) where the hook last time get called;
2) we don't need a counter(to count the lines already executed), since Lua already tracked the line information, and
3) we compare the last hook position and the current/next line number for inequality(instead of substract one from another)

really simple, right?
My thinking is not to differ whether the last hook yielded or not, but to make sure the hook is always called at `the correct time'.

And I am not indicating my idea is better. I am not even sure this won't break other things, after all I feel I still dont have that
deep understanding of all the source code.

In fact, I am just going to post this later in today, to get some feedbacks and suggestions, when I found the rc4 already included it.

Thank you.