From b80077b8f3e27a94c6afa895b41a9f8b52c42e61 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 26 Jul 2019 14:59:39 -0300 Subject: 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'.) --- lobject.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lobject.c') diff --git a/lobject.c b/lobject.c index b4efae4f..b376ab15 100644 --- a/lobject.c +++ b/lobject.c @@ -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); } } -- cgit v1.2.3-55-g6feb