Skip to content

Commit b782869

Browse files
committed
patch 8.1.1043: Lua interface does not support Blob
Problem: Lua interface does not support Blob. Solution: Add support to Blob. (Ozaki Kiichi, closes #4151)
1 parent 832615b commit b782869

4 files changed

Lines changed: 264 additions & 26 deletions

File tree

runtime/doc/if_lua.txt

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ The Lua Interface to Vim *lua* *Lua*
1010
2. The vim module |lua-vim|
1111
3. List userdata |lua-list|
1212
4. Dict userdata |lua-dict|
13-
5. Funcref userdata |lua-funcref|
14-
6. Buffer userdata |lua-buffer|
15-
7. Window userdata |lua-window|
16-
8. The luaeval function |lua-luaeval|
17-
9. Dynamic loading |lua-dynamic|
13+
5. Blob userdata |lua-blob|
14+
6. Funcref userdata |lua-funcref|
15+
7. Buffer userdata |lua-buffer|
16+
8. Window userdata |lua-window|
17+
9. luaeval() Vim function |lua-luaeval|
18+
10. Dynamic loading |lua-dynamic|
1819

1920
{Vi does not have any of these commands}
2021

@@ -140,6 +141,14 @@ Vim evaluation and command execution, and others.
140141
:echo luaeval('vim.dict(t)')
141142
:" {'1': 3.141593, '2': v:false,
142143
:" 'say': 'hi'}
144+
<
145+
vim.blob([arg]) Returns an empty blob or, if "arg" is a Lua
146+
string, returns a blob b such that b is
147+
equivalent to "arg" as a byte string.
148+
Examples: >
149+
:lua s = "12ab\x00\x80\xfe\xff"
150+
:echo luaeval('vim.blob(s)')
151+
:" 0z31326162.0080FEFF
143152
<
144153
vim.funcref({name}) Returns a Funcref to function {name} (see
145154
|Funcref|). It is equivalent to Vim's
@@ -260,7 +269,34 @@ Examples:
260269
<
261270

262271
==============================================================================
263-
5. Funcref userdata *lua-funcref*
272+
5. Blob userdata *lua-blob*
273+
274+
Blob userdata represent vim blobs. A blob "b" has the following properties:
275+
276+
Properties
277+
----------
278+
o "#b" is the length of blob "b", equivalent to "len(b)" in Vim.
279+
o "b[k]" returns the k-th item in "b"; "b" is zero-indexed, as in Vim.
280+
To modify the k-th item, simply do "b[k] = number"; in particular,
281+
"b[#b] = number" can append a byte to tail.
282+
283+
Methods
284+
-------
285+
o "b:add(bytes)" appends "bytes" to the end of "b".
286+
287+
Examples:
288+
>
289+
:let b = 0z001122
290+
:lua b = vim.eval('b') -- same 'b'
291+
:lua print(b, b[0], #b)
292+
:lua b[1] = 32
293+
:lua b[#b] = 0x33 -- append a byte to tail
294+
:lua b:add("\x80\x81\xfe\xff")
295+
:echo b
296+
<
297+
298+
==============================================================================
299+
6. Funcref userdata *lua-funcref*
264300

265301
Funcref userdata represent funcref variables in Vim. Funcrefs that were
266302
defined with a "dict" attribute need to be obtained as a dictionary key
@@ -293,7 +329,7 @@ Examples:
293329
<
294330

295331
==============================================================================
296-
6. Buffer userdata *lua-buffer*
332+
7. Buffer userdata *lua-buffer*
297333

298334
Buffer userdata represent vim buffers. A buffer userdata "b" has the following
299335
properties and methods:
@@ -345,7 +381,7 @@ Examples:
345381
<
346382

347383
==============================================================================
348-
7. Window userdata *lua-window*
384+
8. Window userdata *lua-window*
349385

350386
Window objects represent vim windows. A window userdata "w" has the following
351387
properties and methods:
@@ -377,7 +413,7 @@ Examples:
377413
<
378414

379415
==============================================================================
380-
8. The luaeval function *lua-luaeval* *lua-eval*
416+
9. luaeval() Vim function *lua-luaeval* *lua-eval*
381417

382418
The (dual) equivalent of "vim.eval" for passing Lua values to Vim is
383419
"luaeval". "luaeval" takes an expression string and an optional argument and
@@ -390,10 +426,10 @@ returns the result of the expression. It is semantically equivalent in Lua to:
390426
end
391427
<
392428
Note that "_A" receives the argument to "luaeval". Lua numbers, strings, and
393-
list, dict, and funcref userdata are converted to their Vim respective types,
394-
while Lua booleans are converted to numbers. An error is thrown if conversion
395-
of any of the remaining Lua types, including userdata other than lists, dicts,
396-
and funcrefs, is attempted.
429+
list, dict, blob, and funcref userdata are converted to their Vim respective
430+
types, while Lua booleans are converted to numbers. An error is thrown if
431+
conversion of any of the remaining Lua types, including userdata other than
432+
lists, dicts, blobs, and funcrefs, is attempted.
397433

398434
Examples: >
399435
@@ -408,7 +444,7 @@ Examples: >
408444
409445
410446
==============================================================================
411-
9. Dynamic loading *lua-dynamic*
447+
10. Dynamic loading *lua-dynamic*
412448

413449
On MS-Windows and Unix the Lua library can be loaded dynamically. The
414450
|:version| output then includes |+lua/dyn|.

0 commit comments

Comments
 (0)