Skip to content

Commit 2103e1c

Browse files
committed
The function push_val in Lua.xs was only checking for reference types (like code references) if the underlying Perl variable was an integer, which is incorrect. It needs to check for references before it checks for any other scalar type.
1 parent 3721a3f commit 2103e1c

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

Lua.xs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -221,43 +221,42 @@ void
221221
push_val (lua_State *L, SV *val) {
222222

223223
if (is_lua_nil(val)) {
224-
lua_pushnil(L);
225-
return;
224+
lua_pushnil(L);
225+
return;
226226
}
227227

228228
if (!val || val == &PL_sv_undef || !SvOK(val)) {
229-
if (!UNDEF || UNDEF == &PL_sv_undef || !SvOK(UNDEF))
230-
lua_pushnil(L);
231-
else
232-
/* otherwise we can safely call push_val again
233-
* because Inline::Lua::_undef is defined */
234-
push_val(L, UNDEF);
235-
return;
229+
if (!UNDEF || UNDEF == &PL_sv_undef || !SvOK(UNDEF))
230+
lua_pushnil(L);
231+
else
232+
push_val(L, UNDEF);
233+
return;
234+
}
235+
236+
if (SvROK(val)) {
237+
push_ref(L, val);
238+
return;
236239
}
237240

238241
switch (SvTYPE(val)) {
239-
case SVt_IV:
240-
if(SvROK(val)) {
241-
push_ref(L, val);
242-
} else {
242+
case SVt_IV:
243243
#if LUA_VERSION_NUM < 503
244-
lua_pushnumber(L, (lua_Number)SvIV(val));
244+
lua_pushnumber(L, (lua_Number)SvIV(val));
245245
#else
246-
lua_pushinteger(L, (lua_Integer)SvIV(val));
246+
lua_pushinteger(L, (lua_Integer)SvIV(val));
247247
#endif
248+
return;
249+
case SVt_NV:
250+
lua_pushnumber(L, (lua_Number)SvNV(val));
251+
return;
252+
case SVt_PV: case SVt_PVIV:
253+
case SVt_PVNV: case SVt_PVMG:
254+
{
255+
STRLEN n_a;
256+
char *cval = SvPV(val, n_a);
257+
lua_pushlstring(L, cval, n_a);
258+
return;
248259
}
249-
return;
250-
case SVt_NV:
251-
lua_pushnumber(L, (lua_Number)SvNV(val));
252-
return;
253-
case SVt_PV: case SVt_PVIV:
254-
case SVt_PVNV: case SVt_PVMG:
255-
{
256-
STRLEN n_a;
257-
char *cval = SvPV(val, n_a);
258-
lua_pushlstring(L, cval, n_a);
259-
return;
260-
}
261260
}
262261
}
263262

0 commit comments

Comments
 (0)