Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update if_lua documents #498

Merged
merged 3 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 52 additions & 14 deletions doc/if_lua.jax
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ Vim の Lua インターフェイス *lua* *Lua*
2. vim モジュール |lua-vim|
3. List ユーザーデータ |lua-list|
4. Dict ユーザーデータ |lua-dict|
5. Funcref ユーザーデータ |lua-funcref|
6. バッファユーザーデータ |lua-buffer|
7. ウィンドウユーザーデータ |lua-window|
8. luaeval 関数 |lua-luaeval|
9. 動的ローディング |lua-dynamic|
5. Blob ユーザーデータ |lua-blob|
6. Funcref ユーザーデータ |lua-funcref|
7. バッファユーザーデータ |lua-buffer|
8. ウィンドウユーザーデータ |lua-window|
9. luaeval() Vim 関数 |lua-luaeval|
10. 動的ローディング |lua-dynamic|

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

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

==============================================================================
5. Funcref ユーザーデータ *lua-funcref*
5. Blob ユーザーデータ *lua-blob*

Blob ユーザーデータは vim の Blob を表します。Blob "b" は以下のプロパティを持
っています。

プロパティ
----------
o "#b" は Blob "b" の要素数。Vim の"len(b)" と同じ。
o "b[k]" は "b" の k 個目の要素を返す。"b" のインデックスは Vim と同じ
で、0 を基準とする。
k 個目の要素を変更するには、単に "b[k] = number" とする。特に、
"b[#b] = number" で末尾にバイトを追加できる。

メソッド
--------
o "b:add(bytes)" は "bytes" を "b" の末尾に追加する。

例:
>
:let b = 0z001122
:lua b = vim.eval('b') -- same 'b'
:lua print(b, b[0], #b)
:lua b[1] = 32
:lua b[#b] = 0x33 -- append a byte to tail
:lua b:add("\x80\x81\xfe\xff")
:echo b
<

==============================================================================
6. Funcref ユーザーデータ *lua-funcref*

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

==============================================================================
6. バッファユーザーデータ *lua-buffer*
7. バッファユーザーデータ *lua-buffer*

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

==============================================================================
7. ウィンドウユーザーデータ *lua-window*
8. ウィンドウユーザーデータ *lua-window*

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

==============================================================================
8. luaeval 関数 *lua-luaeval* *lua-eval*
9. luaeval() Vim 関数 *lua-luaeval* *lua-eval*

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

例: >

Expand All @@ -403,7 +441,7 @@ Note "_A" には "luaeval" の引数が渡されます。Lua の数値、文字


==============================================================================
9. 動的ローディング *lua-dynamic*
10. 動的ローディング *lua-dynamic*

MS-Windows と Unix では Lua ライブラリを動的にロードすることができます。
|+lua/dyn| が |:version| の出力に含まれている時に利用できます。
Expand Down
64 changes: 50 additions & 14 deletions en/if_lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ The Lua Interface to Vim *lua* *Lua*
2. The vim module |lua-vim|
3. List userdata |lua-list|
4. Dict userdata |lua-dict|
5. Funcref userdata |lua-funcref|
6. Buffer userdata |lua-buffer|
7. Window userdata |lua-window|
8. The luaeval function |lua-luaeval|
9. Dynamic loading |lua-dynamic|
5. Blob userdata |lua-blob|
6. Funcref userdata |lua-funcref|
7. Buffer userdata |lua-buffer|
8. Window userdata |lua-window|
9. luaeval() Vim function |lua-luaeval|
10. Dynamic loading |lua-dynamic|

{Vi does not have any of these commands}

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

==============================================================================
5. Funcref userdata *lua-funcref*
5. Blob userdata *lua-blob*

Blob userdata represent vim blobs. A blob "b" has the following properties:

Properties
----------
o "#b" is the length of blob "b", equivalent to "len(b)" in Vim.
o "b[k]" returns the k-th item in "b"; "b" is zero-indexed, as in Vim.
To modify the k-th item, simply do "b[k] = number"; in particular,
"b[#b] = number" can append a byte to tail.

Methods
-------
o "b:add(bytes)" appends "bytes" to the end of "b".

Examples:
>
:let b = 0z001122
:lua b = vim.eval('b') -- same 'b'
:lua print(b, b[0], #b)
:lua b[1] = 32
:lua b[#b] = 0x33 -- append a byte to tail
:lua b:add("\x80\x81\xfe\xff")
:echo b
<

==============================================================================
6. Funcref userdata *lua-funcref*

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

==============================================================================
6. Buffer userdata *lua-buffer*
7. Buffer userdata *lua-buffer*

Buffer userdata represent vim buffers. A buffer userdata "b" has the following
properties and methods:
Expand Down Expand Up @@ -345,7 +381,7 @@ Examples:
<

==============================================================================
7. Window userdata *lua-window*
8. Window userdata *lua-window*

Window objects represent vim windows. A window userdata "w" has the following
properties and methods:
Expand Down Expand Up @@ -377,7 +413,7 @@ Examples:
<

==============================================================================
8. The luaeval function *lua-luaeval* *lua-eval*
9. luaeval() Vim function *lua-luaeval* *lua-eval*

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

Examples: >

Expand All @@ -408,7 +444,7 @@ Examples: >


==============================================================================
9. Dynamic loading *lua-dynamic*
10. Dynamic loading *lua-dynamic*

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