Mercurial > vim
annotate runtime/doc/if_lua.txt @ 30839:942f1b3bc694 v9.0.0754
patch 9.0.0754: 'indentexpr' overrules lisp indenting in one situation
Commit: https://github.com/vim/vim/commit/a79b35b5781ae770334cec781d17fec3875f8108
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Oct 15 10:49:36 2022 +0100
patch 9.0.0754: 'indentexpr' overrules lisp indenting in one situation
Problem: 'indentexpr' overrules lisp indenting in one situation.
Solution: Add "else" to keep the lisp indent. (issue https://github.com/vim/vim/issues/11327)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 15 Oct 2022 12:00:03 +0200 |
parents | f8116058ca76 |
children | 4635e43f2c6f |
rev | line source |
---|---|
29314 | 1 *if_lua.txt* For Vim version 9.0. Last change: 2021 Aug 06 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
3 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
4 VIM REFERENCE MANUAL by Luis Carvalho |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
5 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
6 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
7 The Lua Interface to Vim *lua* *Lua* |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
8 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
9 1. Commands |lua-commands| |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
10 2. The vim module |lua-vim| |
3450 | 11 3. List userdata |lua-list| |
12 4. Dict userdata |lua-dict| | |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
13 5. Blob userdata |lua-blob| |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
14 6. Funcref userdata |lua-funcref| |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
15 7. Buffer userdata |lua-buffer| |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
16 8. Window userdata |lua-window| |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
17 9. luaeval() Vim function |lua-luaeval| |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
18 10. Dynamic loading |lua-dynamic| |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
19 |
16553
0e473e9e70c2
patch 8.1.1280: remarks about functionality not in Vi clutters the help
Bram Moolenaar <Bram@vim.org>
parents:
16076
diff
changeset
|
20 {only available when Vim was compiled with the |+lua| feature} |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
21 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
22 ============================================================================== |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
23 1. Commands *lua-commands* |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
24 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
25 *:lua* |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
26 :[range]lua {chunk} |
16553
0e473e9e70c2
patch 8.1.1280: remarks about functionality not in Vi clutters the help
Bram Moolenaar <Bram@vim.org>
parents:
16076
diff
changeset
|
27 Execute Lua chunk {chunk}. |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
28 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
29 Examples: |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
30 > |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
31 :lua print("Hello, Vim!") |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
32 :lua local curbuf = vim.buffer() curbuf[7] = "line #7" |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
33 < |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
34 |
20045
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
18879
diff
changeset
|
35 :[range]lua << [trim] [{endmarker}] |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
36 {script} |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
37 {endmarker} |
16553
0e473e9e70c2
patch 8.1.1280: remarks about functionality not in Vi clutters the help
Bram Moolenaar <Bram@vim.org>
parents:
16076
diff
changeset
|
38 Execute Lua script {script}. |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
39 Note: This command doesn't work when the Lua |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
40 feature wasn't compiled in. To avoid errors, see |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
41 |script-here|. |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
42 |
17571 | 43 If [endmarker] is omitted from after the "<<", a dot '.' must be used after |
20045
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
18879
diff
changeset
|
44 {script}, like for the |:append| and |:insert| commands. Refer to |
04ef2ccf2519
patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents:
18879
diff
changeset
|
45 |:let-heredoc| for more information. |
17571 | 46 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
47 This form of the |:lua| command is mainly useful for including Lua code |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
48 in Vim scripts. |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
49 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
50 Example: |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
51 > |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
52 function! CurrentLineInfo() |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
53 lua << EOF |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
54 local linenr = vim.window().line |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
55 local curline = vim.buffer()[linenr] |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
56 print(string.format("Current line [%d] has %d chars", |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
57 linenr, #curline)) |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
58 EOF |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
59 endfunction |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
60 < |
10153
715d6c5707b8
commit https://github.com/vim/vim/commit/abd468ed0fbcba391e7833feeaa7de3ced841455
Christian Brabandt <cb@256bit.org>
parents:
8673
diff
changeset
|
61 To see what version of Lua you have: > |
715d6c5707b8
commit https://github.com/vim/vim/commit/abd468ed0fbcba391e7833feeaa7de3ced841455
Christian Brabandt <cb@256bit.org>
parents:
8673
diff
changeset
|
62 :lua print(_VERSION) |
715d6c5707b8
commit https://github.com/vim/vim/commit/abd468ed0fbcba391e7833feeaa7de3ced841455
Christian Brabandt <cb@256bit.org>
parents:
8673
diff
changeset
|
63 |
715d6c5707b8
commit https://github.com/vim/vim/commit/abd468ed0fbcba391e7833feeaa7de3ced841455
Christian Brabandt <cb@256bit.org>
parents:
8673
diff
changeset
|
64 If you use LuaJIT you can also use this: > |
715d6c5707b8
commit https://github.com/vim/vim/commit/abd468ed0fbcba391e7833feeaa7de3ced841455
Christian Brabandt <cb@256bit.org>
parents:
8673
diff
changeset
|
65 :lua print(jit.version) |
715d6c5707b8
commit https://github.com/vim/vim/commit/abd468ed0fbcba391e7833feeaa7de3ced841455
Christian Brabandt <cb@256bit.org>
parents:
8673
diff
changeset
|
66 < |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
67 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
68 *:luado* |
3465 | 69 :[range]luado {body} Execute Lua function "function (line, linenr) {body} |
70 end" for each line in the [range], with the function | |
71 argument being set to the text of each line in turn, | |
72 without a trailing <EOL>, and the current line number. | |
73 If the value returned by the function is a string it | |
74 becomes the text of the line in the current turn. The | |
75 default for [range] is the whole file: "1,$". | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
76 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
77 Examples: |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
78 > |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
79 :luado return string.format("%s\t%d", line:reverse(), #line) |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
80 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
81 :lua require"lpeg" |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
82 :lua -- balanced parenthesis grammar: |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
83 :lua bp = lpeg.P{ "(" * ((1 - lpeg.S"()") + lpeg.V(1))^0 * ")" } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
84 :luado if bp:match(line) then return "-->\t" .. line end |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
85 < |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
86 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
87 *:luafile* |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
88 :[range]luafile {file} |
16553
0e473e9e70c2
patch 8.1.1280: remarks about functionality not in Vi clutters the help
Bram Moolenaar <Bram@vim.org>
parents:
16076
diff
changeset
|
89 Execute Lua script in {file}. |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
90 The whole argument is used as a single file name. |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
91 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
92 Examples: |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
93 > |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
94 :luafile script.lua |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
95 :luafile % |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
96 < |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
97 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
98 All these commands execute a Lua chunk from either the command line (:lua and |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
99 :luado) or a file (:luafile) with the given line [range]. Similarly to the Lua |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
100 interpreter, each chunk has its own scope and so only global variables are |
3450 | 101 shared between command calls. All Lua default libraries are available. In |
102 addition, Lua "print" function has its output redirected to the Vim message | |
103 area, with arguments separated by a white space instead of a tab. | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
104 |
2337
a0f87fc19d1d
Better conceal in help. (partly by Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
105 Lua uses the "vim" module (see |lua-vim|) to issue commands to Vim |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
106 and manage buffers (|lua-buffer|) and windows (|lua-window|). However, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
107 procedures that alter buffer content, open new buffers, and change cursor |
2337
a0f87fc19d1d
Better conceal in help. (partly by Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
108 position are restricted when the command is executed in the |sandbox|. |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
109 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
110 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
111 ============================================================================== |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
112 2. The vim module *lua-vim* |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
113 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
114 Lua interfaces Vim through the "vim" module. The first and last line of the |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
115 input range are stored in "vim.firstline" and "vim.lastline" respectively. The |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
116 module also includes routines for buffer, window, and current line queries, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
117 Vim evaluation and command execution, and others. |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
118 |
4911 | 119 vim.list([arg]) Returns an empty list or, if "arg" is a Lua |
120 table with numeric keys 1, ..., n (a | |
121 "sequence"), returns a list l such that l[i] = | |
122 arg[i] for i = 1, ..., n (see |List|). | |
123 Non-numeric keys are not used to initialize | |
124 the list. See also |lua-eval| for conversion | |
125 rules. Example: > | |
14298
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
14239
diff
changeset
|
126 :lua t = {math.pi, false, say = 'hi'} |
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
14239
diff
changeset
|
127 :echo luaeval('vim.list(t)') |
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
14239
diff
changeset
|
128 :" [3.141593, v:false], 'say' is ignored |
4911 | 129 < |
130 vim.dict([arg]) Returns an empty dictionary or, if "arg" is a | |
131 Lua table, returns a dict d such that d[k] = | |
132 arg[k] for all string keys k in "arg" (see | |
133 |Dictionary|). Number keys are converted to | |
134 strings. Keys that are not strings are not | |
135 used to initialize the dictionary. See also | |
136 |lua-eval| for conversion rules. Example: > | |
14298
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
14239
diff
changeset
|
137 :lua t = {math.pi, false, say = 'hi'} |
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
14239
diff
changeset
|
138 :echo luaeval('vim.dict(t)') |
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
14239
diff
changeset
|
139 :" {'1': 3.141593, '2': v:false, |
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
14239
diff
changeset
|
140 :" 'say': 'hi'} |
4911 | 141 < |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
142 vim.blob([arg]) Returns an empty blob or, if "arg" is a Lua |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
143 string, returns a blob b such that b is |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
144 equivalent to "arg" as a byte string. |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
145 Examples: > |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
146 :lua s = "12ab\x00\x80\xfe\xff" |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
147 :echo luaeval('vim.blob(s)') |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
148 :" 0z31326162.0080FEFF |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
149 < |
4911 | 150 vim.funcref({name}) Returns a Funcref to function {name} (see |
14298
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
14239
diff
changeset
|
151 |Funcref|). It is equivalent to Vim's |
4a588e3afd4a
Update runtime files, add Danish translations.
Christian Brabandt <cb@256bit.org>
parents:
14239
diff
changeset
|
152 function(). |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
153 |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
154 vim.buffer([arg]) If "arg" is a number, returns buffer with |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
155 number "arg" in the buffer list or, if "arg" |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
156 is a string, returns buffer whose full or short |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
157 name is "arg". In both cases, returns 'nil' |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
158 (nil value, not string) if the buffer is not |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
159 found. Otherwise, if "toboolean(arg)" is |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
160 'true' returns the first buffer in the buffer |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
161 list or else the current buffer. |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
162 |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
163 vim.window([arg]) If "arg" is a number, returns window with |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
164 number "arg" or 'nil' (nil value, not string) |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
165 if not found. Otherwise, if "toboolean(arg)" |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
166 is 'true' returns the first window or else the |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
167 current window. |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
168 |
3450 | 169 vim.type({arg}) Returns the type of {arg}. It is equivalent to |
170 Lua's "type" function, but returns "list", | |
4911 | 171 "dict", "funcref", "buffer", or "window" if |
172 {arg} is a list, dictionary, funcref, buffer, | |
173 or window, respectively. Examples: > | |
3450 | 174 :lua l = vim.list() |
175 :lua print(type(l), vim.type(l)) | |
14239
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
13963
diff
changeset
|
176 :" list |
3450 | 177 < |
25527
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
178 vim.command({cmds}) Executes one or more lines of Ex-mode commands |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
179 in {cmds}. |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
180 Examples: > |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
181 :lua vim.command"set tw=60" |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
182 :lua vim.command"normal ddp" |
25527
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
183 lua << trim END |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
184 vim.command([[ |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
185 new Myfile.js |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
186 call search('start') |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
187 ]]) |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
188 END |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
189 < |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
190 vim.eval({expr}) Evaluates expression {expr} (see |expression|), |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
191 converts the result to Lua, and returns it. |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
192 Vim strings and numbers are directly converted |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
193 to Lua strings and numbers respectively. Vim |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
194 lists and dictionaries are converted to Lua |
3450 | 195 userdata (see |lua-list| and |lua-dict|). |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
196 Examples: > |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
197 :lua tw = vim.eval"&tw" |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
198 :lua print(vim.eval"{'a': 'one'}".a) |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
199 < |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
200 vim.line() Returns the current line (without the trailing |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
201 <EOL>), a Lua string. |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
202 |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
203 vim.beep() Beeps. |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
204 |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
205 vim.open({fname}) Opens a new buffer for file {fname} and |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
206 returns it. Note that the buffer is not set as |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
207 current. |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
208 |
21676 | 209 vim.call({name} [, {args}]) |
210 Proxy to call Vim function named {name} with | |
20441
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
211 arguments {args}. Example: > |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
212 :lua print(vim.call('has', 'timers')) |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
213 < |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
214 vim.fn Proxy to call Vim functions. Proxy methods are |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
215 created on demand. Example: > |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
216 :lua print(vim.fn.has('timers')) |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
217 < |
24385
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
21676
diff
changeset
|
218 vim.lua_version The Lua version Vim was compiled with, in the |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
21676
diff
changeset
|
219 form {major}.{minor}.{patch}, e.g. "5.1.4". |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
220 |
25527
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
221 vim.version() Returns a Lua table with the Vim version. |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
222 The table will have the following keys: |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
223 major - major Vim version. |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
224 minor - minor Vim version. |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
225 patch - latest patch included. |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
226 |
25503
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
227 *lua-vim-variables* |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
228 The Vim editor global dictionaries |g:| |w:| |b:| |t:| |v:| can be accessed |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
229 from Lua conveniently and idiomatically by referencing the `vim.*` Lua tables |
25881
2ee0425960fe
patch 8.2.3474: some places use "Vimscript" instead of "Vim script"
Bram Moolenaar <Bram@vim.org>
parents:
25619
diff
changeset
|
230 described below. In this way you can easily read and modify global Vim script |
25503
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
231 variables from Lua. |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
232 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
233 Example: > |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
234 |
25881
2ee0425960fe
patch 8.2.3474: some places use "Vimscript" instead of "Vim script"
Bram Moolenaar <Bram@vim.org>
parents:
25619
diff
changeset
|
235 vim.g.foo = 5 -- Set the g:foo Vim script variable. |
2ee0425960fe
patch 8.2.3474: some places use "Vimscript" instead of "Vim script"
Bram Moolenaar <Bram@vim.org>
parents:
25619
diff
changeset
|
236 print(vim.g.foo) -- Get and print the g:foo Vim script variable. |
2ee0425960fe
patch 8.2.3474: some places use "Vimscript" instead of "Vim script"
Bram Moolenaar <Bram@vim.org>
parents:
25619
diff
changeset
|
237 vim.g.foo = nil -- Delete (:unlet) the Vim script variable. |
25503
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
238 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
239 vim.g *vim.g* |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
240 Global (|g:|) editor variables. |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
241 Key with no value returns `nil`. |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
242 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
243 vim.b *vim.b* |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
244 Buffer-scoped (|b:|) variables for the current buffer. |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
245 Invalid or unset key returns `nil`. |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
246 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
247 vim.w *vim.w* |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
248 Window-scoped (|w:|) variables for the current window. |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
249 Invalid or unset key returns `nil`. |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
250 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
251 vim.t *vim.t* |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
252 Tabpage-scoped (|t:|) variables for the current tabpage. |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
253 Invalid or unset key returns `nil`. |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
254 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
255 vim.v *vim.v* |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
256 |v:| variables. |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
257 Invalid or unset key returns `nil`. |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
24387
diff
changeset
|
258 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
259 ============================================================================== |
3450 | 260 3. List userdata *lua-list* |
261 | |
262 List userdata represent vim lists, and the interface tries to follow closely | |
263 Vim's syntax for lists. Since lists are objects, changes in list references in | |
264 Lua are reflected in Vim and vice-versa. A list "l" has the following | |
265 properties and methods: | |
266 | |
21030
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21006
diff
changeset
|
267 NOTE: In patch 8.2.1066 array indexes were changed from zero-based to |
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21006
diff
changeset
|
268 one-based. You can check with: > |
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21006
diff
changeset
|
269 if has("patch-8.2.1066") |
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21006
diff
changeset
|
270 |
3450 | 271 Properties |
272 ---------- | |
273 o "#l" is the number of items in list "l", equivalent to "len(l)" | |
274 in Vim. | |
21030
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21006
diff
changeset
|
275 o "l[k]" returns the k-th item in "l"; "l" is one-indexed, as in Lua. |
3450 | 276 To modify the k-th item, simply do "l[k] = newitem"; in |
21060
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
277 particular, "l[k] = nil" removes the k-th item from "l". Item can |
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
278 be added to the end of the list by "l[#l + 1] = newitem" |
3450 | 279 o "l()" returns an iterator for "l". |
21060
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
280 o "table.insert(l, newitem)" inserts an item at the end of the list. |
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
281 (only Lua 5.3 and later) |
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
282 o "table.insert(l, position, newitem)" inserts an item at the |
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
283 specified position. "position" is one-indexed. (only Lua 5.3 and |
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
284 later) |
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
285 o "table.remove(l, position)" removes an item at the specified |
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
286 position. "position" is one-indexed. |
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
287 |
3450 | 288 |
289 Methods | |
290 ------- | |
291 o "l:add(item)" appends "item" to the end of "l". | |
292 o "l:insert(item[, pos])" inserts "item" at (optional) | |
293 position "pos" in the list. The default value for "pos" is 0. | |
294 | |
295 Examples: | |
296 > | |
297 :let l = [1, 'item'] | |
298 :lua l = vim.eval('l') -- same 'l' | |
299 :lua l:add(vim.list()) | |
21030
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21006
diff
changeset
|
300 :lua l[1] = math.pi |
3450 | 301 :echo l[0] " 3.141593 |
21030
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21006
diff
changeset
|
302 :lua l[1] = nil -- remove first item |
3450 | 303 :lua l:insert(true, 1) |
21030
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21006
diff
changeset
|
304 :lua print(l, #l, l[1], l[2]) |
21060
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
305 :lua l[#l + 1] = 'value' |
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
306 :lua table.insert(l, 100) |
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
307 :lua table.insert(l, 2, 200) |
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
308 :lua table.remove(l, 1) |
3450 | 309 :lua for item in l() do print(item) end |
310 | |
311 ============================================================================== | |
312 4. Dict userdata *lua-dict* | |
313 | |
314 Similarly to list userdata, dict userdata represent vim dictionaries; since | |
315 dictionaries are also objects, references are kept between Lua and Vim. A dict | |
316 "d" has the following properties: | |
317 | |
318 Properties | |
319 ---------- | |
320 o "#d" is the number of items in dict "d", equivalent to "len(d)" | |
321 in Vim. | |
322 o "d.key" or "d['key']" returns the value at entry "key" in "d". | |
323 To modify the entry at this key, simply do "d.key = newvalue"; in | |
324 particular, "d.key = nil" removes the entry from "d". | |
325 o "d()" returns an iterator for "d" and is equivalent to "items(d)" in | |
326 Vim. | |
327 | |
328 Examples: | |
329 > | |
330 :let d = {'n':10} | |
331 :lua d = vim.eval('d') -- same 'd' | |
332 :lua print(d, d.n, #d) | |
333 :let d.self = d | |
334 :lua for k, v in d() do print(d, k, v) end | |
335 :lua d.x = math.pi | |
336 :lua d.self = nil -- remove entry | |
337 :echo d | |
338 < | |
339 | |
340 ============================================================================== | |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
341 5. Blob userdata *lua-blob* |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
342 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
343 Blob userdata represent vim blobs. A blob "b" has the following properties: |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
344 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
345 Properties |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
346 ---------- |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
347 o "#b" is the length of blob "b", equivalent to "len(b)" in Vim. |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
348 o "b[k]" returns the k-th item in "b"; "b" is zero-indexed, as in Vim. |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
349 To modify the k-th item, simply do "b[k] = number"; in particular, |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
350 "b[#b] = number" can append a byte to tail. |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
351 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
352 Methods |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
353 ------- |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
354 o "b:add(bytes)" appends "bytes" to the end of "b". |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
355 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
356 Examples: |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
357 > |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
358 :let b = 0z001122 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
359 :lua b = vim.eval('b') -- same 'b' |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
360 :lua print(b, b[0], #b) |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
361 :lua b[1] = 32 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
362 :lua b[#b] = 0x33 -- append a byte to tail |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
363 :lua b:add("\x80\x81\xfe\xff") |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
364 :echo b |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
365 < |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
366 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
367 ============================================================================== |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
368 6. Funcref userdata *lua-funcref* |
4911 | 369 |
370 Funcref userdata represent funcref variables in Vim. Funcrefs that were | |
371 defined with a "dict" attribute need to be obtained as a dictionary key | |
372 in order to have "self" properly assigned to the dictionary (see examples | |
373 below.) A funcref "f" has the following properties: | |
374 | |
375 Properties | |
376 ---------- | |
377 o "#f" is the name of the function referenced by "f" | |
378 o "f(...)" calls the function referenced by "f" (with arguments) | |
379 | |
380 Examples: | |
381 > | |
382 :function I(x) | |
383 : return a:x | |
384 : endfunction | |
385 :let R = function('I') | |
386 :lua i1 = vim.funcref('I') | |
387 :lua i2 = vim.eval('R') | |
388 :lua print(#i1, #i2) -- both 'I' | |
389 :lua print(i1, i2, #i2(i1) == #i1(i2)) | |
390 :function Mylen() dict | |
391 : return len(self.data) | |
392 : endfunction | |
393 :let mydict = {'data': [0, 1, 2, 3]} | |
394 :lua d = vim.eval('mydict'); d.len = vim.funcref('Mylen') | |
395 :echo mydict.len() | |
396 :lua l = d.len -- assign d as 'self' | |
397 :lua print(l()) | |
398 < | |
21006
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20552
diff
changeset
|
399 Lua functions and closures are automatically converted to a Vim |Funcref| and |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20552
diff
changeset
|
400 can be accessed in Vim scripts. Example: |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20552
diff
changeset
|
401 > |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20552
diff
changeset
|
402 lua <<EOF |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20552
diff
changeset
|
403 vim.fn.timer_start(1000, function(timer) |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20552
diff
changeset
|
404 print('timer callback') |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20552
diff
changeset
|
405 end) |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20552
diff
changeset
|
406 EOF |
4911 | 407 |
408 ============================================================================== | |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
409 7. Buffer userdata *lua-buffer* |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
410 |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
411 Buffer userdata represent vim buffers. A buffer userdata "b" has the following |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
412 properties and methods: |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
413 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
414 Properties |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
415 ---------- |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
416 o "b()" sets "b" as the current buffer. |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
417 o "#b" is the number of lines in buffer "b". |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
418 o "b[k]" represents line number k: "b[k] = newline" replaces line k |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
419 with string "newline" and "b[k] = nil" deletes line k. |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
420 o "b.name" contains the short name of buffer "b" (read-only). |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
421 o "b.fname" contains the full name of buffer "b" (read-only). |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
422 o "b.number" contains the position of buffer "b" in the buffer list |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
423 (read-only). |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
424 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
425 Methods |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
426 ------- |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
427 o "b:insert(newline[, pos])" inserts string "newline" at (optional) |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
428 position "pos" in the buffer. The default value for "pos" is |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
429 "#b + 1". If "pos == 0" then "newline" becomes the first line in |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
430 the buffer. |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
431 o "b:next()" returns the buffer next to "b" in the buffer list. |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
432 o "b:previous()" returns the buffer previous to "b" in the buffer |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
433 list. |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
434 o "b:isvalid()" returns 'true' (boolean) if buffer "b" corresponds to |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
435 a "real" (not freed from memory) Vim buffer. |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
436 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
437 Examples: |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
438 > |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
439 :lua b = vim.buffer() -- current buffer |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
440 :lua print(b.name, b.number) |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
441 :lua b[1] = "first line" |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
442 :lua b:insert("FIRST!", 0) |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
443 :lua b[1] = nil -- delete top line |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
444 :lua for i=1,3 do b:insert(math.random()) end |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
445 :3,4lua for i=vim.lastline,vim.firstline,-1 do b[i] = nil end |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
446 :lua vim.open"myfile"() -- open buffer and set it as current |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
447 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
448 function! ListBuffers() |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
449 lua << EOF |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
450 local b = vim.buffer(true) -- first buffer in list |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
451 while b ~= nil do |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
452 print(b.number, b.name, #b) |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
453 b = b:next() |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
454 end |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
455 vim.beep() |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
456 EOF |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
457 endfunction |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
458 < |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
459 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
460 ============================================================================== |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
461 8. Window userdata *lua-window* |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
462 |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
463 Window objects represent vim windows. A window userdata "w" has the following |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
464 properties and methods: |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
465 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
466 Properties |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
467 ---------- |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
468 o "w()" sets "w" as the current window. |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
469 o "w.buffer" contains the buffer of window "w" (read-only). |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
470 o "w.line" represents the cursor line position in window "w". |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
471 o "w.col" represents the cursor column position in window "w". |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
472 o "w.width" represents the width of window "w". |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
473 o "w.height" represents the height of window "w". |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
474 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
475 Methods |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
476 ------- |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
477 o "w:next()" returns the window next to "w". |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
478 o "w:previous()" returns the window previous to "w". |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
479 o "w:isvalid()" returns 'true' (boolean) if window "w" corresponds to |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
480 a "real" (not freed from memory) Vim window. |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
481 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
482 Examples: |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
483 > |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
484 :lua w = vim.window() -- current window |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
485 :lua print(w.buffer.name, w.line, w.col) |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
486 :lua w.width = w.width + math.random(10) |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
487 :lua w.height = 2 * math.random() * w.height |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
488 :lua n,w = 0,vim.window(true) while w~=nil do n,w = n + 1,w:next() end |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
489 :lua print("There are " .. n .. " windows") |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
490 < |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
491 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
492 ============================================================================== |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
493 9. luaeval() Vim function *lua-luaeval* *lua-eval* |
3450 | 494 |
495 The (dual) equivalent of "vim.eval" for passing Lua values to Vim is | |
496 "luaeval". "luaeval" takes an expression string and an optional argument and | |
497 returns the result of the expression. It is semantically equivalent in Lua to: | |
498 > | |
499 local chunkheader = "local _A = select(1, ...) return " | |
500 function luaeval (expstr, arg) | |
501 local chunk = assert(loadstring(chunkheader .. expstr, "luaeval")) | |
502 return chunk(arg) -- return typval | |
503 end | |
504 < | |
4911 | 505 Note that "_A" receives the argument to "luaeval". Lua numbers, strings, and |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
506 list, dict, blob, and funcref userdata are converted to their Vim respective |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
507 types, while Lua booleans are converted to numbers. An error is thrown if |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
508 conversion of any of the remaining Lua types, including userdata other than |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
509 lists, dicts, blobs, and funcrefs, is attempted. |
4911 | 510 |
511 Examples: > | |
3450 | 512 |
513 :echo luaeval('math.pi') | |
514 :lua a = vim.list():add('newlist') | |
515 :let a = luaeval('a') | |
516 :echo a[0] " 'newlist' | |
517 :function Rand(x,y) " random uniform between x and y | |
518 : return luaeval('(_A.y-_A.x)*math.random()+_A.x', {'x':a:x,'y':a:y}) | |
519 : endfunction | |
520 :echo Rand(1,10) | |
521 | |
522 | |
523 ============================================================================== | |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
14298
diff
changeset
|
524 10. Dynamic loading *lua-dynamic* |
7196
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5340
diff
changeset
|
525 |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5340
diff
changeset
|
526 On MS-Windows and Unix the Lua library can be loaded dynamically. The |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5340
diff
changeset
|
527 |:version| output then includes |+lua/dyn|. |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5340
diff
changeset
|
528 |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5340
diff
changeset
|
529 This means that Vim will search for the Lua DLL or shared library file only |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5340
diff
changeset
|
530 when needed. When you don't use the Lua interface you don't need it, thus |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5340
diff
changeset
|
531 you can use Vim without this file. |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5340
diff
changeset
|
532 |
8673
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
533 |
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
534 MS-Windows ~ |
7196
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5340
diff
changeset
|
535 |
8673
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
536 To use the Lua interface the Lua DLL must be in your search path. In a |
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
537 console window type "path" to see what directories are used. The 'luadll' |
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
538 option can be also used to specify the Lua DLL. The version of the DLL must |
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
539 match the Lua version Vim was compiled with. |
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
540 |
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
541 |
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
542 Unix ~ |
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
543 |
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
544 The 'luadll' option can be used to specify the Lua shared library file instead |
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
545 of DYNAMIC_LUA_DLL file what was specified at compile time. The version of |
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
546 the shared library must match the Lua version Vim was compiled with. |
7196
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5340
diff
changeset
|
547 |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5340
diff
changeset
|
548 |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5340
diff
changeset
|
549 ============================================================================== |
3450 | 550 vim:tw=78:ts=8:noet:ft=help:norl: |