Skip to content

Commit f2384ec

Browse files
Darleleta-denoyelle
authored andcommitted
CLEANUP: hlua: simplify ambiguous lua_insert() usage in hlua_ctx_resume()
'lua_insert(lua->T, -lua_gettop(lua->T))' is actually used to rotate the top value with the bottom one, thus the code was overkill and the comment was actually misleading, let's fix that by using explicit equivalent form (absolute index). It may be backported with 5508db9 ("BUG/MINOR: hlua: fix unsafe lua_tostring() usage with empty stack") to all stable versions to ease code maintenance. (cherry picked from commit 2bde0d6) Signed-off-by: Amaury Denoyelle <[email protected]>
1 parent 8b8fb77 commit f2384ec

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/hlua.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,8 +2087,8 @@ static enum hlua_exec hlua_ctx_resume(struct hlua *lua, int yield_allowed)
20872087
hlua_pushfstring_safe(lua->T, "[state-id %d] unknown runtime error from %s",
20882088
lua->state_id, trace);
20892089

2090-
/* Move the error msg at the top and then empty the stack except last msg */
2091-
lua_insert(lua->T, -lua_gettop(lua->T));
2090+
/* Move the error msg at the bottom and then empty the stack except last msg */
2091+
lua_insert(lua->T, 1);
20922092
lua_settop(lua->T, 1);
20932093
ret = HLUA_E_ERRMSG;
20942094
break;
@@ -2113,8 +2113,8 @@ static enum hlua_exec hlua_ctx_resume(struct hlua *lua, int yield_allowed)
21132113
hlua_pushfstring_safe(lua->T, "[state-id %d] message handler error",
21142114
lua->state_id);
21152115

2116-
/* Move the error msg at the top and then empty the stack except last msg */
2117-
lua_insert(lua->T, -lua_gettop(lua->T));
2116+
/* Move the error msg at the bottom and then empty the stack except last msg */
2117+
lua_insert(lua->T, 1);
21182118
lua_settop(lua->T, 1);
21192119
ret = HLUA_E_ERRMSG;
21202120
break;

0 commit comments

Comments
 (0)