Patch 8.2.2733
Problem: Detecting Lua version is not reliable.
Solution: Add "vim.lua_version". (Ozaki Kiichi, closes #8080)
Files: runtime/doc/if_lua.txt, ci/if_ver-1.vim, src/if_lua.c,
src/testdir/test_lua.vim
*** ../vim-8.2.2732/runtime/doc/if_lua.txt 2021-01-31 17:02:06.254490174
+0100
--- runtime/doc/if_lua.txt 2021-04-07 20:10:27.651979141 +0200
***************
*** 208,213 ****
--- 208,215 ----
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*
*** ../vim-8.2.2732/ci/if_ver-1.vim 2020-01-21 22:13:23.050546956 +0100
--- ci/if_ver-1.vim 2021-04-07 20:05:46.128931831 +0200
***************
*** 6,12 ****
echo "*** Interface versions ***\n"
echo 'Lua:'
! PrintVer lua print(_VERSION)
echo 'MzScheme:'
PrintVer mzscheme (display (version))
--- 6,12 ----
echo "*** Interface versions ***\n"
echo 'Lua:'
! PrintVer lua print(vim.lua_version, jit and "(LuaJIT)" or "")
echo 'MzScheme:'
PrintVer mzscheme (display (version))
*** ../vim-8.2.2732/src/if_lua.c 2021-03-08 19:50:20.452224854 +0100
--- src/if_lua.c 2021-04-07 20:05:46.128931831 +0200
***************
*** 24,29 ****
--- 24,35 ----
#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,2092 ****
--- 2093,2099 ----
{"open", luaV_open},
{"type", luaV_type},
{"call", luaV_call},
+ {"lua_version", NULL},
{NULL, NULL}
};
***************
*** 2168,2173 ****
--- 2175,2194 ----
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,2303 ****
--- 2319,2326 ----
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);
*** ../vim-8.2.2732/src/testdir/test_lua.vim 2021-04-03 17:18:47.296936719
+0200
--- src/testdir/test_lua.vim 2021-04-07 20:05:46.128931831 +0200
***************
*** 13,30 ****
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:lua_53_or_later = 0
let s:lua_543_or_later = 0
if (s:major == 5 && s:minor >= 3) || s:major > 5
--- 13,19 ----
CheckFeature float
" Depending on the lua version, the error messages are different.
! 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
*** ../vim-8.2.2732/src/version.c 2021-04-07 19:42:53.966200626 +0200
--- src/version.c 2021-04-07 20:07:29.688575442 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2733,
/**/
--
If your nose runs, and your feet smell, you might be upside down.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202104071812.137ICbaD3666761%40masaka.moolenaar.net.