Skip to content

Commit 219e043

Browse files
committed
luaL_traceback is not supported in Lua 5.1, except for LuaJIT
1 parent 691f016 commit 219e043

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/lua-utils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "config.h"
12
#include "lua-utils.hpp"
23
#include "format.hpp"
34

@@ -158,11 +159,16 @@ static int pcall_error_traceback_handler(lua_State *lua_state)
158159
// wrapper function for lua_pcall to include a stack traceback
159160
int luaX_pcall(lua_State *lua_state, int narg, int nres)
160161
{
162+
// Lua 5.1 doesn't support luaL_traceback, unless LuaJIT is used
163+
#if LUA_VERSION_NUM < 502 && !defined(HAVE_LUAJIT)
164+
int const status = lua_pcall(lua_state, narg, nres, 0);
165+
#else
161166
int const base = lua_gettop(lua_state) - narg; // function index
162167
lua_pushcfunction(lua_state,
163168
pcall_error_traceback_handler); // push message handler
164169
lua_insert(lua_state, base); // put it under function and args
165170
int const status = lua_pcall(lua_state, narg, nres, base);
166171
lua_remove(lua_state, base); // remove message handler from the stack
172+
#endif
167173
return status;
168174
}

0 commit comments

Comments
 (0)