Bram Moolenaar | d94464e | 2015-11-02 15:28:18 +0100 | [diff] [blame] | 1 | *if_lua.txt* For Vim version 7.4. Last change: 2015 Oct 16 |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 2 | |
| 3 | |
| 4 | VIM REFERENCE MANUAL by Luis Carvalho |
| 5 | |
| 6 | |
| 7 | The Lua Interface to Vim *lua* *Lua* |
| 8 | |
| 9 | 1. Commands |lua-commands| |
| 10 | 2. The vim module |lua-vim| |
Bram Moolenaar | 1dced57 | 2012-04-05 16:54:08 +0200 | [diff] [blame] | 11 | 3. List userdata |lua-list| |
| 12 | 4. Dict userdata |lua-dict| |
Bram Moolenaar | 52b91d8 | 2013-06-15 21:39:51 +0200 | [diff] [blame] | 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| |
Bram Moolenaar | d94464e | 2015-11-02 15:28:18 +0100 | [diff] [blame] | 17 | 9. Dynamic loading |lua-dynamic| |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 18 | |
| 19 | {Vi does not have any of these commands} |
| 20 | |
| 21 | The Lua interface is available only when Vim was compiled with the |
| 22 | |+lua| feature. |
| 23 | |
| 24 | ============================================================================== |
| 25 | 1. Commands *lua-commands* |
| 26 | |
| 27 | *:lua* |
| 28 | :[range]lua {chunk} |
| 29 | Execute Lua chunk {chunk}. {not in Vi} |
| 30 | |
| 31 | Examples: |
| 32 | > |
| 33 | :lua print("Hello, Vim!") |
| 34 | :lua local curbuf = vim.buffer() curbuf[7] = "line #7" |
| 35 | < |
| 36 | |
| 37 | :[range]lua << {endmarker} |
| 38 | {script} |
| 39 | {endmarker} |
| 40 | Execute Lua script {script}. {not in Vi} |
| 41 | Note: This command doesn't work when the Lua |
| 42 | feature wasn't compiled in. To avoid errors, see |
| 43 | |script-here|. |
| 44 | |
| 45 | {endmarker} must NOT be preceded by any white space. If {endmarker} is |
| 46 | omitted from after the "<<", a dot '.' must be used after {script}, like |
| 47 | for the |:append| and |:insert| commands. |
| 48 | This form of the |:lua| command is mainly useful for including Lua code |
| 49 | in Vim scripts. |
| 50 | |
| 51 | Example: |
| 52 | > |
| 53 | function! CurrentLineInfo() |
| 54 | lua << EOF |
| 55 | local linenr = vim.window().line |
| 56 | local curline = vim.buffer()[linenr] |
| 57 | print(string.format("Current line [%d] has %d chars", |
| 58 | linenr, #curline)) |
| 59 | EOF |
| 60 | endfunction |
| 61 | < |
| 62 | |
| 63 | *:luado* |
Bram Moolenaar | 53bfca2 | 2012-04-13 23:04:47 +0200 | [diff] [blame] | 64 | :[range]luado {body} Execute Lua function "function (line, linenr) {body} |
| 65 | end" for each line in the [range], with the function |
| 66 | argument being set to the text of each line in turn, |
| 67 | without a trailing <EOL>, and the current line number. |
| 68 | If the value returned by the function is a string it |
| 69 | becomes the text of the line in the current turn. The |
| 70 | default for [range] is the whole file: "1,$". |
| 71 | {not in Vi} |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 72 | |
| 73 | Examples: |
| 74 | > |
| 75 | :luado return string.format("%s\t%d", line:reverse(), #line) |
| 76 | |
| 77 | :lua require"lpeg" |
| 78 | :lua -- balanced parenthesis grammar: |
| 79 | :lua bp = lpeg.P{ "(" * ((1 - lpeg.S"()") + lpeg.V(1))^0 * ")" } |
| 80 | :luado if bp:match(line) then return "-->\t" .. line end |
| 81 | < |
| 82 | |
| 83 | *:luafile* |
| 84 | :[range]luafile {file} |
| 85 | Execute Lua script in {file}. {not in Vi} |
| 86 | The whole argument is used as a single file name. |
| 87 | |
| 88 | Examples: |
| 89 | > |
| 90 | :luafile script.lua |
| 91 | :luafile % |
| 92 | < |
| 93 | |
| 94 | All these commands execute a Lua chunk from either the command line (:lua and |
| 95 | :luado) or a file (:luafile) with the given line [range]. Similarly to the Lua |
| 96 | interpreter, each chunk has its own scope and so only global variables are |
Bram Moolenaar | 1dced57 | 2012-04-05 16:54:08 +0200 | [diff] [blame] | 97 | shared between command calls. All Lua default libraries are available. In |
| 98 | addition, Lua "print" function has its output redirected to the Vim message |
| 99 | area, with arguments separated by a white space instead of a tab. |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 100 | |
Bram Moolenaar | 9855d6b | 2010-07-18 14:34:51 +0200 | [diff] [blame] | 101 | Lua uses the "vim" module (see |lua-vim|) to issue commands to Vim |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 102 | and manage buffers (|lua-buffer|) and windows (|lua-window|). However, |
| 103 | procedures that alter buffer content, open new buffers, and change cursor |
Bram Moolenaar | 9855d6b | 2010-07-18 14:34:51 +0200 | [diff] [blame] | 104 | position are restricted when the command is executed in the |sandbox|. |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 105 | |
| 106 | |
| 107 | ============================================================================== |
| 108 | 2. The vim module *lua-vim* |
| 109 | |
| 110 | Lua interfaces Vim through the "vim" module. The first and last line of the |
Bram Moolenaar | 2334b6d | 2010-07-22 21:32:16 +0200 | [diff] [blame] | 111 | input range are stored in "vim.firstline" and "vim.lastline" respectively. The |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 112 | module also includes routines for buffer, window, and current line queries, |
| 113 | Vim evaluation and command execution, and others. |
| 114 | |
Bram Moolenaar | 52b91d8 | 2013-06-15 21:39:51 +0200 | [diff] [blame] | 115 | vim.list([arg]) Returns an empty list or, if "arg" is a Lua |
| 116 | table with numeric keys 1, ..., n (a |
| 117 | "sequence"), returns a list l such that l[i] = |
| 118 | arg[i] for i = 1, ..., n (see |List|). |
| 119 | Non-numeric keys are not used to initialize |
| 120 | the list. See also |lua-eval| for conversion |
| 121 | rules. Example: > |
| 122 | :lua t = {math.pi, false, say = 'hi'} |
| 123 | :echo luaeval('vim.list(t)') |
| 124 | :" [3.141593, 0], 'say' is ignored |
| 125 | < |
| 126 | vim.dict([arg]) Returns an empty dictionary or, if "arg" is a |
| 127 | Lua table, returns a dict d such that d[k] = |
| 128 | arg[k] for all string keys k in "arg" (see |
| 129 | |Dictionary|). Number keys are converted to |
| 130 | strings. Keys that are not strings are not |
| 131 | used to initialize the dictionary. See also |
| 132 | |lua-eval| for conversion rules. Example: > |
| 133 | :lua t = {math.pi, false, say = 'hi'} |
| 134 | :echo luaeval('vim.dict(t)') |
| 135 | :" {'say': 'hi'}, numeric keys ignored |
| 136 | < |
| 137 | vim.funcref({name}) Returns a Funcref to function {name} (see |
| 138 | |Funcref|). It is equivalent to Vim's |
Bram Moolenaar | 7cba6c0 | 2013-09-05 22:13:31 +0200 | [diff] [blame] | 139 | "function". NOT IMPLEMENTED YET |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 140 | |
Bram Moolenaar | 2334b6d | 2010-07-22 21:32:16 +0200 | [diff] [blame] | 141 | vim.buffer([arg]) If "arg" is a number, returns buffer with |
| 142 | number "arg" in the buffer list or, if "arg" |
| 143 | is a string, returns buffer whose full or short |
| 144 | name is "arg". In both cases, returns 'nil' |
| 145 | (nil value, not string) if the buffer is not |
| 146 | found. Otherwise, if "toboolean(arg)" is |
| 147 | 'true' returns the first buffer in the buffer |
| 148 | list or else the current buffer. |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 149 | |
Bram Moolenaar | 2334b6d | 2010-07-22 21:32:16 +0200 | [diff] [blame] | 150 | vim.window([arg]) If "arg" is a number, returns window with |
| 151 | number "arg" or 'nil' (nil value, not string) |
| 152 | if not found. Otherwise, if "toboolean(arg)" |
| 153 | is 'true' returns the first window or else the |
| 154 | current window. |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 155 | |
Bram Moolenaar | 1dced57 | 2012-04-05 16:54:08 +0200 | [diff] [blame] | 156 | vim.type({arg}) Returns the type of {arg}. It is equivalent to |
| 157 | Lua's "type" function, but returns "list", |
Bram Moolenaar | 52b91d8 | 2013-06-15 21:39:51 +0200 | [diff] [blame] | 158 | "dict", "funcref", "buffer", or "window" if |
| 159 | {arg} is a list, dictionary, funcref, buffer, |
| 160 | or window, respectively. Examples: > |
Bram Moolenaar | 1dced57 | 2012-04-05 16:54:08 +0200 | [diff] [blame] | 161 | :lua l = vim.list() |
| 162 | :lua print(type(l), vim.type(l)) |
| 163 | :" userdata list |
| 164 | < |
Bram Moolenaar | 2334b6d | 2010-07-22 21:32:16 +0200 | [diff] [blame] | 165 | vim.command({cmd}) Executes the vim (ex-mode) command {cmd}. |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 166 | Examples: > |
| 167 | :lua vim.command"set tw=60" |
| 168 | :lua vim.command"normal ddp" |
| 169 | < |
Bram Moolenaar | 2334b6d | 2010-07-22 21:32:16 +0200 | [diff] [blame] | 170 | vim.eval({expr}) Evaluates expression {expr} (see |expression|), |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 171 | converts the result to Lua, and returns it. |
| 172 | Vim strings and numbers are directly converted |
| 173 | to Lua strings and numbers respectively. Vim |
| 174 | lists and dictionaries are converted to Lua |
Bram Moolenaar | 1dced57 | 2012-04-05 16:54:08 +0200 | [diff] [blame] | 175 | userdata (see |lua-list| and |lua-dict|). |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 176 | Examples: > |
| 177 | :lua tw = vim.eval"&tw" |
| 178 | :lua print(vim.eval"{'a': 'one'}".a) |
| 179 | < |
Bram Moolenaar | 2334b6d | 2010-07-22 21:32:16 +0200 | [diff] [blame] | 180 | vim.line() Returns the current line (without the trailing |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 181 | <EOL>), a Lua string. |
| 182 | |
Bram Moolenaar | 2334b6d | 2010-07-22 21:32:16 +0200 | [diff] [blame] | 183 | vim.beep() Beeps. |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 184 | |
Bram Moolenaar | 2334b6d | 2010-07-22 21:32:16 +0200 | [diff] [blame] | 185 | vim.open({fname}) Opens a new buffer for file {fname} and |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 186 | returns it. Note that the buffer is not set as |
| 187 | current. |
| 188 | |
| 189 | |
| 190 | ============================================================================== |
Bram Moolenaar | 1dced57 | 2012-04-05 16:54:08 +0200 | [diff] [blame] | 191 | 3. List userdata *lua-list* |
| 192 | |
| 193 | List userdata represent vim lists, and the interface tries to follow closely |
| 194 | Vim's syntax for lists. Since lists are objects, changes in list references in |
| 195 | Lua are reflected in Vim and vice-versa. A list "l" has the following |
| 196 | properties and methods: |
| 197 | |
| 198 | Properties |
| 199 | ---------- |
| 200 | o "#l" is the number of items in list "l", equivalent to "len(l)" |
| 201 | in Vim. |
| 202 | o "l[k]" returns the k-th item in "l"; "l" is zero-indexed, as in Vim. |
| 203 | To modify the k-th item, simply do "l[k] = newitem"; in |
| 204 | particular, "l[k] = nil" removes the k-th item from "l". |
| 205 | o "l()" returns an iterator for "l". |
| 206 | |
| 207 | Methods |
| 208 | ------- |
| 209 | o "l:add(item)" appends "item" to the end of "l". |
| 210 | o "l:insert(item[, pos])" inserts "item" at (optional) |
| 211 | position "pos" in the list. The default value for "pos" is 0. |
| 212 | |
| 213 | Examples: |
| 214 | > |
| 215 | :let l = [1, 'item'] |
| 216 | :lua l = vim.eval('l') -- same 'l' |
| 217 | :lua l:add(vim.list()) |
| 218 | :lua l[0] = math.pi |
| 219 | :echo l[0] " 3.141593 |
| 220 | :lua l[0] = nil -- remove first item |
| 221 | :lua l:insert(true, 1) |
| 222 | :lua print(l, #l, l[0], l[1], l[-1]) |
| 223 | :lua for item in l() do print(item) end |
| 224 | < |
| 225 | |
| 226 | ============================================================================== |
| 227 | 4. Dict userdata *lua-dict* |
| 228 | |
| 229 | Similarly to list userdata, dict userdata represent vim dictionaries; since |
| 230 | dictionaries are also objects, references are kept between Lua and Vim. A dict |
| 231 | "d" has the following properties: |
| 232 | |
| 233 | Properties |
| 234 | ---------- |
| 235 | o "#d" is the number of items in dict "d", equivalent to "len(d)" |
| 236 | in Vim. |
| 237 | o "d.key" or "d['key']" returns the value at entry "key" in "d". |
| 238 | To modify the entry at this key, simply do "d.key = newvalue"; in |
| 239 | particular, "d.key = nil" removes the entry from "d". |
| 240 | o "d()" returns an iterator for "d" and is equivalent to "items(d)" in |
| 241 | Vim. |
| 242 | |
| 243 | Examples: |
| 244 | > |
| 245 | :let d = {'n':10} |
| 246 | :lua d = vim.eval('d') -- same 'd' |
| 247 | :lua print(d, d.n, #d) |
| 248 | :let d.self = d |
| 249 | :lua for k, v in d() do print(d, k, v) end |
| 250 | :lua d.x = math.pi |
| 251 | :lua d.self = nil -- remove entry |
| 252 | :echo d |
| 253 | < |
| 254 | |
| 255 | ============================================================================== |
Bram Moolenaar | 52b91d8 | 2013-06-15 21:39:51 +0200 | [diff] [blame] | 256 | 5. Funcref userdata *lua-funcref* |
| 257 | |
| 258 | Funcref userdata represent funcref variables in Vim. Funcrefs that were |
| 259 | defined with a "dict" attribute need to be obtained as a dictionary key |
| 260 | in order to have "self" properly assigned to the dictionary (see examples |
| 261 | below.) A funcref "f" has the following properties: |
| 262 | |
| 263 | Properties |
| 264 | ---------- |
| 265 | o "#f" is the name of the function referenced by "f" |
| 266 | o "f(...)" calls the function referenced by "f" (with arguments) |
| 267 | |
| 268 | Examples: |
| 269 | > |
| 270 | :function I(x) |
| 271 | : return a:x |
| 272 | : endfunction |
| 273 | :let R = function('I') |
| 274 | :lua i1 = vim.funcref('I') |
| 275 | :lua i2 = vim.eval('R') |
| 276 | :lua print(#i1, #i2) -- both 'I' |
| 277 | :lua print(i1, i2, #i2(i1) == #i1(i2)) |
| 278 | :function Mylen() dict |
| 279 | : return len(self.data) |
| 280 | : endfunction |
| 281 | :let mydict = {'data': [0, 1, 2, 3]} |
| 282 | :lua d = vim.eval('mydict'); d.len = vim.funcref('Mylen') |
| 283 | :echo mydict.len() |
| 284 | :lua l = d.len -- assign d as 'self' |
| 285 | :lua print(l()) |
| 286 | < |
| 287 | |
| 288 | ============================================================================== |
| 289 | 6. Buffer userdata *lua-buffer* |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 290 | |
Bram Moolenaar | 2334b6d | 2010-07-22 21:32:16 +0200 | [diff] [blame] | 291 | Buffer userdata represent vim buffers. A buffer userdata "b" has the following |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 292 | properties and methods: |
| 293 | |
| 294 | Properties |
| 295 | ---------- |
Bram Moolenaar | 2334b6d | 2010-07-22 21:32:16 +0200 | [diff] [blame] | 296 | o "b()" sets "b" as the current buffer. |
| 297 | o "#b" is the number of lines in buffer "b". |
| 298 | o "b[k]" represents line number k: "b[k] = newline" replaces line k |
| 299 | with string "newline" and "b[k] = nil" deletes line k. |
| 300 | o "b.name" contains the short name of buffer "b" (read-only). |
| 301 | o "b.fname" contains the full name of buffer "b" (read-only). |
| 302 | o "b.number" contains the position of buffer "b" in the buffer list |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 303 | (read-only). |
| 304 | |
| 305 | Methods |
| 306 | ------- |
Bram Moolenaar | 2334b6d | 2010-07-22 21:32:16 +0200 | [diff] [blame] | 307 | o "b:insert(newline[, pos])" inserts string "newline" at (optional) |
| 308 | position "pos" in the buffer. The default value for "pos" is |
| 309 | "#b + 1". If "pos == 0" then "newline" becomes the first line in |
| 310 | the buffer. |
| 311 | o "b:next()" returns the buffer next to "b" in the buffer list. |
| 312 | o "b:previous()" returns the buffer previous to "b" in the buffer |
| 313 | list. |
| 314 | o "b:isvalid()" returns 'true' (boolean) if buffer "b" corresponds to |
| 315 | a "real" (not freed from memory) Vim buffer. |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 316 | |
| 317 | Examples: |
| 318 | > |
| 319 | :lua b = vim.buffer() -- current buffer |
| 320 | :lua print(b.name, b.number) |
| 321 | :lua b[1] = "first line" |
| 322 | :lua b:insert("FIRST!", 0) |
| 323 | :lua b[1] = nil -- delete top line |
| 324 | :lua for i=1,3 do b:insert(math.random()) end |
| 325 | :3,4lua for i=vim.lastline,vim.firstline,-1 do b[i] = nil end |
| 326 | :lua vim.open"myfile"() -- open buffer and set it as current |
| 327 | |
| 328 | function! ListBuffers() |
| 329 | lua << EOF |
| 330 | local b = vim.buffer(true) -- first buffer in list |
| 331 | while b ~= nil do |
| 332 | print(b.number, b.name, #b) |
| 333 | b = b:next() |
| 334 | end |
| 335 | vim.beep() |
| 336 | EOF |
| 337 | endfunction |
| 338 | < |
| 339 | |
| 340 | ============================================================================== |
Bram Moolenaar | 52b91d8 | 2013-06-15 21:39:51 +0200 | [diff] [blame] | 341 | 7. Window userdata *lua-window* |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 342 | |
Bram Moolenaar | 2334b6d | 2010-07-22 21:32:16 +0200 | [diff] [blame] | 343 | Window objects represent vim windows. A window userdata "w" has the following |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 344 | properties and methods: |
| 345 | |
| 346 | Properties |
| 347 | ---------- |
Bram Moolenaar | 2334b6d | 2010-07-22 21:32:16 +0200 | [diff] [blame] | 348 | o "w()" sets "w" as the current window. |
| 349 | o "w.buffer" contains the buffer of window "w" (read-only). |
| 350 | o "w.line" represents the cursor line position in window "w". |
| 351 | o "w.col" represents the cursor column position in window "w". |
| 352 | o "w.width" represents the width of window "w". |
| 353 | o "w.height" represents the height of window "w". |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 354 | |
| 355 | Methods |
| 356 | ------- |
Bram Moolenaar | 2334b6d | 2010-07-22 21:32:16 +0200 | [diff] [blame] | 357 | o "w:next()" returns the window next to "w". |
| 358 | o "w:previous()" returns the window previous to "w". |
| 359 | o "w:isvalid()" returns 'true' (boolean) if window "w" corresponds to |
| 360 | a "real" (not freed from memory) Vim window. |
Bram Moolenaar | 0ba0429 | 2010-07-14 23:23:17 +0200 | [diff] [blame] | 361 | |
| 362 | Examples: |
| 363 | > |
| 364 | :lua w = vim.window() -- current window |
| 365 | :lua print(w.buffer.name, w.line, w.col) |
| 366 | :lua w.width = w.width + math.random(10) |
| 367 | :lua w.height = 2 * math.random() * w.height |
| 368 | :lua n,w = 0,vim.window(true) while w~=nil do n,w = n + 1,w:next() end |
| 369 | :lua print("There are " .. n .. " windows") |
| 370 | < |
| 371 | |
| 372 | ============================================================================== |
Bram Moolenaar | 52b91d8 | 2013-06-15 21:39:51 +0200 | [diff] [blame] | 373 | 8. The luaeval function *lua-luaeval* *lua-eval* |
Bram Moolenaar | 1dced57 | 2012-04-05 16:54:08 +0200 | [diff] [blame] | 374 | |
| 375 | The (dual) equivalent of "vim.eval" for passing Lua values to Vim is |
| 376 | "luaeval". "luaeval" takes an expression string and an optional argument and |
| 377 | returns the result of the expression. It is semantically equivalent in Lua to: |
| 378 | > |
| 379 | local chunkheader = "local _A = select(1, ...) return " |
| 380 | function luaeval (expstr, arg) |
| 381 | local chunk = assert(loadstring(chunkheader .. expstr, "luaeval")) |
| 382 | return chunk(arg) -- return typval |
| 383 | end |
| 384 | < |
Bram Moolenaar | 52b91d8 | 2013-06-15 21:39:51 +0200 | [diff] [blame] | 385 | Note that "_A" receives the argument to "luaeval". Lua numbers, strings, and |
| 386 | list, dict, and funcref userdata are converted to their Vim respective types, |
| 387 | while Lua booleans are converted to numbers. An error is thrown if conversion |
| 388 | of any of the remaining Lua types, including userdata other than lists, dicts, |
| 389 | and funcrefs, is attempted. |
| 390 | |
| 391 | Examples: > |
Bram Moolenaar | 1dced57 | 2012-04-05 16:54:08 +0200 | [diff] [blame] | 392 | |
| 393 | :echo luaeval('math.pi') |
| 394 | :lua a = vim.list():add('newlist') |
| 395 | :let a = luaeval('a') |
| 396 | :echo a[0] " 'newlist' |
| 397 | :function Rand(x,y) " random uniform between x and y |
| 398 | : return luaeval('(_A.y-_A.x)*math.random()+_A.x', {'x':a:x,'y':a:y}) |
| 399 | : endfunction |
| 400 | :echo Rand(1,10) |
| 401 | |
| 402 | |
| 403 | ============================================================================== |
Bram Moolenaar | d94464e | 2015-11-02 15:28:18 +0100 | [diff] [blame] | 404 | 9. Dynamic loading *lua-dynamic* |
| 405 | |
| 406 | On MS-Windows and Unix the Lua library can be loaded dynamically. The |
| 407 | |:version| output then includes |+lua/dyn|. |
| 408 | |
| 409 | This means that Vim will search for the Lua DLL or shared library file only |
| 410 | when needed. When you don't use the Lua interface you don't need it, thus |
| 411 | you can use Vim without this file. |
| 412 | |
Bram Moolenaar | d94464e | 2015-11-02 15:28:18 +0100 | [diff] [blame] | 413 | |
Bram Moolenaar | e18c0b3 | 2016-03-20 21:08:34 +0100 | [diff] [blame] | 414 | MS-Windows ~ |
| 415 | |
| 416 | To use the Lua interface the Lua DLL must be in your search path. In a |
| 417 | console window type "path" to see what directories are used. The 'luadll' |
| 418 | option can be also used to specify the Lua DLL. The version of the DLL must |
| 419 | match the Lua version Vim was compiled with. |
| 420 | |
| 421 | |
| 422 | Unix ~ |
| 423 | |
| 424 | The 'luadll' option can be used to specify the Lua shared library file instead |
| 425 | of DYNAMIC_LUA_DLL file what was specified at compile time. The version of |
| 426 | the shared library must match the Lua version Vim was compiled with. |
Bram Moolenaar | d94464e | 2015-11-02 15:28:18 +0100 | [diff] [blame] | 427 | |
| 428 | |
| 429 | ============================================================================== |
Bram Moolenaar | 1dced57 | 2012-04-05 16:54:08 +0200 | [diff] [blame] | 430 | vim:tw=78:ts=8:noet:ft=help:norl: |