Skip to content

Commit fe08df4

Browse files
committed
patch 8.1.0164: luaeval('vim.buffer().name') returns an error
Problem: luaeval('vim.buffer().name') returns an error. Solution: Return an empty string. (Dominique Pelle, closes #3167)
1 parent 2549acf commit fe08df4

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/if_lua.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,9 +1123,11 @@ luaV_buffer_index(lua_State *L)
11231123
{
11241124
const char *s = lua_tostring(L, 2);
11251125
if (strncmp(s, "name", 4) == 0)
1126-
lua_pushstring(L, (char *) b->b_sfname);
1126+
lua_pushstring(L, (b->b_sfname == NULL)
1127+
? "" : (char *) b->b_sfname);
11271128
else if (strncmp(s, "fname", 5) == 0)
1128-
lua_pushstring(L, (char *) b->b_ffname);
1129+
lua_pushstring(L, (b->b_ffname == NULL)
1130+
? "" : (char *) b->b_ffname);
11291131
else if (strncmp(s, "number", 6) == 0)
11301132
lua_pushinteger(L, b->b_fnum);
11311133
/* methods */

src/testdir/test_lua.vim

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,8 @@ endfunc
198198
" Test vim.buffer().name and vim.buffer().fname
199199
func Test_buffer_name()
200200
new
201-
" FIXME: for an unnamed buffer, I would expect
202-
" vim.buffer().name to give an empty string, but
203-
" it returns 0. Is it a bug?
204-
" so this assert_equal is commented out.
205-
" call assert_equal('', luaeval('vim.buffer().name'))
201+
call assert_equal('', luaeval('vim.buffer().name'))
202+
call assert_equal('', luaeval('vim.buffer().fname'))
206203
bwipe!
207204

208205
new Xfoo

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,8 @@ static char *(features[]) =
789789

790790
static int included_patches[] =
791791
{ /* Add new patch number below this line */
792+
/**/
793+
164,
792794
/**/
793795
163,
794796
/**/

0 commit comments

Comments
 (0)