summaryrefslogtreecommitdiff
path: root/src/if_lua.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-06-27 12:32:57 +0200
committerBram Moolenaar <Bram@vim.org>2020-06-27 12:32:57 +0200
commitbd84617d1a6766efd59c94aabebb044bef805b99 (patch)
tree57fc315043f9e042b25d78e5c7ebd39ff5b3ad8d /src/if_lua.c
parent7147820cb978f5b179cfec2f9d8b7774e28d43e0 (diff)
downloadvim-git-bd84617d1a6766efd59c94aabebb044bef805b99.tar.gz
patch 8.2.1066: Lua arrays are zero basedv8.2.1066
Problem: Lua arrays are zero based. Solution: Make Lua arrays one based. (Prabir Shrestha, closes #6347) Note: this is not backwards compatible.
Diffstat (limited to 'src/if_lua.c')
-rw-r--r--src/if_lua.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/if_lua.c b/src/if_lua.c
index 4cab3f4b9..2d02f7c58 100644
--- a/src/if_lua.c
+++ b/src/if_lua.c
@@ -871,7 +871,13 @@ luaV_list_index(lua_State *L)
list_T *l = luaV_unbox(L, luaV_List, 1);
if (lua_isnumber(L, 2)) // list item?
{
- listitem_T *li = list_find(l, (long) luaL_checkinteger(L, 2));
+ long n = (long) luaL_checkinteger(L, 2);
+ listitem_T *li;
+
+ // Lua array index starts with 1 while Vim uses 0, subtract 1 to
+ // normalize.
+ n -= 1;
+ li = list_find(l, n);
if (li == NULL)
lua_pushnil(L);
else
@@ -900,6 +906,10 @@ luaV_list_newindex(lua_State *L)
list_T *l = luaV_unbox(L, luaV_List, 1);
long n = (long) luaL_checkinteger(L, 2);
listitem_T *li;
+
+ // Lua array index starts with 1 while Vim uses 0, subtract 1 to normalize.
+ n -= 1;
+
if (l->lv_lock)
luaL_error(L, "list is locked");
li = list_find(l, n);