Skip to content

Commit

Permalink
Fix luajit/lua compatability issue
Browse files Browse the repository at this point in the history
  • Loading branch information
swarn committed Nov 9, 2020
1 parent 4382f69 commit a3f1dd7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fzy-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ build = {
modules = {
fzy = "src/fzy.lua",
fzy_lua = "src/fzy_lua.lua",
fzy_native = {"src/fzy_native.c", "src/match.c" }
fzy_native = {
sources = { "src/fzy_native.c", "src/match.c" },
defines = { "LUA_COMPAT_5_1" }
}
},

copy_directories = { "test" }
Expand Down
13 changes: 13 additions & 0 deletions src/fzy_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
#include "bonus.h"
#include "match.h"

// 5.1 had lua_objlen(). Luajit is based on 5.1, and is used by neovim.
// 5.2 replaced lua_objlen() with lua_rawlen(). 5.4 is the current version.
//
// The two functions are so close that the Lua headers for later versions
// aliased lua_objlen to lua_rawlen if you defined LUA_COMPAT_5_1, so that old
// code would still work. But my CI tests showed this wasn't always true, and
// lua_objlen was still undefined on some platforms.
//
// So, this is my workaround: for Lua 5.1 and luajit, alias the new function
// to the old one.
#if LUA_VERSION_NUM == 501
#define lua_rawlen(L, i) lua_objlen(L, i)
#endif

static int native_has_match(lua_State * L)
{
Expand Down

0 comments on commit a3f1dd7

Please sign in to comment.