summaryrefslogtreecommitdiffstats
path: root/src/if_lua.c
diff options
context:
space:
mode:
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 4cab3f4b9f..2d02f7c58d 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);