diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-26 14:59:39 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-26 14:59:39 -0300 |
commit | b80077b8f3e27a94c6afa895b41a9f8b52c42e61 (patch) | |
tree | 8a7c21ee0acfed553ef1d92bdfd7b1f728f35a91 /lapi.c | |
parent | e70f275f32a5339a86be6f8b9d08c20cb874b205 (diff) | |
download | lua-b80077b8f3e27a94c6afa895b41a9f8b52c42e61.tar.gz lua-b80077b8f3e27a94c6afa895b41a9f8b52c42e61.tar.bz2 lua-b80077b8f3e27a94c6afa895b41a9f8b52c42e61.zip |
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'.)
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 2 |
1 files changed, 2 insertions, 0 deletions
@@ -329,12 +329,14 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { | |||
329 | o1 = index2value(L, index1); | 329 | o1 = index2value(L, index1); |
330 | o2 = index2value(L, index2); | 330 | o2 = index2value(L, index2); |
331 | if (isvalid(L, o1) && isvalid(L, o2)) { | 331 | if (isvalid(L, o1) && isvalid(L, o2)) { |
332 | ptrdiff_t top = savestack(L, L->top); | ||
332 | switch (op) { | 333 | switch (op) { |
333 | case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break; | 334 | case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break; |
334 | case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break; | 335 | case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break; |
335 | case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break; | 336 | case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break; |
336 | default: api_check(L, 0, "invalid option"); | 337 | default: api_check(L, 0, "invalid option"); |
337 | } | 338 | } |
339 | L->top = restorestack(L, top); | ||
338 | } | 340 | } |
339 | lua_unlock(L); | 341 | lua_unlock(L); |
340 | return i; | 342 | return i; |