mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.2.1066: Lua arrays are zero based
Problem: Lua arrays are zero based. Solution: Make Lua arrays one based. (Prabir Shrestha, closes #6347) Note: this is not backwards compatible.
This commit is contained in:
12
src/if_lua.c
12
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);
|
||||
|
Reference in New Issue
Block a user