summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-04-07 20:11:12 +0200
committerBram Moolenaar <Bram@vim.org>2021-04-07 20:11:12 +0200
commit125ed2745c0a0570c1f81f249aebb023b2deef1b (patch)
tree10d0d8af435712f4f74142ef9988fd007ef6717d
parente5b0b98a90acf420bb611fc99534982c98d0645b (diff)
downloadvim-git-125ed2745c0a0570c1f81f249aebb023b2deef1b.tar.gz
patch 8.2.2733: detecting Lua version is not reliablev8.2.2733
Problem: Detecting Lua version is not reliable. Solution: Add "vim.lua_version". (Ozaki Kiichi, closes #8080)
-rw-r--r--ci/if_ver-1.vim2
-rw-r--r--runtime/doc/if_lua.txt2
-rw-r--r--src/if_lua.c23
-rw-r--r--src/testdir/test_lua.vim13
-rw-r--r--src/version.c2
5 files changed, 29 insertions, 13 deletions
diff --git a/ci/if_ver-1.vim b/ci/if_ver-1.vim
index d5b2bb68c..adc40a7cb 100644
--- a/ci/if_ver-1.vim
+++ b/ci/if_ver-1.vim
@@ -6,7 +6,7 @@ if 1
echo "*** Interface versions ***\n"
echo 'Lua:'
- PrintVer lua print(_VERSION)
+ PrintVer lua print(vim.lua_version, jit and "(LuaJIT)" or "")
echo 'MzScheme:'
PrintVer mzscheme (display (version))
diff --git a/runtime/doc/if_lua.txt b/runtime/doc/if_lua.txt
index b55699698..b7ccb04c5 100644
--- a/runtime/doc/if_lua.txt
+++ b/runtime/doc/if_lua.txt
@@ -208,6 +208,8 @@ Vim evaluation and command execution, and others.
created on demand. Example: >
:lua print(vim.fn.has('timers'))
<
+ vim.lua_version The Lua version Vim was compiled with, in the
+ form {major}.{minor}.{patch}, e.g. "5.1.4".
==============================================================================
3. List userdata *lua-list*
diff --git a/src/if_lua.c b/src/if_lua.c
index abcd850b3..c19244fae 100644
--- a/src/if_lua.c
+++ b/src/if_lua.c
@@ -24,6 +24,12 @@
#define LUAVIM_EVALNAME "luaeval"
#define LUAVIM_EVALHEADER "local _A=select(1,...) return "
+#ifdef LUA_RELEASE
+# define LUAVIM_VERSION LUA_RELEASE
+#else
+# define LUAVIM_VERSION LUA_VERSION
+#endif
+
typedef buf_T *luaV_Buffer;
typedef win_T *luaV_Window;
typedef dict_T *luaV_Dict;
@@ -2087,6 +2093,7 @@ static const luaL_Reg luaV_module[] = {
{"open", luaV_open},
{"type", luaV_type},
{"call", luaV_call},
+ {"lua_version", NULL},
{NULL, NULL}
};
@@ -2168,6 +2175,20 @@ luaV_setref(lua_State *L)
return 1;
}
+ static int
+luaV_pushversion(lua_State *L)
+{
+ int major = 0;
+ int minor = 0;
+ int patch = 0;
+ char s[16];
+
+ sscanf(LUAVIM_VERSION, "Lua %d.%d.%d", &major, &minor, &patch);
+ vim_snprintf(s, sizeof(s), "%d.%d.%d", major, minor, patch);
+ lua_pushstring(L, s);
+ return 0;
+}
+
#define LUA_VIM_FN_CODE \
"vim.fn = setmetatable({}, {\n"\
" __index = function (t, key)\n"\
@@ -2298,6 +2319,8 @@ luaopen_vim(lua_State *L)
lua_newtable(L); // vim table
lua_pushvalue(L, 1); // cache table
luaV_openlib(L, luaV_module, 1);
+ luaV_pushversion(L);
+ lua_setfield(L, -2, "lua_version");
lua_setglobal(L, LUAVIM_NAME);
// custom code
(void)luaL_dostring(L, LUA_VIM_FN_CODE);
diff --git a/src/testdir/test_lua.vim b/src/testdir/test_lua.vim
index b9ef0d236..c33056319 100644
--- a/src/testdir/test_lua.vim
+++ b/src/testdir/test_lua.vim
@@ -13,18 +13,7 @@ CheckFeature lua
CheckFeature float
" Depending on the lua version, the error messages are different.
-let s:luaver = split(split(systemlist('lua -v')[0], ' ')[1], '\.')
-if len(s:luaver) < 3
- " Didn't get something that looks like a version, use _VERSION.
- let s:luaver = split(split(luaeval('_VERSION'), ' ')[1], '\.')
-endif
-let s:major = str2nr(s:luaver[0])
-let s:minor = str2nr(s:luaver[1])
-if len(s:luaver) >= 3
- let s:patch = str2nr(s:luaver[2])
-else
- let s:patch = 0
-endif
+let [s:major, s:minor, s:patch] = luaeval('vim.lua_version')->split('\.')->map({-> str2nr(v:val)})
let s:lua_53_or_later = 0
let s:lua_543_or_later = 0
if (s:major == 5 && s:minor >= 3) || s:major > 5
diff --git a/src/version.c b/src/version.c
index 0bf907354..58d6d9f17 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2733,
+/**/
2732,
/**/
2731,