Change in the handling of 'L->top' when calling metamethods

Instead of updating 'L->top' in every place that may call a
metamethod, the metamethod functions themselves (luaT_trybinTM and
luaT_callorderTM) correct the top. (When calling metamethods from
the C API, however, the callers must preserve 'L->top'.)
This commit is contained in:
Roberto Ierusalimschy
2019-07-26 14:59:39 -03:00
parent e70f275f32
commit b80077b8f3
10 changed files with 75 additions and 29 deletions

View File

@@ -127,7 +127,9 @@ void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,
StkId res) {
if (!luaO_rawarith(L, op, p1, p2, s2v(res))) {
/* could not perform raw operation; try metamethod */
ptrdiff_t top = savestack(L, L->top);
luaT_trybinTM(L, p1, p2, res, cast(TMS, (op - LUA_OPADD) + TM_ADD));
L->top = restorestack(L, top);
}
}