Skip to content

Commit 30e98c1

Browse files
authored
Merge pull request #498 from hiromi-mi/update_if_lua_20190402
Update if_lua documents
2 parents 7d0163d + 811e08e commit 30e98c1

File tree

2 files changed

+102
-28
lines changed

2 files changed

+102
-28
lines changed

doc/if_lua.jax

+52-14
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ Vim の Lua インターフェイス *lua* *Lua*
1010
2. vim モジュール |lua-vim|
1111
3. List ユーザーデータ |lua-list|
1212
4. Dict ユーザーデータ |lua-dict|
13-
5. Funcref ユーザーデータ |lua-funcref|
14-
6. バッファユーザーデータ |lua-buffer|
15-
7. ウィンドウユーザーデータ |lua-window|
16-
8. luaeval 関数 |lua-luaeval|
17-
9. 動的ローディング |lua-dynamic|
13+
5. Blob ユーザーデータ |lua-blob|
14+
6. Funcref ユーザーデータ |lua-funcref|
15+
7. バッファユーザーデータ |lua-buffer|
16+
8. ウィンドウユーザーデータ |lua-window|
17+
9. luaeval() Vim 関数 |lua-luaeval|
18+
10. 動的ローディング |lua-dynamic|
1819

1920
{Vi にはこれらのコマンドはありません}
2021

@@ -134,6 +135,14 @@ Lua からは "vim" モジュールを使って Vim を操作します。範囲
134135
:echo luaeval('vim.dict(t)')
135136
:" {'1': 3.141593, '2': v:false,
136137
:" 'say': 'hi'}
138+
<
139+
vim.blob([arg]) 空の Blob、または "arg" が Lua の文字列ならば、
140+
バイト文字列として "arg" と等価な Blob b を返
141+
す。
142+
例: >
143+
:lua s = "12ab\x00\x80\xfe\xff"
144+
:echo luaeval('vim.blob(s)')
145+
:" 0z31326162.0080FEFF
137146
<
138147
vim.funcref({name}) 関数 {name} への関数参照を返します (|Funcref|
139148
を参照) 。その値は Vim の function() と等価で
@@ -251,7 +260,36 @@ list ユーザーデータと同様、dict ユーザーデータは vim の辞
251260
<
252261

253262
==============================================================================
254-
5. Funcref ユーザーデータ *lua-funcref*
263+
5. Blob ユーザーデータ *lua-blob*
264+
265+
Blob ユーザーデータは vim の Blob を表します。Blob "b" は以下のプロパティを持
266+
っています。
267+
268+
プロパティ
269+
----------
270+
o "#b" は Blob "b" の要素数。Vim の"len(b)" と同じ。
271+
o "b[k]" は "b" の k 個目の要素を返す。"b" のインデックスは Vim と同じ
272+
で、0 を基準とする。
273+
k 個目の要素を変更するには、単に "b[k] = number" とする。特に、
274+
"b[#b] = number" で末尾にバイトを追加できる。
275+
276+
メソッド
277+
--------
278+
o "b:add(bytes)" は "bytes" を "b" の末尾に追加する。
279+
280+
例:
281+
>
282+
:let b = 0z001122
283+
:lua b = vim.eval('b') -- same 'b'
284+
:lua print(b, b[0], #b)
285+
:lua b[1] = 32
286+
:lua b[#b] = 0x33 -- append a byte to tail
287+
:lua b:add("\x80\x81\xfe\xff")
288+
:echo b
289+
<
290+
291+
==============================================================================
292+
6. Funcref ユーザーデータ *lua-funcref*
255293

256294
Funcref ユーザーデータは Vim における関数参照変数を表します。"dict" 属性付きで
257295
定義された Vim の関数参照 はその呼び出し時に "self" に適切に辞書が代入できるよ
@@ -284,7 +322,7 @@ Funcref ユーザーデータは Vim における関数参照変数を表しま
284322
<
285323

286324
==============================================================================
287-
6. バッファユーザーデータ *lua-buffer*
325+
7. バッファユーザーデータ *lua-buffer*
288326

289327
バッファユーザーデータは Vim のバッファを表します。バッファユーザーデータ "b"
290328
は以下のプロパティとメソッドを持っています:
@@ -341,7 +379,7 @@ Funcref ユーザーデータは Vim における関数参照変数を表しま
341379
<
342380

343381
==============================================================================
344-
7. ウィンドウユーザーデータ *lua-window*
382+
8. ウィンドウユーザーデータ *lua-window*
345383

346384
ウィンドウオブジェクトは Vim のウィンドウを表します。ウィンドウユーザーデータ
347385
"w" は以下のプロパティとメソッドを持っています:
@@ -373,7 +411,7 @@ Funcref ユーザーデータは Vim における関数参照変数を表しま
373411
<
374412

375413
==============================================================================
376-
8. luaeval 関数 *lua-luaeval* *lua-eval*
414+
9. luaeval() Vim 関数 *lua-luaeval* *lua-eval*
377415

378416
"luaeval" は "vim.eval" と対となる関数で Lua の値を Vim に渡すことができます。
379417
"luaeval" は式文字列と任意の引数を受け取り、式の結果を返します。意味的には次の
@@ -385,10 +423,10 @@ Lua コードと同じです:
385423
return chunk(arg) -- return typval
386424
end
387425
<
388-
Note "_A" には "luaeval" の引数が渡されます。Lua の数値、文字列、リスト、辞書
389-
そして Funcref ユーザーデータはそれぞれの Vim の型に変換されます。ただし、Lua
390-
のブール値は数値に変換されます。リスト、辞書および関数参照以外のユーザーデータ
391-
を含む、それ以外の Lua の型を変換しようとするとエラーが返されます。
426+
Note "_A" には "luaeval" の引数が渡されます。Lua の数値、文字列、リスト、Blob、
427+
辞書そして Funcref ユーザーデータはそれぞれの Vim の型に変換されます。ただし、
428+
Lua のブール値は数値に変換されます。リスト、辞書および関数参照以外のユーザーデ
429+
ータを含む、それ以外の Lua の型を変換しようとするとエラーが返されます。
392430

393431
例: >
394432
@@ -403,7 +441,7 @@ Note "_A" には "luaeval" の引数が渡されます。Lua の数値、文字
403441
404442
405443
==============================================================================
406-
9. 動的ローディング *lua-dynamic*
444+
10. 動的ローディング *lua-dynamic*
407445

408446
MS-Windows と Unix では Lua ライブラリを動的にロードすることができます。
409447
|+lua/dyn||:version| の出力に含まれている時に利用できます。

en/if_lua.txt

+50-14
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)