const char *s = (const char *) eap->arg;
luaL_Buffer b;
size_t len;
+ buf_T *was_curbuf = curbuf;
+
if (lua_init() == FAIL) return;
if (u_save(eap->line1 - 1, eap->line2 + 1) == FAIL)
{
lua_replace(L, -2); /* function -> body */
for (l = eap->line1; l <= eap->line2; l++)
{
+ /* Check the line number, the command my have deleted lines. */
+ if (l > curbuf->b_ml.ml_line_count)
+ break;
+
lua_pushvalue(L, -1); /* function */
luaV_pushline(L, curbuf, l); /* current line as arg */
lua_pushinteger(L, l); /* current line number as arg */
luaV_emsg(L);
break;
}
+ /* Catch the command switching to another buffer. */
+ if (curbuf != was_curbuf)
+ break;
if (lua_isstring(L, -1)) /* update line? */
{
#ifdef HAVE_SANDBOX
--- /dev/null
+" Tests for Lua.
+" TODO: move tests from test85.in here.
+
+if !has('lua')
+ finish
+endif
+
+func Test_luado()
+ new
+ call setline(1, ['one', 'two', 'three'])
+ luado vim.command("%d_")
+ bwipe!
+
+ " Check switching to another buffer does not trigger ml_get error.
+ new
+ let wincount = winnr('$')
+ call setline(1, ['one', 'two', 'three'])
+ luado vim.command("new")
+ call assert_equal(wincount + 1, winnr('$'))
+ bwipe!
+ bwipe!
+endfunc