|
Karsten Hopp |
b81f34 |
To: vim_dev@googlegroups.com
|
|
Karsten Hopp |
b81f34 |
Subject: Patch 7.3.490
|
|
Karsten Hopp |
b81f34 |
Fcc: outbox
|
|
Karsten Hopp |
b81f34 |
From: Bram Moolenaar <Bram@moolenaar.net>
|
|
Karsten Hopp |
b81f34 |
Mime-Version: 1.0
|
|
Karsten Hopp |
b81f34 |
Content-Type: text/plain; charset=UTF-8
|
|
Karsten Hopp |
b81f34 |
Content-Transfer-Encoding: 8bit
|
|
Karsten Hopp |
b81f34 |
------------
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
Patch 7.3.490
|
|
Karsten Hopp |
b81f34 |
Problem: Member confusion in Lua interface.
|
|
Karsten Hopp |
b81f34 |
Solution: Fix it. Add luaeval(). (Taro Muraoka, Luis Carvalho)
|
|
Karsten Hopp |
b81f34 |
Files: runtime/doc/if_lua.txt, src/eval.c, src/if_lua.c,
|
|
Karsten Hopp |
b81f34 |
src/proto/if_lua.pro
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
*** ../vim-7.3.489/runtime/doc/if_lua.txt 2010-08-15 21:57:14.000000000 +0200
|
|
Karsten Hopp |
b81f34 |
--- runtime/doc/if_lua.txt 2012-04-05 16:41:35.000000000 +0200
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 1,4 ****
|
|
Karsten Hopp |
b81f34 |
! *if_lua.txt* For Vim version 7.3. Last change: 2010 Jul 22
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
VIM REFERENCE MANUAL by Luis Carvalho
|
|
Karsten Hopp |
b81f34 |
--- 1,4 ----
|
|
Karsten Hopp |
b81f34 |
! *if_lua.txt* For Vim version 7.3. Last change: 2012 Jan 16
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
VIM REFERENCE MANUAL by Luis Carvalho
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 8,15 ****
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
1. Commands |lua-commands|
|
|
Karsten Hopp |
b81f34 |
2. The vim module |lua-vim|
|
|
Karsten Hopp |
b81f34 |
! 3. Buffer userdata |lua-buffer|
|
|
Karsten Hopp |
b81f34 |
! 4. Window userdata |lua-window|
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
{Vi does not have any of these commands}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
--- 8,18 ----
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
1. Commands |lua-commands|
|
|
Karsten Hopp |
b81f34 |
2. The vim module |lua-vim|
|
|
Karsten Hopp |
b81f34 |
! 3. List userdata |lua-list|
|
|
Karsten Hopp |
b81f34 |
! 4. Dict userdata |lua-dict|
|
|
Karsten Hopp |
b81f34 |
! 5. Buffer userdata |lua-buffer|
|
|
Karsten Hopp |
b81f34 |
! 6. Window userdata |lua-window|
|
|
Karsten Hopp |
b81f34 |
! 7. The luaeval function |lua-luaeval|
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
{Vi does not have any of these commands}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 88,98 ****
|
|
Karsten Hopp |
b81f34 |
All these commands execute a Lua chunk from either the command line (:lua and
|
|
Karsten Hopp |
b81f34 |
:luado) or a file (:luafile) with the given line [range]. Similarly to the Lua
|
|
Karsten Hopp |
b81f34 |
interpreter, each chunk has its own scope and so only global variables are
|
|
Karsten Hopp |
b81f34 |
! shared between command calls. Lua default libraries "table", "string", "math",
|
|
Karsten Hopp |
b81f34 |
! and "package" are available, "io" and "debug" are not, and "os" is restricted
|
|
Karsten Hopp |
b81f34 |
! to functions "date", "clock", "time", "difftime", and "getenv". In addition,
|
|
Karsten Hopp |
b81f34 |
! Lua "print" function has its output redirected to the Vim message area, with
|
|
Karsten Hopp |
b81f34 |
! arguments separated by a white space instead of a tab.
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
Lua uses the "vim" module (see |lua-vim|) to issue commands to Vim
|
|
Karsten Hopp |
b81f34 |
and manage buffers (|lua-buffer|) and windows (|lua-window|). However,
|
|
Karsten Hopp |
b81f34 |
--- 91,99 ----
|
|
Karsten Hopp |
b81f34 |
All these commands execute a Lua chunk from either the command line (:lua and
|
|
Karsten Hopp |
b81f34 |
:luado) or a file (:luafile) with the given line [range]. Similarly to the Lua
|
|
Karsten Hopp |
b81f34 |
interpreter, each chunk has its own scope and so only global variables are
|
|
Karsten Hopp |
b81f34 |
! shared between command calls. All Lua default libraries are available. In
|
|
Karsten Hopp |
b81f34 |
! addition, Lua "print" function has its output redirected to the Vim message
|
|
Karsten Hopp |
b81f34 |
! area, with arguments separated by a white space instead of a tab.
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
Lua uses the "vim" module (see |lua-vim|) to issue commands to Vim
|
|
Karsten Hopp |
b81f34 |
and manage buffers (|lua-buffer|) and windows (|lua-window|). However,
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 108,116 ****
|
|
Karsten Hopp |
b81f34 |
module also includes routines for buffer, window, and current line queries,
|
|
Karsten Hopp |
b81f34 |
Vim evaluation and command execution, and others.
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! vim.isbuffer(value) Returns 'true' (boolean, not string) if
|
|
Karsten Hopp |
b81f34 |
! "value" is a buffer userdata and 'false'
|
|
Karsten Hopp |
b81f34 |
! otherwise (see |lua-buffer|).
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
vim.buffer([arg]) If "arg" is a number, returns buffer with
|
|
Karsten Hopp |
b81f34 |
number "arg" in the buffer list or, if "arg"
|
|
Karsten Hopp |
b81f34 |
--- 109,117 ----
|
|
Karsten Hopp |
b81f34 |
module also includes routines for buffer, window, and current line queries,
|
|
Karsten Hopp |
b81f34 |
Vim evaluation and command execution, and others.
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! vim.list() Returns an empty list (see |List|).
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! vim.dict() Returns an empty dictionary (see |Dictionary|).
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
vim.buffer([arg]) If "arg" is a number, returns buffer with
|
|
Karsten Hopp |
b81f34 |
number "arg" in the buffer list or, if "arg"
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 121,136 ****
|
|
Karsten Hopp |
b81f34 |
'true' returns the first buffer in the buffer
|
|
Karsten Hopp |
b81f34 |
list or else the current buffer.
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
- vim.iswindow(value) Returns 'true' (boolean, not string) if
|
|
Karsten Hopp |
b81f34 |
- "value" is a window userdata and
|
|
Karsten Hopp |
b81f34 |
- 'false' otherwise (see |lua-window|).
|
|
Karsten Hopp |
b81f34 |
-
|
|
Karsten Hopp |
b81f34 |
vim.window([arg]) If "arg" is a number, returns window with
|
|
Karsten Hopp |
b81f34 |
number "arg" or 'nil' (nil value, not string)
|
|
Karsten Hopp |
b81f34 |
if not found. Otherwise, if "toboolean(arg)"
|
|
Karsten Hopp |
b81f34 |
is 'true' returns the first window or else the
|
|
Karsten Hopp |
b81f34 |
current window.
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
vim.command({cmd}) Executes the vim (ex-mode) command {cmd}.
|
|
Karsten Hopp |
b81f34 |
Examples: >
|
|
Karsten Hopp |
b81f34 |
:lua vim.command"set tw=60"
|
|
Karsten Hopp |
b81f34 |
--- 122,142 ----
|
|
Karsten Hopp |
b81f34 |
'true' returns the first buffer in the buffer
|
|
Karsten Hopp |
b81f34 |
list or else the current buffer.
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
vim.window([arg]) If "arg" is a number, returns window with
|
|
Karsten Hopp |
b81f34 |
number "arg" or 'nil' (nil value, not string)
|
|
Karsten Hopp |
b81f34 |
if not found. Otherwise, if "toboolean(arg)"
|
|
Karsten Hopp |
b81f34 |
is 'true' returns the first window or else the
|
|
Karsten Hopp |
b81f34 |
current window.
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
+ vim.type({arg}) Returns the type of {arg}. It is equivalent to
|
|
Karsten Hopp |
b81f34 |
+ Lua's "type" function, but returns "list",
|
|
Karsten Hopp |
b81f34 |
+ "dict", "buffer", or "window" if {arg} is a
|
|
Karsten Hopp |
b81f34 |
+ list, dictionary, buffer, or window,
|
|
Karsten Hopp |
b81f34 |
+ respectively. Examples: >
|
|
Karsten Hopp |
b81f34 |
+ :lua l = vim.list()
|
|
Karsten Hopp |
b81f34 |
+ :lua print(type(l), vim.type(l))
|
|
Karsten Hopp |
b81f34 |
+ :" userdata list
|
|
Karsten Hopp |
b81f34 |
+ <
|
|
Karsten Hopp |
b81f34 |
vim.command({cmd}) Executes the vim (ex-mode) command {cmd}.
|
|
Karsten Hopp |
b81f34 |
Examples: >
|
|
Karsten Hopp |
b81f34 |
:lua vim.command"set tw=60"
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 141,147 ****
|
|
Karsten Hopp |
b81f34 |
Vim strings and numbers are directly converted
|
|
Karsten Hopp |
b81f34 |
to Lua strings and numbers respectively. Vim
|
|
Karsten Hopp |
b81f34 |
lists and dictionaries are converted to Lua
|
|
Karsten Hopp |
b81f34 |
! tables (lists become integer-keyed tables).
|
|
Karsten Hopp |
b81f34 |
Examples: >
|
|
Karsten Hopp |
b81f34 |
:lua tw = vim.eval"&tw"
|
|
Karsten Hopp |
b81f34 |
:lua print(vim.eval"{'a': 'one'}".a)
|
|
Karsten Hopp |
b81f34 |
--- 147,153 ----
|
|
Karsten Hopp |
b81f34 |
Vim strings and numbers are directly converted
|
|
Karsten Hopp |
b81f34 |
to Lua strings and numbers respectively. Vim
|
|
Karsten Hopp |
b81f34 |
lists and dictionaries are converted to Lua
|
|
Karsten Hopp |
b81f34 |
! userdata (see |lua-list| and |lua-dict|).
|
|
Karsten Hopp |
b81f34 |
Examples: >
|
|
Karsten Hopp |
b81f34 |
:lua tw = vim.eval"&tw"
|
|
Karsten Hopp |
b81f34 |
:lua print(vim.eval"{'a': 'one'}".a)
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 157,163 ****
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
==============================================================================
|
|
Karsten Hopp |
b81f34 |
! 3. Buffer userdata *lua-buffer*
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
Buffer userdata represent vim buffers. A buffer userdata "b" has the following
|
|
Karsten Hopp |
b81f34 |
properties and methods:
|
|
Karsten Hopp |
b81f34 |
--- 163,234 ----
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
==============================================================================
|
|
Karsten Hopp |
b81f34 |
! 3. List userdata *lua-list*
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! List userdata represent vim lists, and the interface tries to follow closely
|
|
Karsten Hopp |
b81f34 |
! Vim's syntax for lists. Since lists are objects, changes in list references in
|
|
Karsten Hopp |
b81f34 |
! Lua are reflected in Vim and vice-versa. A list "l" has the following
|
|
Karsten Hopp |
b81f34 |
! properties and methods:
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! Properties
|
|
Karsten Hopp |
b81f34 |
! ----------
|
|
Karsten Hopp |
b81f34 |
! o "#l" is the number of items in list "l", equivalent to "len(l)"
|
|
Karsten Hopp |
b81f34 |
! in Vim.
|
|
Karsten Hopp |
b81f34 |
! o "l[k]" returns the k-th item in "l"; "l" is zero-indexed, as in Vim.
|
|
Karsten Hopp |
b81f34 |
! To modify the k-th item, simply do "l[k] = newitem"; in
|
|
Karsten Hopp |
b81f34 |
! particular, "l[k] = nil" removes the k-th item from "l".
|
|
Karsten Hopp |
b81f34 |
! o "l()" returns an iterator for "l".
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! Methods
|
|
Karsten Hopp |
b81f34 |
! -------
|
|
Karsten Hopp |
b81f34 |
! o "l:add(item)" appends "item" to the end of "l".
|
|
Karsten Hopp |
b81f34 |
! o "l:insert(item[, pos])" inserts "item" at (optional)
|
|
Karsten Hopp |
b81f34 |
! position "pos" in the list. The default value for "pos" is 0.
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! Examples:
|
|
Karsten Hopp |
b81f34 |
! >
|
|
Karsten Hopp |
b81f34 |
! :let l = [1, 'item']
|
|
Karsten Hopp |
b81f34 |
! :lua l = vim.eval('l') -- same 'l'
|
|
Karsten Hopp |
b81f34 |
! :lua l:add(vim.list())
|
|
Karsten Hopp |
b81f34 |
! :lua l[0] = math.pi
|
|
Karsten Hopp |
b81f34 |
! :echo l[0] " 3.141593
|
|
Karsten Hopp |
b81f34 |
! :lua l[0] = nil -- remove first item
|
|
Karsten Hopp |
b81f34 |
! :lua l:insert(true, 1)
|
|
Karsten Hopp |
b81f34 |
! :lua print(l, #l, l[0], l[1], l[-1])
|
|
Karsten Hopp |
b81f34 |
! :lua for item in l() do print(item) end
|
|
Karsten Hopp |
b81f34 |
! <
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! ==============================================================================
|
|
Karsten Hopp |
b81f34 |
! 4. Dict userdata *lua-dict*
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! Similarly to list userdata, dict userdata represent vim dictionaries; since
|
|
Karsten Hopp |
b81f34 |
! dictionaries are also objects, references are kept between Lua and Vim. A dict
|
|
Karsten Hopp |
b81f34 |
! "d" has the following properties:
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! Properties
|
|
Karsten Hopp |
b81f34 |
! ----------
|
|
Karsten Hopp |
b81f34 |
! o "#d" is the number of items in dict "d", equivalent to "len(d)"
|
|
Karsten Hopp |
b81f34 |
! in Vim.
|
|
Karsten Hopp |
b81f34 |
! o "d.key" or "d['key']" returns the value at entry "key" in "d".
|
|
Karsten Hopp |
b81f34 |
! To modify the entry at this key, simply do "d.key = newvalue"; in
|
|
Karsten Hopp |
b81f34 |
! particular, "d.key = nil" removes the entry from "d".
|
|
Karsten Hopp |
b81f34 |
! o "d()" returns an iterator for "d" and is equivalent to "items(d)" in
|
|
Karsten Hopp |
b81f34 |
! Vim.
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! Examples:
|
|
Karsten Hopp |
b81f34 |
! >
|
|
Karsten Hopp |
b81f34 |
! :let d = {'n':10}
|
|
Karsten Hopp |
b81f34 |
! :lua d = vim.eval('d') -- same 'd'
|
|
Karsten Hopp |
b81f34 |
! :lua print(d, d.n, #d)
|
|
Karsten Hopp |
b81f34 |
! :let d.self = d
|
|
Karsten Hopp |
b81f34 |
! :lua for k, v in d() do print(d, k, v) end
|
|
Karsten Hopp |
b81f34 |
! :lua d.x = math.pi
|
|
Karsten Hopp |
b81f34 |
! :lua d.self = nil -- remove entry
|
|
Karsten Hopp |
b81f34 |
! :echo d
|
|
Karsten Hopp |
b81f34 |
! <
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! ==============================================================================
|
|
Karsten Hopp |
b81f34 |
! 5. Buffer userdata *lua-buffer*
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
Buffer userdata represent vim buffers. A buffer userdata "b" has the following
|
|
Karsten Hopp |
b81f34 |
properties and methods:
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 209,215 ****
|
|
Karsten Hopp |
b81f34 |
<
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
==============================================================================
|
|
Karsten Hopp |
b81f34 |
! 4. Window userdata *lua-window*
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
Window objects represent vim windows. A window userdata "w" has the following
|
|
Karsten Hopp |
b81f34 |
properties and methods:
|
|
Karsten Hopp |
b81f34 |
--- 280,286 ----
|
|
Karsten Hopp |
b81f34 |
<
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
==============================================================================
|
|
Karsten Hopp |
b81f34 |
! 6. Window userdata *lua-window*
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
Window objects represent vim windows. A window userdata "w" has the following
|
|
Karsten Hopp |
b81f34 |
properties and methods:
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 241,244 ****
|
|
Karsten Hopp |
b81f34 |
<
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
==============================================================================
|
|
Karsten Hopp |
b81f34 |
! vim:tw=78:ts=8:ft=help:norl:
|
|
Karsten Hopp |
b81f34 |
--- 312,340 ----
|
|
Karsten Hopp |
b81f34 |
<
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
==============================================================================
|
|
Karsten Hopp |
b81f34 |
! 7. The luaeval function *lua-luaeval*
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! The (dual) equivalent of "vim.eval" for passing Lua values to Vim is
|
|
Karsten Hopp |
b81f34 |
! "luaeval". "luaeval" takes an expression string and an optional argument and
|
|
Karsten Hopp |
b81f34 |
! returns the result of the expression. It is semantically equivalent in Lua to:
|
|
Karsten Hopp |
b81f34 |
! >
|
|
Karsten Hopp |
b81f34 |
! local chunkheader = "local _A = select(1, ...) return "
|
|
Karsten Hopp |
b81f34 |
! function luaeval (expstr, arg)
|
|
Karsten Hopp |
b81f34 |
! local chunk = assert(loadstring(chunkheader .. expstr, "luaeval"))
|
|
Karsten Hopp |
b81f34 |
! return chunk(arg) -- return typval
|
|
Karsten Hopp |
b81f34 |
! end
|
|
Karsten Hopp |
b81f34 |
! <
|
|
Karsten Hopp |
b81f34 |
! Note that "_A" receives the argument to "luaeval". Examples: >
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! :echo luaeval('math.pi')
|
|
Karsten Hopp |
b81f34 |
! :lua a = vim.list():add('newlist')
|
|
Karsten Hopp |
b81f34 |
! :let a = luaeval('a')
|
|
Karsten Hopp |
b81f34 |
! :echo a[0] " 'newlist'
|
|
Karsten Hopp |
b81f34 |
! :function Rand(x,y) " random uniform between x and y
|
|
Karsten Hopp |
b81f34 |
! : return luaeval('(_A.y-_A.x)*math.random()+_A.x', {'x':a:x,'y':a:y})
|
|
Karsten Hopp |
b81f34 |
! : endfunction
|
|
Karsten Hopp |
b81f34 |
! :echo Rand(1,10)
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! ==============================================================================
|
|
Karsten Hopp |
b81f34 |
! vim:tw=78:ts=8:noet:ft=help:norl:
|
|
Karsten Hopp |
b81f34 |
*** ../vim-7.3.489/src/eval.c 2012-03-28 16:49:25.000000000 +0200
|
|
Karsten Hopp |
b81f34 |
--- src/eval.c 2012-04-05 16:41:35.000000000 +0200
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 622,627 ****
|
|
Karsten Hopp |
b81f34 |
--- 622,630 ----
|
|
Karsten Hopp |
b81f34 |
static void f_log __ARGS((typval_T *argvars, typval_T *rettv));
|
|
Karsten Hopp |
b81f34 |
static void f_log10 __ARGS((typval_T *argvars, typval_T *rettv));
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
+ #ifdef FEAT_LUA
|
|
Karsten Hopp |
b81f34 |
+ static void f_luaeval __ARGS((typval_T *argvars, typval_T *rettv));
|
|
Karsten Hopp |
b81f34 |
+ #endif
|
|
Karsten Hopp |
b81f34 |
static void f_map __ARGS((typval_T *argvars, typval_T *rettv));
|
|
Karsten Hopp |
b81f34 |
static void f_maparg __ARGS((typval_T *argvars, typval_T *rettv));
|
|
Karsten Hopp |
b81f34 |
static void f_mapcheck __ARGS((typval_T *argvars, typval_T *rettv));
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 6777,6782 ****
|
|
Karsten Hopp |
b81f34 |
--- 6780,6789 ----
|
|
Karsten Hopp |
b81f34 |
/* v: vars */
|
|
Karsten Hopp |
b81f34 |
set_ref_in_ht(&vimvarht, copyID);
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
+ #ifdef FEAT_LUA
|
|
Karsten Hopp |
b81f34 |
+ set_ref_in_lua(copyID);
|
|
Karsten Hopp |
b81f34 |
+ #endif
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
/*
|
|
Karsten Hopp |
b81f34 |
* 2. Free lists and dictionaries that are not referenced.
|
|
Karsten Hopp |
b81f34 |
*/
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 7946,7951 ****
|
|
Karsten Hopp |
b81f34 |
--- 7953,7961 ----
|
|
Karsten Hopp |
b81f34 |
{"log", 1, 1, f_log},
|
|
Karsten Hopp |
b81f34 |
{"log10", 1, 1, f_log10},
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
+ #ifdef FEAT_LUA
|
|
Karsten Hopp |
b81f34 |
+ {"luaeval", 1, 2, f_luaeval},
|
|
Karsten Hopp |
b81f34 |
+ #endif
|
|
Karsten Hopp |
b81f34 |
{"map", 2, 2, f_map},
|
|
Karsten Hopp |
b81f34 |
{"maparg", 1, 4, f_maparg},
|
|
Karsten Hopp |
b81f34 |
{"mapcheck", 1, 3, f_mapcheck},
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 13626,13631 ****
|
|
Karsten Hopp |
b81f34 |
--- 13636,13658 ----
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
+ #ifdef FEAT_LUA
|
|
Karsten Hopp |
b81f34 |
+ /*
|
|
Karsten Hopp |
b81f34 |
+ * "luaeval()" function
|
|
Karsten Hopp |
b81f34 |
+ */
|
|
Karsten Hopp |
b81f34 |
+ static void
|
|
Karsten Hopp |
b81f34 |
+ f_luaeval(argvars, rettv)
|
|
Karsten Hopp |
b81f34 |
+ typval_T *argvars;
|
|
Karsten Hopp |
b81f34 |
+ typval_T *rettv;
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ char_u *str;
|
|
Karsten Hopp |
b81f34 |
+ char_u buf[NUMBUFLEN];
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ str = get_tv_string_buf(&argvars[0], buf);
|
|
Karsten Hopp |
b81f34 |
+ do_luaeval(str, argvars + 1, rettv);
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+ #endif
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
/*
|
|
Karsten Hopp |
b81f34 |
* "map()" function
|
|
Karsten Hopp |
b81f34 |
*/
|
|
Karsten Hopp |
b81f34 |
*** ../vim-7.3.489/src/if_lua.c 2011-12-08 16:00:12.000000000 +0100
|
|
Karsten Hopp |
b81f34 |
--- src/if_lua.c 2012-04-05 16:41:35.000000000 +0200
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 1,4 ****
|
|
Karsten Hopp |
b81f34 |
! /* vi:set ts=8 sts=4 sw=4:
|
|
Karsten Hopp |
b81f34 |
*
|
|
Karsten Hopp |
b81f34 |
* VIM - Vi IMproved by Bram Moolenaar
|
|
Karsten Hopp |
b81f34 |
*
|
|
Karsten Hopp |
b81f34 |
--- 1,4 ----
|
|
Karsten Hopp |
b81f34 |
! /* vi:set ts=8 sts=4 sw=4 noet:
|
|
Karsten Hopp |
b81f34 |
*
|
|
Karsten Hopp |
b81f34 |
* VIM - Vi IMproved by Bram Moolenaar
|
|
Karsten Hopp |
b81f34 |
*
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 21,35 ****
|
|
Karsten Hopp |
b81f34 |
--- 21,53 ----
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
#define LUAVIM_CHUNKNAME "vim chunk"
|
|
Karsten Hopp |
b81f34 |
#define LUAVIM_NAME "vim"
|
|
Karsten Hopp |
b81f34 |
+ #define LUAVIM_EVALNAME "luaeval"
|
|
Karsten Hopp |
b81f34 |
+ #define LUAVIM_EVALHEADER "local _A=select(1,...) return "
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
typedef buf_T *luaV_Buffer;
|
|
Karsten Hopp |
b81f34 |
typedef win_T *luaV_Window;
|
|
Karsten Hopp |
b81f34 |
+ typedef dict_T *luaV_Dict;
|
|
Karsten Hopp |
b81f34 |
+ typedef list_T *luaV_List;
|
|
Karsten Hopp |
b81f34 |
typedef void (*msgfunc_T)(char_u *);
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
+ static const char LUAVIM_DICT[] = "dict";
|
|
Karsten Hopp |
b81f34 |
+ static const char LUAVIM_LIST[] = "list";
|
|
Karsten Hopp |
b81f34 |
static const char LUAVIM_BUFFER[] = "buffer";
|
|
Karsten Hopp |
b81f34 |
static const char LUAVIM_WINDOW[] = "window";
|
|
Karsten Hopp |
b81f34 |
static const char LUAVIM_FREE[] = "luaV_free";
|
|
Karsten Hopp |
b81f34 |
+ static const char LUAVIM_LUAEVAL[] = "luaV_luaeval";
|
|
Karsten Hopp |
b81f34 |
+ static const char LUAVIM_SETREF[] = "luaV_setref";
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
+ /* most functions are closures with a cache table as first upvalue;
|
|
Karsten Hopp |
b81f34 |
+ * get/setudata manage references to vim userdata in cache table through
|
|
Karsten Hopp |
b81f34 |
+ * object pointers (light userdata) */
|
|
Karsten Hopp |
b81f34 |
+ #define luaV_getudata(L, v) \
|
|
Karsten Hopp |
b81f34 |
+ lua_pushlightuserdata((L), (void *) (v)); \
|
|
Karsten Hopp |
b81f34 |
+ lua_rawget((L), lua_upvalueindex(1))
|
|
Karsten Hopp |
b81f34 |
+ #define luaV_setudata(L, v) \
|
|
Karsten Hopp |
b81f34 |
+ lua_pushlightuserdata((L), (void *) (v)); \
|
|
Karsten Hopp |
b81f34 |
+ lua_pushvalue((L), -2); \
|
|
Karsten Hopp |
b81f34 |
+ lua_rawset((L), lua_upvalueindex(1))
|
|
Karsten Hopp |
b81f34 |
#define luaV_getfield(L, s) \
|
|
Karsten Hopp |
b81f34 |
lua_pushlightuserdata((L), (void *)(s)); \
|
|
Karsten Hopp |
b81f34 |
lua_rawget((L), LUA_REGISTRYINDEX)
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 38,43 ****
|
|
Karsten Hopp |
b81f34 |
--- 56,70 ----
|
|
Karsten Hopp |
b81f34 |
#define luaV_msg(L) luaV_msgfunc((L), (msgfunc_T) msg)
|
|
Karsten Hopp |
b81f34 |
#define luaV_emsg(L) luaV_msgfunc((L), (msgfunc_T) emsg)
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
+ static luaV_List *luaV_pushlist (lua_State *L, list_T *lis);
|
|
Karsten Hopp |
b81f34 |
+ static luaV_Dict *luaV_pushdict (lua_State *L, dict_T *dic);
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ #if LUA_VERSION_NUM <= 501
|
|
Karsten Hopp |
b81f34 |
+ #define luaV_openlib(L, l, n) luaL_openlib(L, NULL, l, n)
|
|
Karsten Hopp |
b81f34 |
+ #define luaL_typeerror luaL_typerror
|
|
Karsten Hopp |
b81f34 |
+ #else
|
|
Karsten Hopp |
b81f34 |
+ #define luaV_openlib luaL_setfuncs
|
|
Karsten Hopp |
b81f34 |
+ #endif
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
#ifdef DYNAMIC_LUA
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 54,85 ****
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
/* lauxlib */
|
|
Karsten Hopp |
b81f34 |
#define luaL_register dll_luaL_register
|
|
Karsten Hopp |
b81f34 |
#define luaL_typerror dll_luaL_typerror
|
|
Karsten Hopp |
b81f34 |
#define luaL_checklstring dll_luaL_checklstring
|
|
Karsten Hopp |
b81f34 |
#define luaL_checkinteger dll_luaL_checkinteger
|
|
Karsten Hopp |
b81f34 |
#define luaL_optinteger dll_luaL_optinteger
|
|
Karsten Hopp |
b81f34 |
#define luaL_checktype dll_luaL_checktype
|
|
Karsten Hopp |
b81f34 |
#define luaL_error dll_luaL_error
|
|
Karsten Hopp |
b81f34 |
- #define luaL_loadfile dll_luaL_loadfile
|
|
Karsten Hopp |
b81f34 |
- #define luaL_loadbuffer dll_luaL_loadbuffer
|
|
Karsten Hopp |
b81f34 |
#define luaL_newstate dll_luaL_newstate
|
|
Karsten Hopp |
b81f34 |
#define luaL_buffinit dll_luaL_buffinit
|
|
Karsten Hopp |
b81f34 |
- #define luaL_prepbuffer dll_luaL_prepbuffer
|
|
Karsten Hopp |
b81f34 |
#define luaL_addlstring dll_luaL_addlstring
|
|
Karsten Hopp |
b81f34 |
#define luaL_pushresult dll_luaL_pushresult
|
|
Karsten Hopp |
b81f34 |
/* lua */
|
|
Karsten Hopp |
b81f34 |
#define lua_close dll_lua_close
|
|
Karsten Hopp |
b81f34 |
#define lua_gettop dll_lua_gettop
|
|
Karsten Hopp |
b81f34 |
#define lua_settop dll_lua_settop
|
|
Karsten Hopp |
b81f34 |
#define lua_pushvalue dll_lua_pushvalue
|
|
Karsten Hopp |
b81f34 |
#define lua_replace dll_lua_replace
|
|
Karsten Hopp |
b81f34 |
#define lua_isnumber dll_lua_isnumber
|
|
Karsten Hopp |
b81f34 |
#define lua_isstring dll_lua_isstring
|
|
Karsten Hopp |
b81f34 |
#define lua_type dll_lua_type
|
|
Karsten Hopp |
b81f34 |
#define lua_rawequal dll_lua_rawequal
|
|
Karsten Hopp |
b81f34 |
- #define lua_tonumber dll_lua_tonumber
|
|
Karsten Hopp |
b81f34 |
- #define lua_tointeger dll_lua_tointeger
|
|
Karsten Hopp |
b81f34 |
#define lua_toboolean dll_lua_toboolean
|
|
Karsten Hopp |
b81f34 |
#define lua_tolstring dll_lua_tolstring
|
|
Karsten Hopp |
b81f34 |
#define lua_touserdata dll_lua_touserdata
|
|
Karsten Hopp |
b81f34 |
--- 81,134 ----
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
/* lauxlib */
|
|
Karsten Hopp |
b81f34 |
+ #if LUA_VERSION_NUM <= 501
|
|
Karsten Hopp |
b81f34 |
#define luaL_register dll_luaL_register
|
|
Karsten Hopp |
b81f34 |
+ #define luaL_prepbuffer dll_luaL_prepbuffer
|
|
Karsten Hopp |
b81f34 |
+ #define luaL_openlib dll_luaL_openlib
|
|
Karsten Hopp |
b81f34 |
#define luaL_typerror dll_luaL_typerror
|
|
Karsten Hopp |
b81f34 |
+ #define luaL_loadfile dll_luaL_loadfile
|
|
Karsten Hopp |
b81f34 |
+ #define luaL_loadbuffer dll_luaL_loadbuffer
|
|
Karsten Hopp |
b81f34 |
+ #else
|
|
Karsten Hopp |
b81f34 |
+ #define luaL_prepbuffsize dll_luaL_prepbuffsize
|
|
Karsten Hopp |
b81f34 |
+ #define luaL_setfuncs dll_luaL_setfuncs
|
|
Karsten Hopp |
b81f34 |
+ #define luaL_loadfilex dll_luaL_loadfilex
|
|
Karsten Hopp |
b81f34 |
+ #define luaL_loadbufferx dll_luaL_loadbufferx
|
|
Karsten Hopp |
b81f34 |
+ #define luaL_argerror dll_luaL_argerror
|
|
Karsten Hopp |
b81f34 |
+ #endif
|
|
Karsten Hopp |
b81f34 |
#define luaL_checklstring dll_luaL_checklstring
|
|
Karsten Hopp |
b81f34 |
#define luaL_checkinteger dll_luaL_checkinteger
|
|
Karsten Hopp |
b81f34 |
#define luaL_optinteger dll_luaL_optinteger
|
|
Karsten Hopp |
b81f34 |
#define luaL_checktype dll_luaL_checktype
|
|
Karsten Hopp |
b81f34 |
#define luaL_error dll_luaL_error
|
|
Karsten Hopp |
b81f34 |
#define luaL_newstate dll_luaL_newstate
|
|
Karsten Hopp |
b81f34 |
#define luaL_buffinit dll_luaL_buffinit
|
|
Karsten Hopp |
b81f34 |
#define luaL_addlstring dll_luaL_addlstring
|
|
Karsten Hopp |
b81f34 |
#define luaL_pushresult dll_luaL_pushresult
|
|
Karsten Hopp |
b81f34 |
/* lua */
|
|
Karsten Hopp |
b81f34 |
+ #if LUA_VERSION_NUM <= 501
|
|
Karsten Hopp |
b81f34 |
+ #define lua_tonumber dll_lua_tonumber
|
|
Karsten Hopp |
b81f34 |
+ #define lua_tointeger dll_lua_tointeger
|
|
Karsten Hopp |
b81f34 |
+ #define lua_call dll_lua_call
|
|
Karsten Hopp |
b81f34 |
+ #define lua_pcall dll_lua_pcall
|
|
Karsten Hopp |
b81f34 |
+ #else
|
|
Karsten Hopp |
b81f34 |
+ #define lua_tonumberx dll_lua_tonumberx
|
|
Karsten Hopp |
b81f34 |
+ #define lua_tointegerx dll_lua_tointegerx
|
|
Karsten Hopp |
b81f34 |
+ #define lua_callk dll_lua_callk
|
|
Karsten Hopp |
b81f34 |
+ #define lua_pcallk dll_lua_pcallk
|
|
Karsten Hopp |
b81f34 |
+ #define lua_getglobal dll_lua_getglobal
|
|
Karsten Hopp |
b81f34 |
+ #define lua_setglobal dll_lua_setglobal
|
|
Karsten Hopp |
b81f34 |
+ #define lua_typename dll_lua_typename
|
|
Karsten Hopp |
b81f34 |
+ #endif
|
|
Karsten Hopp |
b81f34 |
#define lua_close dll_lua_close
|
|
Karsten Hopp |
b81f34 |
#define lua_gettop dll_lua_gettop
|
|
Karsten Hopp |
b81f34 |
#define lua_settop dll_lua_settop
|
|
Karsten Hopp |
b81f34 |
#define lua_pushvalue dll_lua_pushvalue
|
|
Karsten Hopp |
b81f34 |
#define lua_replace dll_lua_replace
|
|
Karsten Hopp |
b81f34 |
+ #define lua_remove dll_lua_remove
|
|
Karsten Hopp |
b81f34 |
#define lua_isnumber dll_lua_isnumber
|
|
Karsten Hopp |
b81f34 |
#define lua_isstring dll_lua_isstring
|
|
Karsten Hopp |
b81f34 |
#define lua_type dll_lua_type
|
|
Karsten Hopp |
b81f34 |
#define lua_rawequal dll_lua_rawequal
|
|
Karsten Hopp |
b81f34 |
#define lua_toboolean dll_lua_toboolean
|
|
Karsten Hopp |
b81f34 |
#define lua_tolstring dll_lua_tolstring
|
|
Karsten Hopp |
b81f34 |
#define lua_touserdata dll_lua_touserdata
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 94,109 ****
|
|
Karsten Hopp |
b81f34 |
#define lua_pushlightuserdata dll_lua_pushlightuserdata
|
|
Karsten Hopp |
b81f34 |
#define lua_getfield dll_lua_getfield
|
|
Karsten Hopp |
b81f34 |
#define lua_rawget dll_lua_rawget
|
|
Karsten Hopp |
b81f34 |
#define lua_createtable dll_lua_createtable
|
|
Karsten Hopp |
b81f34 |
#define lua_newuserdata dll_lua_newuserdata
|
|
Karsten Hopp |
b81f34 |
#define lua_getmetatable dll_lua_getmetatable
|
|
Karsten Hopp |
b81f34 |
#define lua_setfield dll_lua_setfield
|
|
Karsten Hopp |
b81f34 |
#define lua_rawset dll_lua_rawset
|
|
Karsten Hopp |
b81f34 |
#define lua_rawseti dll_lua_rawseti
|
|
Karsten Hopp |
b81f34 |
- #define lua_remove dll_lua_remove
|
|
Karsten Hopp |
b81f34 |
#define lua_setmetatable dll_lua_setmetatable
|
|
Karsten Hopp |
b81f34 |
- #define lua_call dll_lua_call
|
|
Karsten Hopp |
b81f34 |
- #define lua_pcall dll_lua_pcall
|
|
Karsten Hopp |
b81f34 |
/* libs */
|
|
Karsten Hopp |
b81f34 |
#define luaopen_base dll_luaopen_base
|
|
Karsten Hopp |
b81f34 |
#define luaopen_table dll_luaopen_table
|
|
Karsten Hopp |
b81f34 |
--- 143,156 ----
|
|
Karsten Hopp |
b81f34 |
#define lua_pushlightuserdata dll_lua_pushlightuserdata
|
|
Karsten Hopp |
b81f34 |
#define lua_getfield dll_lua_getfield
|
|
Karsten Hopp |
b81f34 |
#define lua_rawget dll_lua_rawget
|
|
Karsten Hopp |
b81f34 |
+ #define lua_rawgeti dll_lua_rawgeti
|
|
Karsten Hopp |
b81f34 |
#define lua_createtable dll_lua_createtable
|
|
Karsten Hopp |
b81f34 |
#define lua_newuserdata dll_lua_newuserdata
|
|
Karsten Hopp |
b81f34 |
#define lua_getmetatable dll_lua_getmetatable
|
|
Karsten Hopp |
b81f34 |
#define lua_setfield dll_lua_setfield
|
|
Karsten Hopp |
b81f34 |
#define lua_rawset dll_lua_rawset
|
|
Karsten Hopp |
b81f34 |
#define lua_rawseti dll_lua_rawseti
|
|
Karsten Hopp |
b81f34 |
#define lua_setmetatable dll_lua_setmetatable
|
|
Karsten Hopp |
b81f34 |
/* libs */
|
|
Karsten Hopp |
b81f34 |
#define luaopen_base dll_luaopen_base
|
|
Karsten Hopp |
b81f34 |
#define luaopen_table dll_luaopen_table
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 116,147 ****
|
|
Karsten Hopp |
b81f34 |
#define luaL_openlibs dll_luaL_openlibs
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
/* lauxlib */
|
|
Karsten Hopp |
b81f34 |
void (*dll_luaL_register) (lua_State *L, const char *libname, const luaL_Reg *l);
|
|
Karsten Hopp |
b81f34 |
int (*dll_luaL_typerror) (lua_State *L, int narg, const char *tname);
|
|
Karsten Hopp |
b81f34 |
const char *(*dll_luaL_checklstring) (lua_State *L, int numArg, size_t *l);
|
|
Karsten Hopp |
b81f34 |
lua_Integer (*dll_luaL_checkinteger) (lua_State *L, int numArg);
|
|
Karsten Hopp |
b81f34 |
lua_Integer (*dll_luaL_optinteger) (lua_State *L, int nArg, lua_Integer def);
|
|
Karsten Hopp |
b81f34 |
void (*dll_luaL_checktype) (lua_State *L, int narg, int t);
|
|
Karsten Hopp |
b81f34 |
int (*dll_luaL_error) (lua_State *L, const char *fmt, ...);
|
|
Karsten Hopp |
b81f34 |
- int (*dll_luaL_loadfile) (lua_State *L, const char *filename);
|
|
Karsten Hopp |
b81f34 |
- int (*dll_luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, const char *name);
|
|
Karsten Hopp |
b81f34 |
lua_State *(*dll_luaL_newstate) (void);
|
|
Karsten Hopp |
b81f34 |
void (*dll_luaL_buffinit) (lua_State *L, luaL_Buffer *B);
|
|
Karsten Hopp |
b81f34 |
- char *(*dll_luaL_prepbuffer) (luaL_Buffer *B);
|
|
Karsten Hopp |
b81f34 |
void (*dll_luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
|
|
Karsten Hopp |
b81f34 |
void (*dll_luaL_pushresult) (luaL_Buffer *B);
|
|
Karsten Hopp |
b81f34 |
/* lua */
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_close) (lua_State *L);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_gettop) (lua_State *L);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_settop) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_pushvalue) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_replace) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_isnumber) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_isstring) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_type) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_rawequal) (lua_State *L, int idx1, int idx2);
|
|
Karsten Hopp |
b81f34 |
- lua_Number (*dll_lua_tonumber) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
- lua_Integer (*dll_lua_tointeger) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_toboolean) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
const char *(*dll_lua_tolstring) (lua_State *L, int idx, size_t *len);
|
|
Karsten Hopp |
b81f34 |
void *(*dll_lua_touserdata) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
--- 163,218 ----
|
|
Karsten Hopp |
b81f34 |
#define luaL_openlibs dll_luaL_openlibs
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
/* lauxlib */
|
|
Karsten Hopp |
b81f34 |
+ #if LUA_VERSION_NUM <= 501
|
|
Karsten Hopp |
b81f34 |
void (*dll_luaL_register) (lua_State *L, const char *libname, const luaL_Reg *l);
|
|
Karsten Hopp |
b81f34 |
+ char *(*dll_luaL_prepbuffer) (luaL_Buffer *B);
|
|
Karsten Hopp |
b81f34 |
+ void (*dll_luaL_openlib) (lua_State *L, const char *libname, const luaL_Reg *l, int nup);
|
|
Karsten Hopp |
b81f34 |
int (*dll_luaL_typerror) (lua_State *L, int narg, const char *tname);
|
|
Karsten Hopp |
b81f34 |
+ int (*dll_luaL_loadfile) (lua_State *L, const char *filename);
|
|
Karsten Hopp |
b81f34 |
+ int (*dll_luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, const char *name);
|
|
Karsten Hopp |
b81f34 |
+ #else
|
|
Karsten Hopp |
b81f34 |
+ char *(*dll_luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);
|
|
Karsten Hopp |
b81f34 |
+ void (*dll_luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
|
|
Karsten Hopp |
b81f34 |
+ int (*dll_luaL_loadfilex) (lua_State *L, const char *filename, const char *mode);
|
|
Karsten Hopp |
b81f34 |
+ int (*dll_luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, const char *name, const char *mode);
|
|
Karsten Hopp |
b81f34 |
+ int (*dll_luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
|
|
Karsten Hopp |
b81f34 |
+ #endif
|
|
Karsten Hopp |
b81f34 |
const char *(*dll_luaL_checklstring) (lua_State *L, int numArg, size_t *l);
|
|
Karsten Hopp |
b81f34 |
lua_Integer (*dll_luaL_checkinteger) (lua_State *L, int numArg);
|
|
Karsten Hopp |
b81f34 |
lua_Integer (*dll_luaL_optinteger) (lua_State *L, int nArg, lua_Integer def);
|
|
Karsten Hopp |
b81f34 |
void (*dll_luaL_checktype) (lua_State *L, int narg, int t);
|
|
Karsten Hopp |
b81f34 |
int (*dll_luaL_error) (lua_State *L, const char *fmt, ...);
|
|
Karsten Hopp |
b81f34 |
lua_State *(*dll_luaL_newstate) (void);
|
|
Karsten Hopp |
b81f34 |
void (*dll_luaL_buffinit) (lua_State *L, luaL_Buffer *B);
|
|
Karsten Hopp |
b81f34 |
void (*dll_luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
|
|
Karsten Hopp |
b81f34 |
void (*dll_luaL_pushresult) (luaL_Buffer *B);
|
|
Karsten Hopp |
b81f34 |
/* lua */
|
|
Karsten Hopp |
b81f34 |
+ #if LUA_VERSION_NUM <= 501
|
|
Karsten Hopp |
b81f34 |
+ lua_Number (*dll_lua_tonumber) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
+ lua_Integer (*dll_lua_tointeger) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
+ void (*dll_lua_call) (lua_State *L, int nargs, int nresults);
|
|
Karsten Hopp |
b81f34 |
+ int (*dll_lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
|
|
Karsten Hopp |
b81f34 |
+ #else
|
|
Karsten Hopp |
b81f34 |
+ lua_Number (*dll_lua_tonumberx) (lua_State *L, int idx, int *isnum);
|
|
Karsten Hopp |
b81f34 |
+ lua_Integer (*dll_lua_tointegerx) (lua_State *L, int idx, int *isnum);
|
|
Karsten Hopp |
b81f34 |
+ void (*dll_lua_callk) (lua_State *L, int nargs, int nresults, int ctx,
|
|
Karsten Hopp |
b81f34 |
+ lua_CFunction k);
|
|
Karsten Hopp |
b81f34 |
+ int (*dll_lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
|
|
Karsten Hopp |
b81f34 |
+ int ctx, lua_CFunction k);
|
|
Karsten Hopp |
b81f34 |
+ void (*dll_lua_getglobal) (lua_State *L, const char *var);
|
|
Karsten Hopp |
b81f34 |
+ void (*dll_lua_setglobal) (lua_State *L, const char *var);
|
|
Karsten Hopp |
b81f34 |
+ const char *(*dll_lua_typename) (lua_State *L, int tp);
|
|
Karsten Hopp |
b81f34 |
+ #endif
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_close) (lua_State *L);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_gettop) (lua_State *L);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_settop) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_pushvalue) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_replace) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
+ void (*dll_lua_remove) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_isnumber) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_isstring) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_type) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_rawequal) (lua_State *L, int idx1, int idx2);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_toboolean) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
const char *(*dll_lua_tolstring) (lua_State *L, int idx, size_t *len);
|
|
Karsten Hopp |
b81f34 |
void *(*dll_lua_touserdata) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 156,171 ****
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_pushlightuserdata) (lua_State *L, void *p);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_getfield) (lua_State *L, int idx, const char *k);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_rawget) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_createtable) (lua_State *L, int narr, int nrec);
|
|
Karsten Hopp |
b81f34 |
void *(*dll_lua_newuserdata) (lua_State *L, size_t sz);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_getmetatable) (lua_State *L, int objindex);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_setfield) (lua_State *L, int idx, const char *k);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_rawset) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_rawseti) (lua_State *L, int idx, int n);
|
|
Karsten Hopp |
b81f34 |
- void (*dll_lua_remove) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_setmetatable) (lua_State *L, int objindex);
|
|
Karsten Hopp |
b81f34 |
- void (*dll_lua_call) (lua_State *L, int nargs, int nresults);
|
|
Karsten Hopp |
b81f34 |
- int (*dll_lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
|
|
Karsten Hopp |
b81f34 |
/* libs */
|
|
Karsten Hopp |
b81f34 |
int (*dll_luaopen_base) (lua_State *L);
|
|
Karsten Hopp |
b81f34 |
int (*dll_luaopen_table) (lua_State *L);
|
|
Karsten Hopp |
b81f34 |
--- 227,240 ----
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_pushlightuserdata) (lua_State *L, void *p);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_getfield) (lua_State *L, int idx, const char *k);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_rawget) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
+ void (*dll_lua_rawgeti) (lua_State *L, int idx, int n);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_createtable) (lua_State *L, int narr, int nrec);
|
|
Karsten Hopp |
b81f34 |
void *(*dll_lua_newuserdata) (lua_State *L, size_t sz);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_getmetatable) (lua_State *L, int objindex);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_setfield) (lua_State *L, int idx, const char *k);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_rawset) (lua_State *L, int idx);
|
|
Karsten Hopp |
b81f34 |
void (*dll_lua_rawseti) (lua_State *L, int idx, int n);
|
|
Karsten Hopp |
b81f34 |
int (*dll_lua_setmetatable) (lua_State *L, int objindex);
|
|
Karsten Hopp |
b81f34 |
/* libs */
|
|
Karsten Hopp |
b81f34 |
int (*dll_luaopen_base) (lua_State *L);
|
|
Karsten Hopp |
b81f34 |
int (*dll_luaopen_table) (lua_State *L);
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 185,216 ****
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static const luaV_Reg luaV_dll[] = {
|
|
Karsten Hopp |
b81f34 |
/* lauxlib */
|
|
Karsten Hopp |
b81f34 |
{"luaL_register", (luaV_function) &dll_luaL_register},
|
|
Karsten Hopp |
b81f34 |
{"luaL_typerror", (luaV_function) &dll_luaL_typerror},
|
|
Karsten Hopp |
b81f34 |
{"luaL_checklstring", (luaV_function) &dll_luaL_checklstring},
|
|
Karsten Hopp |
b81f34 |
{"luaL_checkinteger", (luaV_function) &dll_luaL_checkinteger},
|
|
Karsten Hopp |
b81f34 |
{"luaL_optinteger", (luaV_function) &dll_luaL_optinteger},
|
|
Karsten Hopp |
b81f34 |
{"luaL_checktype", (luaV_function) &dll_luaL_checktype},
|
|
Karsten Hopp |
b81f34 |
{"luaL_error", (luaV_function) &dll_luaL_error},
|
|
Karsten Hopp |
b81f34 |
- {"luaL_loadfile", (luaV_function) &dll_luaL_loadfile},
|
|
Karsten Hopp |
b81f34 |
- {"luaL_loadbuffer", (luaV_function) &dll_luaL_loadbuffer},
|
|
Karsten Hopp |
b81f34 |
{"luaL_newstate", (luaV_function) &dll_luaL_newstate},
|
|
Karsten Hopp |
b81f34 |
{"luaL_buffinit", (luaV_function) &dll_luaL_buffinit},
|
|
Karsten Hopp |
b81f34 |
- {"luaL_prepbuffer", (luaV_function) &dll_luaL_prepbuffer},
|
|
Karsten Hopp |
b81f34 |
{"luaL_addlstring", (luaV_function) &dll_luaL_addlstring},
|
|
Karsten Hopp |
b81f34 |
{"luaL_pushresult", (luaV_function) &dll_luaL_pushresult},
|
|
Karsten Hopp |
b81f34 |
/* lua */
|
|
Karsten Hopp |
b81f34 |
{"lua_close", (luaV_function) &dll_lua_close},
|
|
Karsten Hopp |
b81f34 |
{"lua_gettop", (luaV_function) &dll_lua_gettop},
|
|
Karsten Hopp |
b81f34 |
{"lua_settop", (luaV_function) &dll_lua_settop},
|
|
Karsten Hopp |
b81f34 |
{"lua_pushvalue", (luaV_function) &dll_lua_pushvalue},
|
|
Karsten Hopp |
b81f34 |
{"lua_replace", (luaV_function) &dll_lua_replace},
|
|
Karsten Hopp |
b81f34 |
{"lua_isnumber", (luaV_function) &dll_lua_isnumber},
|
|
Karsten Hopp |
b81f34 |
{"lua_isstring", (luaV_function) &dll_lua_isstring},
|
|
Karsten Hopp |
b81f34 |
{"lua_type", (luaV_function) &dll_lua_type},
|
|
Karsten Hopp |
b81f34 |
{"lua_rawequal", (luaV_function) &dll_lua_rawequal},
|
|
Karsten Hopp |
b81f34 |
- {"lua_tonumber", (luaV_function) &dll_lua_tonumber},
|
|
Karsten Hopp |
b81f34 |
- {"lua_tointeger", (luaV_function) &dll_lua_tointeger},
|
|
Karsten Hopp |
b81f34 |
{"lua_toboolean", (luaV_function) &dll_lua_toboolean},
|
|
Karsten Hopp |
b81f34 |
{"lua_tolstring", (luaV_function) &dll_lua_tolstring},
|
|
Karsten Hopp |
b81f34 |
{"lua_touserdata", (luaV_function) &dll_lua_touserdata},
|
|
Karsten Hopp |
b81f34 |
--- 254,307 ----
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static const luaV_Reg luaV_dll[] = {
|
|
Karsten Hopp |
b81f34 |
/* lauxlib */
|
|
Karsten Hopp |
b81f34 |
+ #if LUA_VERSION_NUM <= 501
|
|
Karsten Hopp |
b81f34 |
{"luaL_register", (luaV_function) &dll_luaL_register},
|
|
Karsten Hopp |
b81f34 |
+ {"luaL_prepbuffer", (luaV_function) &dll_luaL_prepbuffer},
|
|
Karsten Hopp |
b81f34 |
+ {"luaL_openlib", (luaV_function) &dll_luaL_openlib},
|
|
Karsten Hopp |
b81f34 |
{"luaL_typerror", (luaV_function) &dll_luaL_typerror},
|
|
Karsten Hopp |
b81f34 |
+ {"luaL_loadfile", (luaV_function) &dll_luaL_loadfile},
|
|
Karsten Hopp |
b81f34 |
+ {"luaL_loadbuffer", (luaV_function) &dll_luaL_loadbuffer},
|
|
Karsten Hopp |
b81f34 |
+ #else
|
|
Karsten Hopp |
b81f34 |
+ {"luaL_prepbuffsize", (luaV_function) &dll_luaL_prepbuffsize},
|
|
Karsten Hopp |
b81f34 |
+ {"luaL_setfuncs", (luaV_function) &dll_luaL_setfuncs},
|
|
Karsten Hopp |
b81f34 |
+ {"luaL_loadfilex", (luaV_function) &dll_luaL_loadfilex},
|
|
Karsten Hopp |
b81f34 |
+ {"luaL_loadbufferx", (luaV_function) &dll_luaL_loadbufferx},
|
|
Karsten Hopp |
b81f34 |
+ {"luaL_argerror", (luaV_function) &dll_luaL_argerror},
|
|
Karsten Hopp |
b81f34 |
+ #endif
|
|
Karsten Hopp |
b81f34 |
{"luaL_checklstring", (luaV_function) &dll_luaL_checklstring},
|
|
Karsten Hopp |
b81f34 |
{"luaL_checkinteger", (luaV_function) &dll_luaL_checkinteger},
|
|
Karsten Hopp |
b81f34 |
{"luaL_optinteger", (luaV_function) &dll_luaL_optinteger},
|
|
Karsten Hopp |
b81f34 |
{"luaL_checktype", (luaV_function) &dll_luaL_checktype},
|
|
Karsten Hopp |
b81f34 |
{"luaL_error", (luaV_function) &dll_luaL_error},
|
|
Karsten Hopp |
b81f34 |
{"luaL_newstate", (luaV_function) &dll_luaL_newstate},
|
|
Karsten Hopp |
b81f34 |
{"luaL_buffinit", (luaV_function) &dll_luaL_buffinit},
|
|
Karsten Hopp |
b81f34 |
{"luaL_addlstring", (luaV_function) &dll_luaL_addlstring},
|
|
Karsten Hopp |
b81f34 |
{"luaL_pushresult", (luaV_function) &dll_luaL_pushresult},
|
|
Karsten Hopp |
b81f34 |
/* lua */
|
|
Karsten Hopp |
b81f34 |
+ #if LUA_VERSION_NUM <= 501
|
|
Karsten Hopp |
b81f34 |
+ {"lua_tonumber", (luaV_function) &dll_lua_tonumber},
|
|
Karsten Hopp |
b81f34 |
+ {"lua_tointeger", (luaV_function) &dll_lua_tointeger},
|
|
Karsten Hopp |
b81f34 |
+ {"lua_call", (luaV_function) &dll_lua_call},
|
|
Karsten Hopp |
b81f34 |
+ {"lua_pcall", (luaV_function) &dll_lua_pcall},
|
|
Karsten Hopp |
b81f34 |
+ #else
|
|
Karsten Hopp |
b81f34 |
+ {"lua_tonumberx", (luaV_function) &dll_lua_tonumberx},
|
|
Karsten Hopp |
b81f34 |
+ {"lua_tointegerx", (luaV_function) &dll_lua_tointegerx},
|
|
Karsten Hopp |
b81f34 |
+ {"lua_callk", (luaV_function) &dll_lua_callk},
|
|
Karsten Hopp |
b81f34 |
+ {"lua_pcallk", (luaV_function) &dll_lua_pcallk},
|
|
Karsten Hopp |
b81f34 |
+ {"lua_getglobal", (luaV_function) &dll_lua_getglobal},
|
|
Karsten Hopp |
b81f34 |
+ {"lua_setglobal", (luaV_function) &dll_lua_setglobal},
|
|
Karsten Hopp |
b81f34 |
+ {"lua_typename", (luaV_function) &dll_lua_typename},
|
|
Karsten Hopp |
b81f34 |
+ #endif
|
|
Karsten Hopp |
b81f34 |
{"lua_close", (luaV_function) &dll_lua_close},
|
|
Karsten Hopp |
b81f34 |
{"lua_gettop", (luaV_function) &dll_lua_gettop},
|
|
Karsten Hopp |
b81f34 |
{"lua_settop", (luaV_function) &dll_lua_settop},
|
|
Karsten Hopp |
b81f34 |
{"lua_pushvalue", (luaV_function) &dll_lua_pushvalue},
|
|
Karsten Hopp |
b81f34 |
{"lua_replace", (luaV_function) &dll_lua_replace},
|
|
Karsten Hopp |
b81f34 |
+ {"lua_remove", (luaV_function) &dll_lua_remove},
|
|
Karsten Hopp |
b81f34 |
{"lua_isnumber", (luaV_function) &dll_lua_isnumber},
|
|
Karsten Hopp |
b81f34 |
{"lua_isstring", (luaV_function) &dll_lua_isstring},
|
|
Karsten Hopp |
b81f34 |
{"lua_type", (luaV_function) &dll_lua_type},
|
|
Karsten Hopp |
b81f34 |
{"lua_rawequal", (luaV_function) &dll_lua_rawequal},
|
|
Karsten Hopp |
b81f34 |
{"lua_toboolean", (luaV_function) &dll_lua_toboolean},
|
|
Karsten Hopp |
b81f34 |
{"lua_tolstring", (luaV_function) &dll_lua_tolstring},
|
|
Karsten Hopp |
b81f34 |
{"lua_touserdata", (luaV_function) &dll_lua_touserdata},
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 225,240 ****
|
|
Karsten Hopp |
b81f34 |
{"lua_pushlightuserdata", (luaV_function) &dll_lua_pushlightuserdata},
|
|
Karsten Hopp |
b81f34 |
{"lua_getfield", (luaV_function) &dll_lua_getfield},
|
|
Karsten Hopp |
b81f34 |
{"lua_rawget", (luaV_function) &dll_lua_rawget},
|
|
Karsten Hopp |
b81f34 |
{"lua_createtable", (luaV_function) &dll_lua_createtable},
|
|
Karsten Hopp |
b81f34 |
{"lua_newuserdata", (luaV_function) &dll_lua_newuserdata},
|
|
Karsten Hopp |
b81f34 |
{"lua_getmetatable", (luaV_function) &dll_lua_getmetatable},
|
|
Karsten Hopp |
b81f34 |
{"lua_setfield", (luaV_function) &dll_lua_setfield},
|
|
Karsten Hopp |
b81f34 |
{"lua_rawset", (luaV_function) &dll_lua_rawset},
|
|
Karsten Hopp |
b81f34 |
{"lua_rawseti", (luaV_function) &dll_lua_rawseti},
|
|
Karsten Hopp |
b81f34 |
- {"lua_remove", (luaV_function) &dll_lua_remove},
|
|
Karsten Hopp |
b81f34 |
{"lua_setmetatable", (luaV_function) &dll_lua_setmetatable},
|
|
Karsten Hopp |
b81f34 |
- {"lua_call", (luaV_function) &dll_lua_call},
|
|
Karsten Hopp |
b81f34 |
- {"lua_pcall", (luaV_function) &dll_lua_pcall},
|
|
Karsten Hopp |
b81f34 |
/* libs */
|
|
Karsten Hopp |
b81f34 |
{"luaopen_base", (luaV_function) &dll_luaopen_base},
|
|
Karsten Hopp |
b81f34 |
{"luaopen_table", (luaV_function) &dll_luaopen_table},
|
|
Karsten Hopp |
b81f34 |
--- 316,329 ----
|
|
Karsten Hopp |
b81f34 |
{"lua_pushlightuserdata", (luaV_function) &dll_lua_pushlightuserdata},
|
|
Karsten Hopp |
b81f34 |
{"lua_getfield", (luaV_function) &dll_lua_getfield},
|
|
Karsten Hopp |
b81f34 |
{"lua_rawget", (luaV_function) &dll_lua_rawget},
|
|
Karsten Hopp |
b81f34 |
+ {"lua_rawgeti", (luaV_function) &dll_lua_rawgeti},
|
|
Karsten Hopp |
b81f34 |
{"lua_createtable", (luaV_function) &dll_lua_createtable},
|
|
Karsten Hopp |
b81f34 |
{"lua_newuserdata", (luaV_function) &dll_lua_newuserdata},
|
|
Karsten Hopp |
b81f34 |
{"lua_getmetatable", (luaV_function) &dll_lua_getmetatable},
|
|
Karsten Hopp |
b81f34 |
{"lua_setfield", (luaV_function) &dll_lua_setfield},
|
|
Karsten Hopp |
b81f34 |
{"lua_rawset", (luaV_function) &dll_lua_rawset},
|
|
Karsten Hopp |
b81f34 |
{"lua_rawseti", (luaV_function) &dll_lua_rawseti},
|
|
Karsten Hopp |
b81f34 |
{"lua_setmetatable", (luaV_function) &dll_lua_setmetatable},
|
|
Karsten Hopp |
b81f34 |
/* libs */
|
|
Karsten Hopp |
b81f34 |
{"luaopen_base", (luaV_function) &dll_luaopen_base},
|
|
Karsten Hopp |
b81f34 |
{"luaopen_table", (luaV_function) &dll_luaopen_table},
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 294,299 ****
|
|
Karsten Hopp |
b81f34 |
--- 383,398 ----
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
#endif /* DYNAMIC_LUA */
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
+ #if LUA_VERSION_NUM > 501
|
|
Karsten Hopp |
b81f34 |
+ static int
|
|
Karsten Hopp |
b81f34 |
+ luaL_typeerror (lua_State *L, int narg, const char *tname)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ const char *msg = lua_pushfstring(L, "%s expected, got %s",
|
|
Karsten Hopp |
b81f34 |
+ tname, luaL_typename(L, narg));
|
|
Karsten Hopp |
b81f34 |
+ return luaL_argerror(L, narg, msg);
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+ #endif
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
/* ======= Internal ======= */
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 327,343 ****
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static void *
|
|
Karsten Hopp |
b81f34 |
luaV_checkudata(lua_State *L, int ud, const char *tname)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
void *p = luaV_toudata(L, ud, tname);
|
|
Karsten Hopp |
b81f34 |
! if (p == NULL) luaL_typerror(L, ud, tname);
|
|
Karsten Hopp |
b81f34 |
return p;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static void
|
|
Karsten Hopp |
b81f34 |
luaV_pushtypval(lua_State *L, typval_T *tv)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! if (tv == NULL) luaL_error(L, "null type");
|
|
Karsten Hopp |
b81f34 |
switch (tv->v_type)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
case VAR_STRING:
|
|
Karsten Hopp |
b81f34 |
--- 426,460 ----
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static void *
|
|
Karsten Hopp |
b81f34 |
+ luaV_checkcache(lua_State *L, void *p)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ luaV_getudata(L, p);
|
|
Karsten Hopp |
b81f34 |
+ if (lua_isnil(L, -1)) luaL_error(L, "invalid object");
|
|
Karsten Hopp |
b81f34 |
+ lua_pop(L, 1);
|
|
Karsten Hopp |
b81f34 |
+ return p;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ #define luaV_unbox(L,luatyp,ud) (*((luatyp *) lua_touserdata((L),(ud))))
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ #define luaV_checkvalid(L,luatyp,ud) \
|
|
Karsten Hopp |
b81f34 |
+ luaV_checkcache((L), (void *) luaV_unbox((L),luatyp,(ud)))
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ static void *
|
|
Karsten Hopp |
b81f34 |
luaV_checkudata(lua_State *L, int ud, const char *tname)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
void *p = luaV_toudata(L, ud, tname);
|
|
Karsten Hopp |
b81f34 |
! if (p == NULL) luaL_typeerror(L, ud, tname);
|
|
Karsten Hopp |
b81f34 |
return p;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static void
|
|
Karsten Hopp |
b81f34 |
luaV_pushtypval(lua_State *L, typval_T *tv)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! if (tv == NULL)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
! return;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
switch (tv->v_type)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
case VAR_STRING:
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 351,418 ****
|
|
Karsten Hopp |
b81f34 |
lua_pushnumber(L, (lua_Number) tv->vval.v_float);
|
|
Karsten Hopp |
b81f34 |
break;
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
! case VAR_LIST: {
|
|
Karsten Hopp |
b81f34 |
! list_T *l = tv->vval.v_list;
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! if (l != NULL)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! /* check cache */
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) l);
|
|
Karsten Hopp |
b81f34 |
! lua_rawget(L, LUA_ENVIRONINDEX);
|
|
Karsten Hopp |
b81f34 |
! if (lua_isnil(L, -1)) /* not interned? */
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! listitem_T *li;
|
|
Karsten Hopp |
b81f34 |
! int n = 0;
|
|
Karsten Hopp |
b81f34 |
! lua_pop(L, 1); /* nil */
|
|
Karsten Hopp |
b81f34 |
! lua_newtable(L);
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) l);
|
|
Karsten Hopp |
b81f34 |
! lua_pushvalue(L, -2);
|
|
Karsten Hopp |
b81f34 |
! lua_rawset(L, LUA_ENVIRONINDEX);
|
|
Karsten Hopp |
b81f34 |
! for (li = l->lv_first; li != NULL; li = li->li_next)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! luaV_pushtypval(L, &li->li_tv);
|
|
Karsten Hopp |
b81f34 |
! lua_rawseti(L, -2, ++n);
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! else lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
! break;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! case VAR_DICT: {
|
|
Karsten Hopp |
b81f34 |
! dict_T *d = tv->vval.v_dict;
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! if (d != NULL)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! /* check cache */
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) d);
|
|
Karsten Hopp |
b81f34 |
! lua_rawget(L, LUA_ENVIRONINDEX);
|
|
Karsten Hopp |
b81f34 |
! if (lua_isnil(L, -1)) /* not interned? */
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! hashtab_T *ht = &d->dv_hashtab;
|
|
Karsten Hopp |
b81f34 |
! hashitem_T *hi;
|
|
Karsten Hopp |
b81f34 |
! int n = ht->ht_used; /* remaining items */
|
|
Karsten Hopp |
b81f34 |
! lua_pop(L, 1); /* nil */
|
|
Karsten Hopp |
b81f34 |
! lua_newtable(L);
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) d);
|
|
Karsten Hopp |
b81f34 |
! lua_pushvalue(L, -2);
|
|
Karsten Hopp |
b81f34 |
! lua_rawset(L, LUA_ENVIRONINDEX);
|
|
Karsten Hopp |
b81f34 |
! for (hi = ht->ht_array; n > 0; hi++)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! if (!HASHITEM_EMPTY(hi))
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! dictitem_T *di = dict_lookup(hi);
|
|
Karsten Hopp |
b81f34 |
! luaV_pushtypval(L, &di->di_tv);
|
|
Karsten Hopp |
b81f34 |
! lua_setfield(L, -2, (char *) hi->hi_key);
|
|
Karsten Hopp |
b81f34 |
! n--;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
- else lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
break;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
default:
|
|
Karsten Hopp |
b81f34 |
! luaL_error(L, "invalid type");
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
--- 468,537 ----
|
|
Karsten Hopp |
b81f34 |
lua_pushnumber(L, (lua_Number) tv->vval.v_float);
|
|
Karsten Hopp |
b81f34 |
break;
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
! case VAR_LIST:
|
|
Karsten Hopp |
b81f34 |
! luaV_pushlist(L, tv->vval.v_list);
|
|
Karsten Hopp |
b81f34 |
! break;
|
|
Karsten Hopp |
b81f34 |
! case VAR_DICT:
|
|
Karsten Hopp |
b81f34 |
! luaV_pushdict(L, tv->vval.v_dict);
|
|
Karsten Hopp |
b81f34 |
! break;
|
|
Karsten Hopp |
b81f34 |
! default:
|
|
Karsten Hopp |
b81f34 |
! lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! /* converts lua value at 'pos' to typval 'tv' */
|
|
Karsten Hopp |
b81f34 |
! static void
|
|
Karsten Hopp |
b81f34 |
! luaV_totypval (lua_State *L, int pos, typval_T *tv)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! switch(lua_type(L, pos)) {
|
|
Karsten Hopp |
b81f34 |
! case LUA_TBOOLEAN:
|
|
Karsten Hopp |
b81f34 |
! tv->v_type = VAR_NUMBER;
|
|
Karsten Hopp |
b81f34 |
! tv->vval.v_number = (varnumber_T) lua_toboolean(L, pos);
|
|
Karsten Hopp |
b81f34 |
! break;
|
|
Karsten Hopp |
b81f34 |
! case LUA_TSTRING:
|
|
Karsten Hopp |
b81f34 |
! tv->v_type = VAR_STRING;
|
|
Karsten Hopp |
b81f34 |
! tv->vval.v_string = vim_strsave((char_u *) lua_tostring(L, pos));
|
|
Karsten Hopp |
b81f34 |
! break;
|
|
Karsten Hopp |
b81f34 |
! case LUA_TNUMBER:
|
|
Karsten Hopp |
b81f34 |
! #ifdef FEAT_FLOAT
|
|
Karsten Hopp |
b81f34 |
! tv->v_type = VAR_FLOAT;
|
|
Karsten Hopp |
b81f34 |
! tv->vval.v_float = (float_T) lua_tonumber(L, pos);
|
|
Karsten Hopp |
b81f34 |
! #else
|
|
Karsten Hopp |
b81f34 |
! tv->v_type = VAR_NUMBER;
|
|
Karsten Hopp |
b81f34 |
! tv->vval.v_number = (varnumber_T) lua_tointeger(L, pos);
|
|
Karsten Hopp |
b81f34 |
! #endif
|
|
Karsten Hopp |
b81f34 |
! break;
|
|
Karsten Hopp |
b81f34 |
! case LUA_TUSERDATA: {
|
|
Karsten Hopp |
b81f34 |
! void *p = lua_touserdata(L, pos);
|
|
Karsten Hopp |
b81f34 |
! if (lua_getmetatable(L, pos)) /* has metatable? */
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! /* check list */
|
|
Karsten Hopp |
b81f34 |
! luaV_getfield(L, LUAVIM_LIST);
|
|
Karsten Hopp |
b81f34 |
! if (lua_rawequal(L, -1, -2))
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! tv->v_type = VAR_LIST;
|
|
Karsten Hopp |
b81f34 |
! tv->vval.v_list = *((luaV_List *) p);
|
|
Karsten Hopp |
b81f34 |
! ++tv->vval.v_list->lv_refcount;
|
|
Karsten Hopp |
b81f34 |
! lua_pop(L, 2); /* MTs */
|
|
Karsten Hopp |
b81f34 |
! return;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
! /* check dict */
|
|
Karsten Hopp |
b81f34 |
! luaV_getfield(L, LUAVIM_DICT);
|
|
Karsten Hopp |
b81f34 |
! if (lua_rawequal(L, -1, -3))
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! tv->v_type = VAR_DICT;
|
|
Karsten Hopp |
b81f34 |
! tv->vval.v_dict = *((luaV_Dict *) p);
|
|
Karsten Hopp |
b81f34 |
! ++tv->vval.v_dict->dv_refcount;
|
|
Karsten Hopp |
b81f34 |
! lua_pop(L, 3); /* MTs */
|
|
Karsten Hopp |
b81f34 |
! return;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
+ lua_pop(L, 3); /* MTs */
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
break;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
default:
|
|
Karsten Hopp |
b81f34 |
! tv->v_type = VAR_NUMBER;
|
|
Karsten Hopp |
b81f34 |
! tv->vval.v_number = 0;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 481,569 ****
|
|
Karsten Hopp |
b81f34 |
lua_pop(L, 2); /* original and modified strings */
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! /* ======= Buffer type ======= */
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! static luaV_Buffer *
|
|
Karsten Hopp |
b81f34 |
! luaV_newbuffer(lua_State *L, buf_T *buf)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! luaV_Buffer *b = (luaV_Buffer *) lua_newuserdata(L, sizeof(luaV_Buffer));
|
|
Karsten Hopp |
b81f34 |
! *b = buf;
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) buf);
|
|
Karsten Hopp |
b81f34 |
! lua_pushvalue(L, -2);
|
|
Karsten Hopp |
b81f34 |
! lua_rawset(L, LUA_ENVIRONINDEX); /* env[buf] = udata */
|
|
Karsten Hopp |
b81f34 |
! /* to avoid GC, store as key in env */
|
|
Karsten Hopp |
b81f34 |
! lua_pushvalue(L, -1);
|
|
Karsten Hopp |
b81f34 |
! lua_pushboolean(L, 1);
|
|
Karsten Hopp |
b81f34 |
! lua_rawset(L, LUA_ENVIRONINDEX); /* env[udata] = true */
|
|
Karsten Hopp |
b81f34 |
! /* set metatable */
|
|
Karsten Hopp |
b81f34 |
! luaV_getfield(L, LUAVIM_BUFFER);
|
|
Karsten Hopp |
b81f34 |
lua_setmetatable(L, -2);
|
|
Karsten Hopp |
b81f34 |
! return b;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! static luaV_Buffer *
|
|
Karsten Hopp |
b81f34 |
! luaV_pushbuffer (lua_State *L, buf_T *buf)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! luaV_Buffer *b = NULL;
|
|
Karsten Hopp |
b81f34 |
! if (buf == NULL)
|
|
Karsten Hopp |
b81f34 |
! lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
! else {
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) buf);
|
|
Karsten Hopp |
b81f34 |
! lua_rawget(L, LUA_ENVIRONINDEX);
|
|
Karsten Hopp |
b81f34 |
! if (lua_isnil(L, -1)) /* not interned? */
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! lua_pop(L, 1);
|
|
Karsten Hopp |
b81f34 |
! b = luaV_newbuffer(L, buf);
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
else
|
|
Karsten Hopp |
b81f34 |
! b = (luaV_Buffer *) lua_touserdata(L, -1);
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
! return b;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! /* Buffer metamethods */
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
! luaV_buffer_tostring(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! lua_pushfstring(L, "%s: %p", LUAVIM_BUFFER, lua_touserdata(L, 1));
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_len(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! luaV_Buffer *b = lua_touserdata(L, 1);
|
|
Karsten Hopp |
b81f34 |
! lua_pushinteger(L, (*b)->b_ml.ml_line_count);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_call(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! luaV_Buffer *b = (luaV_Buffer *) lua_touserdata(L, 1);
|
|
Karsten Hopp |
b81f34 |
lua_settop(L, 1);
|
|
Karsten Hopp |
b81f34 |
! set_curbuf(*b, DOBUF_SPLIT);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_index(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! luaV_Buffer *b = (luaV_Buffer *) lua_touserdata(L, 1);
|
|
Karsten Hopp |
b81f34 |
linenr_T n = (linenr_T) lua_tointeger(L, 2);
|
|
Karsten Hopp |
b81f34 |
! if (n > 0 && n <= (*b)->b_ml.ml_line_count)
|
|
Karsten Hopp |
b81f34 |
! luaV_pushline(L, *b, n);
|
|
Karsten Hopp |
b81f34 |
else if (lua_isstring(L, 2))
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
const char *s = lua_tostring(L, 2);
|
|
Karsten Hopp |
b81f34 |
if (strncmp(s, "name", 4) == 0)
|
|
Karsten Hopp |
b81f34 |
! lua_pushstring(L, (char *) (*b)->b_sfname);
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "fname", 5) == 0)
|
|
Karsten Hopp |
b81f34 |
! lua_pushstring(L, (char *) (*b)->b_ffname);
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "number", 6) == 0)
|
|
Karsten Hopp |
b81f34 |
! lua_pushinteger(L, (*b)->b_fnum);
|
|
Karsten Hopp |
b81f34 |
/* methods */
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "insert", 6) == 0
|
|
Karsten Hopp |
b81f34 |
|| strncmp(s, "next", 4) == 0
|
|
Karsten Hopp |
b81f34 |
--- 600,1107 ----
|
|
Karsten Hopp |
b81f34 |
lua_pop(L, 2); /* original and modified strings */
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
+ #define luaV_newtype(typ,tname,luatyp,luatname) \
|
|
Karsten Hopp |
b81f34 |
+ static luatyp * \
|
|
Karsten Hopp |
b81f34 |
+ luaV_new##tname (lua_State *L, typ *obj) \
|
|
Karsten Hopp |
b81f34 |
+ { \
|
|
Karsten Hopp |
b81f34 |
+ luatyp *o = (luatyp *) lua_newuserdata(L, sizeof(luatyp)); \
|
|
Karsten Hopp |
b81f34 |
+ *o = obj; \
|
|
Karsten Hopp |
b81f34 |
+ luaV_setudata(L, obj); /* cache[obj] = udata */ \
|
|
Karsten Hopp |
b81f34 |
+ luaV_getfield(L, luatname); \
|
|
Karsten Hopp |
b81f34 |
+ lua_setmetatable(L, -2); \
|
|
Karsten Hopp |
b81f34 |
+ return o; \
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ #define luaV_pushtype(typ,tname,luatyp) \
|
|
Karsten Hopp |
b81f34 |
+ static luatyp * \
|
|
Karsten Hopp |
b81f34 |
+ luaV_push##tname (lua_State *L, typ *obj) \
|
|
Karsten Hopp |
b81f34 |
+ { \
|
|
Karsten Hopp |
b81f34 |
+ luatyp *o = NULL; \
|
|
Karsten Hopp |
b81f34 |
+ if (obj == NULL) \
|
|
Karsten Hopp |
b81f34 |
+ lua_pushnil(L); \
|
|
Karsten Hopp |
b81f34 |
+ else { \
|
|
Karsten Hopp |
b81f34 |
+ luaV_getudata(L, obj); \
|
|
Karsten Hopp |
b81f34 |
+ if (lua_isnil(L, -1)) /* not interned? */ \
|
|
Karsten Hopp |
b81f34 |
+ { \
|
|
Karsten Hopp |
b81f34 |
+ lua_pop(L, 1); \
|
|
Karsten Hopp |
b81f34 |
+ o = luaV_new##tname(L, obj); \
|
|
Karsten Hopp |
b81f34 |
+ } \
|
|
Karsten Hopp |
b81f34 |
+ else \
|
|
Karsten Hopp |
b81f34 |
+ o = (luatyp *) lua_touserdata(L, -1); \
|
|
Karsten Hopp |
b81f34 |
+ } \
|
|
Karsten Hopp |
b81f34 |
+ return o; \
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ #define luaV_type_tostring(tname,luatname) \
|
|
Karsten Hopp |
b81f34 |
+ static int \
|
|
Karsten Hopp |
b81f34 |
+ luaV_##tname##_tostring (lua_State *L) \
|
|
Karsten Hopp |
b81f34 |
+ { \
|
|
Karsten Hopp |
b81f34 |
+ lua_pushfstring(L, "%s: %p", luatname, lua_touserdata(L, 1)); \
|
|
Karsten Hopp |
b81f34 |
+ return 1; \
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! /* adapted from eval.c */
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! #define listitem_alloc() (listitem_T *)alloc(sizeof(listitem_T))
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static listitem_T *
|
|
Karsten Hopp |
b81f34 |
! list_find (list_T *l, long n)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! listitem_T *li;
|
|
Karsten Hopp |
b81f34 |
! if (l == NULL || n < -l->lv_len || n >= l->lv_len)
|
|
Karsten Hopp |
b81f34 |
! return NULL;
|
|
Karsten Hopp |
b81f34 |
! if (n < 0) /* search backward? */
|
|
Karsten Hopp |
b81f34 |
! for (li = l->lv_last; n < -1; li = li->li_prev)
|
|
Karsten Hopp |
b81f34 |
! n++;
|
|
Karsten Hopp |
b81f34 |
! else /* search forward */
|
|
Karsten Hopp |
b81f34 |
! for (li = l->lv_first; n > 0; li = li->li_next)
|
|
Karsten Hopp |
b81f34 |
! n--;
|
|
Karsten Hopp |
b81f34 |
! return li;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! static void
|
|
Karsten Hopp |
b81f34 |
! list_remove (list_T *l, listitem_T *li)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! listwatch_T *lw;
|
|
Karsten Hopp |
b81f34 |
! --l->lv_len;
|
|
Karsten Hopp |
b81f34 |
! /* fix watchers */
|
|
Karsten Hopp |
b81f34 |
! for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next)
|
|
Karsten Hopp |
b81f34 |
! if (lw->lw_item == li)
|
|
Karsten Hopp |
b81f34 |
! lw->lw_item = li->li_next;
|
|
Karsten Hopp |
b81f34 |
! /* fix list pointers */
|
|
Karsten Hopp |
b81f34 |
! if (li->li_next == NULL) /* last? */
|
|
Karsten Hopp |
b81f34 |
! l->lv_last = li->li_prev;
|
|
Karsten Hopp |
b81f34 |
! else
|
|
Karsten Hopp |
b81f34 |
! li->li_next->li_prev = li->li_prev;
|
|
Karsten Hopp |
b81f34 |
! if (li->li_prev == NULL) /* first? */
|
|
Karsten Hopp |
b81f34 |
! l->lv_first = li->li_next;
|
|
Karsten Hopp |
b81f34 |
! else
|
|
Karsten Hopp |
b81f34 |
! li->li_prev->li_next = li->li_next;
|
|
Karsten Hopp |
b81f34 |
! l->lv_idx_item = NULL;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static void
|
|
Karsten Hopp |
b81f34 |
! list_append(list_T *l, listitem_T *item)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! if (l->lv_last == NULL) /* empty list? */
|
|
Karsten Hopp |
b81f34 |
! l->lv_first = item;
|
|
Karsten Hopp |
b81f34 |
! else
|
|
Karsten Hopp |
b81f34 |
! l->lv_last->li_next = item;
|
|
Karsten Hopp |
b81f34 |
! item->li_prev = l->lv_last;
|
|
Karsten Hopp |
b81f34 |
! item->li_next = NULL;
|
|
Karsten Hopp |
b81f34 |
! l->lv_last = item;
|
|
Karsten Hopp |
b81f34 |
! ++l->lv_len;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static int
|
|
Karsten Hopp |
b81f34 |
! list_insert_tv(list_T *l, typval_T *tv, listitem_T *item)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! listitem_T *ni = listitem_alloc();
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! if (ni == NULL)
|
|
Karsten Hopp |
b81f34 |
! return FAIL;
|
|
Karsten Hopp |
b81f34 |
! copy_tv(tv, &ni->li_tv);
|
|
Karsten Hopp |
b81f34 |
! if (item == NULL)
|
|
Karsten Hopp |
b81f34 |
! list_append(l, ni);
|
|
Karsten Hopp |
b81f34 |
! else
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! ni->li_prev = item->li_prev;
|
|
Karsten Hopp |
b81f34 |
! ni->li_next = item;
|
|
Karsten Hopp |
b81f34 |
! if (item->li_prev == NULL)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! l->lv_first = ni;
|
|
Karsten Hopp |
b81f34 |
! ++l->lv_idx;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! else
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! item->li_prev->li_next = ni;
|
|
Karsten Hopp |
b81f34 |
! l->lv_idx_item = NULL;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! item->li_prev = ni;
|
|
Karsten Hopp |
b81f34 |
! ++l->lv_len;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! return OK;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! /* set references */
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static void set_ref_in_tv (typval_T *tv, int copyID);
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static void
|
|
Karsten Hopp |
b81f34 |
! set_ref_in_dict(dict_T *d, int copyID)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! hashtab_T *ht = &d->dv_hashtab;
|
|
Karsten Hopp |
b81f34 |
! int n = ht->ht_used;
|
|
Karsten Hopp |
b81f34 |
! hashitem_T *hi;
|
|
Karsten Hopp |
b81f34 |
! for (hi = ht->ht_array; n > 0; ++hi)
|
|
Karsten Hopp |
b81f34 |
! if (!HASHITEM_EMPTY(hi))
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! dictitem_T *di = dict_lookup(hi);
|
|
Karsten Hopp |
b81f34 |
! set_ref_in_tv(&di->di_tv, copyID);
|
|
Karsten Hopp |
b81f34 |
! --n;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static void
|
|
Karsten Hopp |
b81f34 |
! set_ref_in_list(list_T *l, int copyID)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! listitem_T *li;
|
|
Karsten Hopp |
b81f34 |
! for (li = l->lv_first; li != NULL; li = li->li_next)
|
|
Karsten Hopp |
b81f34 |
! set_ref_in_tv(&li->li_tv, copyID);
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static void
|
|
Karsten Hopp |
b81f34 |
! set_ref_in_tv(typval_T *tv, int copyID)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! if (tv->v_type == VAR_LIST)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! list_T *l = tv->vval.v_list;
|
|
Karsten Hopp |
b81f34 |
! if (l != NULL && l->lv_copyID != copyID)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! l->lv_copyID = copyID;
|
|
Karsten Hopp |
b81f34 |
! set_ref_in_list(l, copyID);
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! else if (tv->v_type == VAR_DICT)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! dict_T *d = tv->vval.v_dict;
|
|
Karsten Hopp |
b81f34 |
! if (d != NULL && d->dv_copyID != copyID)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! d->dv_copyID = copyID;
|
|
Karsten Hopp |
b81f34 |
! set_ref_in_dict(d, copyID);
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! /* ======= List type ======= */
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static luaV_List *
|
|
Karsten Hopp |
b81f34 |
! luaV_newlist (lua_State *L, list_T *lis)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! luaV_List *l = (luaV_List *) lua_newuserdata(L, sizeof(luaV_List));
|
|
Karsten Hopp |
b81f34 |
! *l = lis;
|
|
Karsten Hopp |
b81f34 |
! lis->lv_refcount++; /* reference in Lua */
|
|
Karsten Hopp |
b81f34 |
! luaV_setudata(L, lis); /* cache[lis] = udata */
|
|
Karsten Hopp |
b81f34 |
! luaV_getfield(L, LUAVIM_LIST);
|
|
Karsten Hopp |
b81f34 |
lua_setmetatable(L, -2);
|
|
Karsten Hopp |
b81f34 |
! return l;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! luaV_pushtype(list_T, list, luaV_List)
|
|
Karsten Hopp |
b81f34 |
! luaV_type_tostring(list, LUAVIM_LIST)
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static int
|
|
Karsten Hopp |
b81f34 |
! luaV_list_gc (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! list_unref(luaV_unbox(L, luaV_List, 1));
|
|
Karsten Hopp |
b81f34 |
! return 0;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static int
|
|
Karsten Hopp |
b81f34 |
! luaV_list_len (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! list_T *l = luaV_unbox(L, luaV_List, 1);
|
|
Karsten Hopp |
b81f34 |
! lua_pushinteger(L, (l == NULL) ? 0 : (int) l->lv_len);
|
|
Karsten Hopp |
b81f34 |
! return 1;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static int
|
|
Karsten Hopp |
b81f34 |
! luaV_list_iter (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! listitem_T *li = (listitem_T *) lua_touserdata(L, lua_upvalueindex(2));
|
|
Karsten Hopp |
b81f34 |
! if (li == NULL) return 0;
|
|
Karsten Hopp |
b81f34 |
! luaV_pushtypval(L, &li->li_tv);
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) li->li_next);
|
|
Karsten Hopp |
b81f34 |
! lua_replace(L, lua_upvalueindex(2));
|
|
Karsten Hopp |
b81f34 |
! return 1;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static int
|
|
Karsten Hopp |
b81f34 |
! luaV_list_call (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! list_T *l = luaV_unbox(L, luaV_List, 1);
|
|
Karsten Hopp |
b81f34 |
! lua_pushvalue(L, lua_upvalueindex(1)); /* pass cache table along */
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) l->lv_first);
|
|
Karsten Hopp |
b81f34 |
! lua_pushcclosure(L, luaV_list_iter, 2);
|
|
Karsten Hopp |
b81f34 |
! return 1;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static int
|
|
Karsten Hopp |
b81f34 |
! luaV_list_index (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! list_T *l = luaV_unbox(L, luaV_List, 1);
|
|
Karsten Hopp |
b81f34 |
! if (lua_isnumber(L, 2)) /* list item? */
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! listitem_T *li = list_find(l, (long) luaL_checkinteger(L, 2));
|
|
Karsten Hopp |
b81f34 |
! if (li == NULL)
|
|
Karsten Hopp |
b81f34 |
! lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
! else
|
|
Karsten Hopp |
b81f34 |
! luaV_pushtypval(L, &li->li_tv);
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! else if (lua_isstring(L, 2)) /* method? */
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! const char *s = lua_tostring(L, 2);
|
|
Karsten Hopp |
b81f34 |
! if (strncmp(s, "add", 3) == 0
|
|
Karsten Hopp |
b81f34 |
! || strncmp(s, "insert", 6) == 0
|
|
Karsten Hopp |
b81f34 |
! || strncmp(s, "extend", 6) == 0)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! lua_getmetatable(L, 1);
|
|
Karsten Hopp |
b81f34 |
! lua_getfield(L, -1, s);
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
else
|
|
Karsten Hopp |
b81f34 |
! lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
! else
|
|
Karsten Hopp |
b81f34 |
! lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
! return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! static int
|
|
Karsten Hopp |
b81f34 |
! luaV_list_newindex (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! list_T *l = luaV_unbox(L, luaV_List, 1);
|
|
Karsten Hopp |
b81f34 |
! long n = (long) luaL_checkinteger(L, 2);
|
|
Karsten Hopp |
b81f34 |
! listitem_T *li;
|
|
Karsten Hopp |
b81f34 |
! if (l->lv_lock)
|
|
Karsten Hopp |
b81f34 |
! luaL_error(L, "list is locked");
|
|
Karsten Hopp |
b81f34 |
! li = list_find(l, n);
|
|
Karsten Hopp |
b81f34 |
! if (li == NULL) return 0;
|
|
Karsten Hopp |
b81f34 |
! if (lua_isnil(L, 3)) /* remove? */
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! list_remove(l, li);
|
|
Karsten Hopp |
b81f34 |
! clear_tv(&li->li_tv);
|
|
Karsten Hopp |
b81f34 |
! vim_free(li);
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! else
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! typval_T v;
|
|
Karsten Hopp |
b81f34 |
! luaV_totypval(L, 3, &v);
|
|
Karsten Hopp |
b81f34 |
! clear_tv(&li->li_tv);
|
|
Karsten Hopp |
b81f34 |
! copy_tv(&v, &li->li_tv);
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! return 0;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
! luaV_list_add (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! luaV_List *lis = luaV_checkudata(L, 1, LUAVIM_LIST);
|
|
Karsten Hopp |
b81f34 |
! list_T *l = (list_T *) luaV_checkcache(L, (void *) *lis);
|
|
Karsten Hopp |
b81f34 |
! listitem_T *li;
|
|
Karsten Hopp |
b81f34 |
! if (l->lv_lock)
|
|
Karsten Hopp |
b81f34 |
! luaL_error(L, "list is locked");
|
|
Karsten Hopp |
b81f34 |
! li = listitem_alloc();
|
|
Karsten Hopp |
b81f34 |
! if (li != NULL)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! typval_T v;
|
|
Karsten Hopp |
b81f34 |
! lua_settop(L, 2);
|
|
Karsten Hopp |
b81f34 |
! luaV_totypval(L, 2, &v);
|
|
Karsten Hopp |
b81f34 |
! copy_tv(&v, &li->li_tv);
|
|
Karsten Hopp |
b81f34 |
! list_append(l, li);
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! lua_settop(L, 1);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
+ luaV_list_insert (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ luaV_List *lis = luaV_checkudata(L, 1, LUAVIM_LIST);
|
|
Karsten Hopp |
b81f34 |
+ list_T *l = (list_T *) luaV_checkcache(L, (void *) *lis);
|
|
Karsten Hopp |
b81f34 |
+ long pos = luaL_optlong(L, 3, 0);
|
|
Karsten Hopp |
b81f34 |
+ listitem_T *li = NULL;
|
|
Karsten Hopp |
b81f34 |
+ typval_T v;
|
|
Karsten Hopp |
b81f34 |
+ if (l->lv_lock)
|
|
Karsten Hopp |
b81f34 |
+ luaL_error(L, "list is locked");
|
|
Karsten Hopp |
b81f34 |
+ if (pos < l->lv_len)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ li = list_find(l, pos);
|
|
Karsten Hopp |
b81f34 |
+ if (li == NULL)
|
|
Karsten Hopp |
b81f34 |
+ luaL_error(L, "invalid position");
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+ lua_settop(L, 2);
|
|
Karsten Hopp |
b81f34 |
+ luaV_totypval(L, 2, &v);
|
|
Karsten Hopp |
b81f34 |
+ list_insert_tv(l, &v, li);
|
|
Karsten Hopp |
b81f34 |
+ lua_settop(L, 1);
|
|
Karsten Hopp |
b81f34 |
+ return 1;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ static const luaL_Reg luaV_List_mt[] = {
|
|
Karsten Hopp |
b81f34 |
+ {"__tostring", luaV_list_tostring},
|
|
Karsten Hopp |
b81f34 |
+ {"__gc", luaV_list_gc},
|
|
Karsten Hopp |
b81f34 |
+ {"__len", luaV_list_len},
|
|
Karsten Hopp |
b81f34 |
+ {"__call", luaV_list_call},
|
|
Karsten Hopp |
b81f34 |
+ {"__index", luaV_list_index},
|
|
Karsten Hopp |
b81f34 |
+ {"__newindex", luaV_list_newindex},
|
|
Karsten Hopp |
b81f34 |
+ {"add", luaV_list_add},
|
|
Karsten Hopp |
b81f34 |
+ {"insert", luaV_list_insert},
|
|
Karsten Hopp |
b81f34 |
+ {NULL, NULL}
|
|
Karsten Hopp |
b81f34 |
+ };
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ /* ======= Dict type ======= */
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ static luaV_Dict *
|
|
Karsten Hopp |
b81f34 |
+ luaV_newdict (lua_State *L, dict_T *dic)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ luaV_Dict *d = (luaV_Dict *) lua_newuserdata(L, sizeof(luaV_Dict));
|
|
Karsten Hopp |
b81f34 |
+ *d = dic;
|
|
Karsten Hopp |
b81f34 |
+ dic->dv_refcount++; /* reference in Lua */
|
|
Karsten Hopp |
b81f34 |
+ luaV_setudata(L, dic); /* cache[dic] = udata */
|
|
Karsten Hopp |
b81f34 |
+ luaV_getfield(L, LUAVIM_DICT);
|
|
Karsten Hopp |
b81f34 |
+ lua_setmetatable(L, -2);
|
|
Karsten Hopp |
b81f34 |
+ return d;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ luaV_pushtype(dict_T, dict, luaV_Dict)
|
|
Karsten Hopp |
b81f34 |
+ luaV_type_tostring(dict, LUAVIM_DICT)
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ static int
|
|
Karsten Hopp |
b81f34 |
+ luaV_dict_gc (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ dict_unref(luaV_unbox(L, luaV_Dict, 1));
|
|
Karsten Hopp |
b81f34 |
+ return 0;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ static int
|
|
Karsten Hopp |
b81f34 |
+ luaV_dict_len (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ dict_T *d = luaV_unbox(L, luaV_Dict, 1);
|
|
Karsten Hopp |
b81f34 |
+ lua_pushinteger(L, (d == NULL) ? 0 : (int) d->dv_hashtab.ht_used);
|
|
Karsten Hopp |
b81f34 |
+ return 1;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ static int
|
|
Karsten Hopp |
b81f34 |
+ luaV_dict_iter (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ hashitem_T *hi = (hashitem_T *) lua_touserdata(L, lua_upvalueindex(2));
|
|
Karsten Hopp |
b81f34 |
+ int n = lua_tointeger(L, lua_upvalueindex(3));
|
|
Karsten Hopp |
b81f34 |
+ dictitem_T *di;
|
|
Karsten Hopp |
b81f34 |
+ if (n <= 0) return 0;
|
|
Karsten Hopp |
b81f34 |
+ while (HASHITEM_EMPTY(hi)) hi++;
|
|
Karsten Hopp |
b81f34 |
+ di = dict_lookup(hi);
|
|
Karsten Hopp |
b81f34 |
+ lua_pushstring(L, (char *) hi->hi_key);
|
|
Karsten Hopp |
b81f34 |
+ luaV_pushtypval(L, &di->di_tv);
|
|
Karsten Hopp |
b81f34 |
+ lua_pushlightuserdata(L, (void *) (hi + 1));
|
|
Karsten Hopp |
b81f34 |
+ lua_replace(L, lua_upvalueindex(2));
|
|
Karsten Hopp |
b81f34 |
+ lua_pushinteger(L, n - 1);
|
|
Karsten Hopp |
b81f34 |
+ lua_replace(L, lua_upvalueindex(3));
|
|
Karsten Hopp |
b81f34 |
+ return 2;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ static int
|
|
Karsten Hopp |
b81f34 |
+ luaV_dict_call (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ dict_T *d = luaV_unbox(L, luaV_Dict, 1);
|
|
Karsten Hopp |
b81f34 |
+ hashtab_T *ht = &d->dv_hashtab;
|
|
Karsten Hopp |
b81f34 |
+ lua_pushvalue(L, lua_upvalueindex(1)); /* pass cache table along */
|
|
Karsten Hopp |
b81f34 |
+ lua_pushlightuserdata(L, (void *) ht->ht_array);
|
|
Karsten Hopp |
b81f34 |
+ lua_pushinteger(L, ht->ht_used); /* # remaining items */
|
|
Karsten Hopp |
b81f34 |
+ lua_pushcclosure(L, luaV_dict_iter, 3);
|
|
Karsten Hopp |
b81f34 |
+ return 1;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ static int
|
|
Karsten Hopp |
b81f34 |
+ luaV_dict_index (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ dict_T *d = luaV_unbox(L, luaV_Dict, 1);
|
|
Karsten Hopp |
b81f34 |
+ char_u *key = (char_u *) luaL_checkstring(L, 2);
|
|
Karsten Hopp |
b81f34 |
+ dictitem_T *di = dict_find(d, key, -1);
|
|
Karsten Hopp |
b81f34 |
+ if (di == NULL)
|
|
Karsten Hopp |
b81f34 |
+ lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
+ else
|
|
Karsten Hopp |
b81f34 |
+ luaV_pushtypval(L, &di->di_tv);
|
|
Karsten Hopp |
b81f34 |
+ return 1;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ static int
|
|
Karsten Hopp |
b81f34 |
+ luaV_dict_newindex (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ dict_T *d = luaV_unbox(L, luaV_Dict, 1);
|
|
Karsten Hopp |
b81f34 |
+ char_u *key = (char_u *) luaL_checkstring(L, 2);
|
|
Karsten Hopp |
b81f34 |
+ dictitem_T *di;
|
|
Karsten Hopp |
b81f34 |
+ if (d->dv_lock)
|
|
Karsten Hopp |
b81f34 |
+ luaL_error(L, "dict is locked");
|
|
Karsten Hopp |
b81f34 |
+ di = dict_find(d, key, -1);
|
|
Karsten Hopp |
b81f34 |
+ if (di == NULL) /* non-existing key? */
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ if (lua_isnil(L, 3)) return 0;
|
|
Karsten Hopp |
b81f34 |
+ di = dictitem_alloc(key);
|
|
Karsten Hopp |
b81f34 |
+ if (di == NULL) return 0;
|
|
Karsten Hopp |
b81f34 |
+ if (dict_add(d, di) == FAIL)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ vim_free(di);
|
|
Karsten Hopp |
b81f34 |
+ return 0;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+ else
|
|
Karsten Hopp |
b81f34 |
+ clear_tv(&di->di_tv);
|
|
Karsten Hopp |
b81f34 |
+ if (lua_isnil(L, 3)) /* remove? */
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ hashitem_T *hi = hash_find(&d->dv_hashtab, di->di_key);
|
|
Karsten Hopp |
b81f34 |
+ hash_remove(&d->dv_hashtab, hi);
|
|
Karsten Hopp |
b81f34 |
+ dictitem_free(di);
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+ else {
|
|
Karsten Hopp |
b81f34 |
+ typval_T v;
|
|
Karsten Hopp |
b81f34 |
+ luaV_totypval(L, 3, &v);
|
|
Karsten Hopp |
b81f34 |
+ copy_tv(&v, &di->di_tv);
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+ return 0;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ static const luaL_Reg luaV_Dict_mt[] = {
|
|
Karsten Hopp |
b81f34 |
+ {"__tostring", luaV_dict_tostring},
|
|
Karsten Hopp |
b81f34 |
+ {"__gc", luaV_dict_gc},
|
|
Karsten Hopp |
b81f34 |
+ {"__len", luaV_dict_len},
|
|
Karsten Hopp |
b81f34 |
+ {"__call", luaV_dict_call},
|
|
Karsten Hopp |
b81f34 |
+ {"__index", luaV_dict_index},
|
|
Karsten Hopp |
b81f34 |
+ {"__newindex", luaV_dict_newindex},
|
|
Karsten Hopp |
b81f34 |
+ {NULL, NULL}
|
|
Karsten Hopp |
b81f34 |
+ };
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ /* ======= Buffer type ======= */
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ luaV_newtype(buf_T, buffer, luaV_Buffer, LUAVIM_BUFFER)
|
|
Karsten Hopp |
b81f34 |
+ luaV_pushtype(buf_T, buffer, luaV_Buffer)
|
|
Karsten Hopp |
b81f34 |
+ luaV_type_tostring(buffer, LUAVIM_BUFFER)
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ static int
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_len(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! buf_T *b = (buf_T *) luaV_checkvalid(L, luaV_Buffer, 1);
|
|
Karsten Hopp |
b81f34 |
! lua_pushinteger(L, b->b_ml.ml_line_count);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_call(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! buf_T *b = (buf_T *) luaV_checkvalid(L, luaV_Buffer, 1);
|
|
Karsten Hopp |
b81f34 |
lua_settop(L, 1);
|
|
Karsten Hopp |
b81f34 |
! set_curbuf(b, DOBUF_SPLIT);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_index(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! buf_T *b = (buf_T *) luaV_checkvalid(L, luaV_Buffer, 1);
|
|
Karsten Hopp |
b81f34 |
linenr_T n = (linenr_T) lua_tointeger(L, 2);
|
|
Karsten Hopp |
b81f34 |
! if (n > 0 && n <= b->b_ml.ml_line_count)
|
|
Karsten Hopp |
b81f34 |
! luaV_pushline(L, b, n);
|
|
Karsten Hopp |
b81f34 |
else if (lua_isstring(L, 2))
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
const char *s = lua_tostring(L, 2);
|
|
Karsten Hopp |
b81f34 |
if (strncmp(s, "name", 4) == 0)
|
|
Karsten Hopp |
b81f34 |
! lua_pushstring(L, (char *) b->b_sfname);
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "fname", 5) == 0)
|
|
Karsten Hopp |
b81f34 |
! lua_pushstring(L, (char *) b->b_ffname);
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "number", 6) == 0)
|
|
Karsten Hopp |
b81f34 |
! lua_pushinteger(L, b->b_fnum);
|
|
Karsten Hopp |
b81f34 |
/* methods */
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "insert", 6) == 0
|
|
Karsten Hopp |
b81f34 |
|| strncmp(s, "next", 4) == 0
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 584,600 ****
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_newindex(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! luaV_Buffer *b = (luaV_Buffer *) lua_touserdata(L, 1);
|
|
Karsten Hopp |
b81f34 |
linenr_T n = (linenr_T) luaL_checkinteger(L, 2);
|
|
Karsten Hopp |
b81f34 |
#ifdef HAVE_SANDBOX
|
|
Karsten Hopp |
b81f34 |
luaV_checksandbox(L);
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
! if (n < 1 || n > (*b)->b_ml.ml_line_count)
|
|
Karsten Hopp |
b81f34 |
luaL_error(L, "invalid line number");
|
|
Karsten Hopp |
b81f34 |
if (lua_isnil(L, 3)) /* delete line */
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
buf_T *buf = curbuf;
|
|
Karsten Hopp |
b81f34 |
! curbuf = *b;
|
|
Karsten Hopp |
b81f34 |
if (u_savedel(n, 1L) == FAIL)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
curbuf = buf;
|
|
Karsten Hopp |
b81f34 |
--- 1122,1138 ----
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_newindex(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! buf_T *b = (buf_T *) luaV_checkvalid(L, luaV_Buffer, 1);
|
|
Karsten Hopp |
b81f34 |
linenr_T n = (linenr_T) luaL_checkinteger(L, 2);
|
|
Karsten Hopp |
b81f34 |
#ifdef HAVE_SANDBOX
|
|
Karsten Hopp |
b81f34 |
luaV_checksandbox(L);
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
! if (n < 1 || n > b->b_ml.ml_line_count)
|
|
Karsten Hopp |
b81f34 |
luaL_error(L, "invalid line number");
|
|
Karsten Hopp |
b81f34 |
if (lua_isnil(L, 3)) /* delete line */
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
buf_T *buf = curbuf;
|
|
Karsten Hopp |
b81f34 |
! curbuf = b;
|
|
Karsten Hopp |
b81f34 |
if (u_savedel(n, 1L) == FAIL)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
curbuf = buf;
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 607,613 ****
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
else {
|
|
Karsten Hopp |
b81f34 |
deleted_lines_mark(n, 1L);
|
|
Karsten Hopp |
b81f34 |
! if (*b == curwin->w_buffer) /* fix cursor in current window? */
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
if (curwin->w_cursor.lnum >= n)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
--- 1145,1151 ----
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
else {
|
|
Karsten Hopp |
b81f34 |
deleted_lines_mark(n, 1L);
|
|
Karsten Hopp |
b81f34 |
! if (b == curwin->w_buffer) /* fix cursor in current window? */
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
if (curwin->w_cursor.lnum >= n)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 627,633 ****
|
|
Karsten Hopp |
b81f34 |
else if (lua_isstring(L, 3)) /* update line */
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
buf_T *buf = curbuf;
|
|
Karsten Hopp |
b81f34 |
! curbuf = *b;
|
|
Karsten Hopp |
b81f34 |
if (u_savesub(n) == FAIL)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
curbuf = buf;
|
|
Karsten Hopp |
b81f34 |
--- 1165,1171 ----
|
|
Karsten Hopp |
b81f34 |
else if (lua_isstring(L, 3)) /* update line */
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
buf_T *buf = curbuf;
|
|
Karsten Hopp |
b81f34 |
! curbuf = b;
|
|
Karsten Hopp |
b81f34 |
if (u_savesub(n) == FAIL)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
curbuf = buf;
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 640,646 ****
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
else changed_bytes(n, 0);
|
|
Karsten Hopp |
b81f34 |
curbuf = buf;
|
|
Karsten Hopp |
b81f34 |
! if (*b == curwin->w_buffer)
|
|
Karsten Hopp |
b81f34 |
check_cursor_col();
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
else
|
|
Karsten Hopp |
b81f34 |
--- 1178,1184 ----
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
else changed_bytes(n, 0);
|
|
Karsten Hopp |
b81f34 |
curbuf = buf;
|
|
Karsten Hopp |
b81f34 |
! if (b == curwin->w_buffer)
|
|
Karsten Hopp |
b81f34 |
check_cursor_col();
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
else
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 651,658 ****
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_insert(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER);
|
|
Karsten Hopp |
b81f34 |
! linenr_T last = (*b)->b_ml.ml_line_count;
|
|
Karsten Hopp |
b81f34 |
linenr_T n = (linenr_T) luaL_optinteger(L, 3, last);
|
|
Karsten Hopp |
b81f34 |
buf_T *buf;
|
|
Karsten Hopp |
b81f34 |
luaL_checktype(L, 2, LUA_TSTRING);
|
|
Karsten Hopp |
b81f34 |
--- 1189,1197 ----
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_insert(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! luaV_Buffer *lb = luaV_checkudata(L, 1, LUAVIM_BUFFER);
|
|
Karsten Hopp |
b81f34 |
! buf_T *b = (buf_T *) luaV_checkcache(L, (void *) *lb);
|
|
Karsten Hopp |
b81f34 |
! linenr_T last = b->b_ml.ml_line_count;
|
|
Karsten Hopp |
b81f34 |
linenr_T n = (linenr_T) luaL_optinteger(L, 3, last);
|
|
Karsten Hopp |
b81f34 |
buf_T *buf;
|
|
Karsten Hopp |
b81f34 |
luaL_checktype(L, 2, LUA_TSTRING);
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 664,670 ****
|
|
Karsten Hopp |
b81f34 |
if (n > last) n = last;
|
|
Karsten Hopp |
b81f34 |
/* insert */
|
|
Karsten Hopp |
b81f34 |
buf = curbuf;
|
|
Karsten Hopp |
b81f34 |
! curbuf = *b;
|
|
Karsten Hopp |
b81f34 |
if (u_save(n, n + 1) == FAIL)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
curbuf = buf;
|
|
Karsten Hopp |
b81f34 |
--- 1203,1209 ----
|
|
Karsten Hopp |
b81f34 |
if (n > last) n = last;
|
|
Karsten Hopp |
b81f34 |
/* insert */
|
|
Karsten Hopp |
b81f34 |
buf = curbuf;
|
|
Karsten Hopp |
b81f34 |
! curbuf = b;
|
|
Karsten Hopp |
b81f34 |
if (u_save(n, n + 1) == FAIL)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
curbuf = buf;
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 686,692 ****
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_next(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER);
|
|
Karsten Hopp |
b81f34 |
! luaV_pushbuffer(L, (*b)->b_next);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
--- 1225,1232 ----
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_next(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER);
|
|
Karsten Hopp |
b81f34 |
! buf_T *buf = (buf_T *) luaV_checkcache(L, (void *) *b);
|
|
Karsten Hopp |
b81f34 |
! luaV_pushbuffer(L, buf->b_next);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 694,700 ****
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_previous(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER);
|
|
Karsten Hopp |
b81f34 |
! luaV_pushbuffer(L, (*b)->b_prev);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
--- 1234,1241 ----
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_previous(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER);
|
|
Karsten Hopp |
b81f34 |
! buf_T *buf = (buf_T *) luaV_checkcache(L, (void *) *b);
|
|
Karsten Hopp |
b81f34 |
! luaV_pushbuffer(L, buf->b_prev);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 702,709 ****
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_isvalid(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER);
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) (*b));
|
|
Karsten Hopp |
b81f34 |
! lua_rawget(L, LUA_ENVIRONINDEX);
|
|
Karsten Hopp |
b81f34 |
lua_pushboolean(L, !lua_isnil(L, -1));
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
--- 1243,1249 ----
|
|
Karsten Hopp |
b81f34 |
luaV_buffer_isvalid(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER);
|
|
Karsten Hopp |
b81f34 |
! luaV_getudata(L, *b);
|
|
Karsten Hopp |
b81f34 |
lua_pushboolean(L, !lua_isnil(L, -1));
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 724,801 ****
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
/* ======= Window type ======= */
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! static luaV_Window *
|
|
Karsten Hopp |
b81f34 |
! luaV_newwindow(lua_State *L, win_T *win)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! luaV_Window *w = (luaV_Window *) lua_newuserdata(L, sizeof(luaV_Window));
|
|
Karsten Hopp |
b81f34 |
! *w = win;
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) win);
|
|
Karsten Hopp |
b81f34 |
! lua_pushvalue(L, -2);
|
|
Karsten Hopp |
b81f34 |
! lua_rawset(L, LUA_ENVIRONINDEX); /* env[win] = udata */
|
|
Karsten Hopp |
b81f34 |
! /* to avoid GC, store as key in env */
|
|
Karsten Hopp |
b81f34 |
! lua_pushvalue(L, -1);
|
|
Karsten Hopp |
b81f34 |
! lua_pushboolean(L, 1);
|
|
Karsten Hopp |
b81f34 |
! lua_rawset(L, LUA_ENVIRONINDEX); /* env[udata] = true */
|
|
Karsten Hopp |
b81f34 |
! /* set metatable */
|
|
Karsten Hopp |
b81f34 |
! luaV_getfield(L, LUAVIM_WINDOW);
|
|
Karsten Hopp |
b81f34 |
! lua_setmetatable(L, -2);
|
|
Karsten Hopp |
b81f34 |
! return w;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static luaV_Window *
|
|
Karsten Hopp |
b81f34 |
! luaV_pushwindow(lua_State *L, win_T *win)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! luaV_Window *w = NULL;
|
|
Karsten Hopp |
b81f34 |
! if (win == NULL)
|
|
Karsten Hopp |
b81f34 |
! lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
! else {
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) win);
|
|
Karsten Hopp |
b81f34 |
! lua_rawget(L, LUA_ENVIRONINDEX);
|
|
Karsten Hopp |
b81f34 |
! if (lua_isnil(L, -1)) /* not interned? */
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! lua_pop(L, 1);
|
|
Karsten Hopp |
b81f34 |
! w = luaV_newwindow(L, win);
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! else w = (luaV_Window *) lua_touserdata(L, -1);
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! return w;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! /* Window metamethods */
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static int
|
|
Karsten Hopp |
b81f34 |
! luaV_window_tostring(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! lua_pushfstring(L, "%s: %p", LUAVIM_WINDOW, lua_touserdata(L, 1));
|
|
Karsten Hopp |
b81f34 |
! return 1;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaV_window_call(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! luaV_Window *w = (luaV_Window *) lua_touserdata(L, 1);
|
|
Karsten Hopp |
b81f34 |
lua_settop(L, 1);
|
|
Karsten Hopp |
b81f34 |
! win_goto(*w);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaV_window_index(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! luaV_Window *w = (luaV_Window *) lua_touserdata(L, 1);
|
|
Karsten Hopp |
b81f34 |
const char *s = luaL_checkstring(L, 2);
|
|
Karsten Hopp |
b81f34 |
if (strncmp(s, "buffer", 6) == 0)
|
|
Karsten Hopp |
b81f34 |
! luaV_pushbuffer(L, (*w)->w_buffer);
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "line", 4) == 0)
|
|
Karsten Hopp |
b81f34 |
! lua_pushinteger(L, (*w)->w_cursor.lnum);
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "col", 3) == 0)
|
|
Karsten Hopp |
b81f34 |
! lua_pushinteger(L, (*w)->w_cursor.col + 1);
|
|
Karsten Hopp |
b81f34 |
#ifdef FEAT_VERTSPLIT
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "width", 5) == 0)
|
|
Karsten Hopp |
b81f34 |
! lua_pushinteger(L, W_WIDTH((*w)));
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "height", 6) == 0)
|
|
Karsten Hopp |
b81f34 |
! lua_pushinteger(L, (*w)->w_height);
|
|
Karsten Hopp |
b81f34 |
/* methods */
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "next", 4) == 0
|
|
Karsten Hopp |
b81f34 |
|| strncmp(s, "previous", 8) == 0
|
|
Karsten Hopp |
b81f34 |
--- 1264,1299 ----
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
/* ======= Window type ======= */
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! luaV_newtype(win_T, window, luaV_Window, LUAVIM_WINDOW)
|
|
Karsten Hopp |
b81f34 |
! luaV_pushtype(win_T, window, luaV_Window)
|
|
Karsten Hopp |
b81f34 |
! luaV_type_tostring(window, LUAVIM_WINDOW)
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaV_window_call(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! win_T *w = (win_T *) luaV_checkvalid(L, luaV_Window, 1);
|
|
Karsten Hopp |
b81f34 |
lua_settop(L, 1);
|
|
Karsten Hopp |
b81f34 |
! win_goto(w);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaV_window_index(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! win_T *w = (win_T *) luaV_checkvalid(L, luaV_Window, 1);
|
|
Karsten Hopp |
b81f34 |
const char *s = luaL_checkstring(L, 2);
|
|
Karsten Hopp |
b81f34 |
if (strncmp(s, "buffer", 6) == 0)
|
|
Karsten Hopp |
b81f34 |
! luaV_pushbuffer(L, w->w_buffer);
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "line", 4) == 0)
|
|
Karsten Hopp |
b81f34 |
! lua_pushinteger(L, w->w_cursor.lnum);
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "col", 3) == 0)
|
|
Karsten Hopp |
b81f34 |
! lua_pushinteger(L, w->w_cursor.col + 1);
|
|
Karsten Hopp |
b81f34 |
#ifdef FEAT_VERTSPLIT
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "width", 5) == 0)
|
|
Karsten Hopp |
b81f34 |
! lua_pushinteger(L, W_WIDTH(w));
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "height", 6) == 0)
|
|
Karsten Hopp |
b81f34 |
! lua_pushinteger(L, w->w_height);
|
|
Karsten Hopp |
b81f34 |
/* methods */
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "next", 4) == 0
|
|
Karsten Hopp |
b81f34 |
|| strncmp(s, "previous", 8) == 0
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 812,818 ****
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaV_window_newindex (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! luaV_Window *w = (luaV_Window *) lua_touserdata(L, 1);
|
|
Karsten Hopp |
b81f34 |
const char *s = luaL_checkstring(L, 2);
|
|
Karsten Hopp |
b81f34 |
int v = luaL_checkinteger(L, 3);
|
|
Karsten Hopp |
b81f34 |
if (strncmp(s, "line", 4) == 0)
|
|
Karsten Hopp |
b81f34 |
--- 1310,1316 ----
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaV_window_newindex (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! win_T *w = (win_T *) luaV_checkvalid(L, luaV_Window, 1);
|
|
Karsten Hopp |
b81f34 |
const char *s = luaL_checkstring(L, 2);
|
|
Karsten Hopp |
b81f34 |
int v = luaL_checkinteger(L, 3);
|
|
Karsten Hopp |
b81f34 |
if (strncmp(s, "line", 4) == 0)
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 820,828 ****
|
|
Karsten Hopp |
b81f34 |
#ifdef HAVE_SANDBOX
|
|
Karsten Hopp |
b81f34 |
luaV_checksandbox(L);
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
! if (v < 1 || v > (*w)->w_buffer->b_ml.ml_line_count)
|
|
Karsten Hopp |
b81f34 |
luaL_error(L, "line out of range");
|
|
Karsten Hopp |
b81f34 |
! (*w)->w_cursor.lnum = v;
|
|
Karsten Hopp |
b81f34 |
update_screen(VALID);
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "col", 3) == 0)
|
|
Karsten Hopp |
b81f34 |
--- 1318,1326 ----
|
|
Karsten Hopp |
b81f34 |
#ifdef HAVE_SANDBOX
|
|
Karsten Hopp |
b81f34 |
luaV_checksandbox(L);
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
! if (v < 1 || v > w->w_buffer->b_ml.ml_line_count)
|
|
Karsten Hopp |
b81f34 |
luaL_error(L, "line out of range");
|
|
Karsten Hopp |
b81f34 |
! w->w_cursor.lnum = v;
|
|
Karsten Hopp |
b81f34 |
update_screen(VALID);
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
else if (strncmp(s, "col", 3) == 0)
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 830,836 ****
|
|
Karsten Hopp |
b81f34 |
#ifdef HAVE_SANDBOX
|
|
Karsten Hopp |
b81f34 |
luaV_checksandbox(L);
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
! (*w)->w_cursor.col = v - 1;
|
|
Karsten Hopp |
b81f34 |
update_screen(VALID);
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
#ifdef FEAT_VERTSPLIT
|
|
Karsten Hopp |
b81f34 |
--- 1328,1334 ----
|
|
Karsten Hopp |
b81f34 |
#ifdef HAVE_SANDBOX
|
|
Karsten Hopp |
b81f34 |
luaV_checksandbox(L);
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
! w->w_cursor.col = v - 1;
|
|
Karsten Hopp |
b81f34 |
update_screen(VALID);
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
#ifdef FEAT_VERTSPLIT
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 840,846 ****
|
|
Karsten Hopp |
b81f34 |
#ifdef FEAT_GUI
|
|
Karsten Hopp |
b81f34 |
need_mouse_correct = TRUE;
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
! curwin = *w;
|
|
Karsten Hopp |
b81f34 |
win_setwidth(v);
|
|
Karsten Hopp |
b81f34 |
curwin = win;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
--- 1338,1344 ----
|
|
Karsten Hopp |
b81f34 |
#ifdef FEAT_GUI
|
|
Karsten Hopp |
b81f34 |
need_mouse_correct = TRUE;
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
! curwin = w;
|
|
Karsten Hopp |
b81f34 |
win_setwidth(v);
|
|
Karsten Hopp |
b81f34 |
curwin = win;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 851,857 ****
|
|
Karsten Hopp |
b81f34 |
#ifdef FEAT_GUI
|
|
Karsten Hopp |
b81f34 |
need_mouse_correct = TRUE;
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
! curwin = *w;
|
|
Karsten Hopp |
b81f34 |
win_setheight(v);
|
|
Karsten Hopp |
b81f34 |
curwin = win;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
--- 1349,1355 ----
|
|
Karsten Hopp |
b81f34 |
#ifdef FEAT_GUI
|
|
Karsten Hopp |
b81f34 |
need_mouse_correct = TRUE;
|
|
Karsten Hopp |
b81f34 |
#endif
|
|
Karsten Hopp |
b81f34 |
! curwin = w;
|
|
Karsten Hopp |
b81f34 |
win_setheight(v);
|
|
Karsten Hopp |
b81f34 |
curwin = win;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 864,870 ****
|
|
Karsten Hopp |
b81f34 |
luaV_window_next(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW);
|
|
Karsten Hopp |
b81f34 |
! luaV_pushwindow(L, (*w)->w_next);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
--- 1362,1369 ----
|
|
Karsten Hopp |
b81f34 |
luaV_window_next(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW);
|
|
Karsten Hopp |
b81f34 |
! win_T *win = (win_T *) luaV_checkcache(L, (void *) *w);
|
|
Karsten Hopp |
b81f34 |
! luaV_pushwindow(L, win->w_next);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 872,878 ****
|
|
Karsten Hopp |
b81f34 |
luaV_window_previous(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW);
|
|
Karsten Hopp |
b81f34 |
! luaV_pushwindow(L, (*w)->w_prev);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
--- 1371,1378 ----
|
|
Karsten Hopp |
b81f34 |
luaV_window_previous(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW);
|
|
Karsten Hopp |
b81f34 |
! win_T *win = (win_T *) luaV_checkcache(L, (void *) *w);
|
|
Karsten Hopp |
b81f34 |
! luaV_pushwindow(L, win->w_prev);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 880,887 ****
|
|
Karsten Hopp |
b81f34 |
luaV_window_isvalid(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW);
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) (*w));
|
|
Karsten Hopp |
b81f34 |
! lua_rawget(L, LUA_ENVIRONINDEX);
|
|
Karsten Hopp |
b81f34 |
lua_pushboolean(L, !lua_isnil(L, -1));
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
--- 1380,1386 ----
|
|
Karsten Hopp |
b81f34 |
luaV_window_isvalid(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW);
|
|
Karsten Hopp |
b81f34 |
! luaV_getudata(L, *w);
|
|
Karsten Hopp |
b81f34 |
lua_pushboolean(L, !lua_isnil(L, -1));
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 983,988 ****
|
|
Karsten Hopp |
b81f34 |
--- 1482,1509 ----
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
+ luaV_list(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ list_T *l = list_alloc();
|
|
Karsten Hopp |
b81f34 |
+ if (l == NULL)
|
|
Karsten Hopp |
b81f34 |
+ lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
+ else
|
|
Karsten Hopp |
b81f34 |
+ luaV_newlist(L, l);
|
|
Karsten Hopp |
b81f34 |
+ return 1;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ static int
|
|
Karsten Hopp |
b81f34 |
+ luaV_dict(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ dict_T *d = dict_alloc();
|
|
Karsten Hopp |
b81f34 |
+ if (d == NULL)
|
|
Karsten Hopp |
b81f34 |
+ lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
+ else
|
|
Karsten Hopp |
b81f34 |
+ luaV_newdict(L, d);
|
|
Karsten Hopp |
b81f34 |
+ return 1;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ static int
|
|
Karsten Hopp |
b81f34 |
luaV_buffer(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
buf_T *buf;
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 1008,1022 ****
|
|
Karsten Hopp |
b81f34 |
break;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
- if (buf == NULL) /* not found? */
|
|
Karsten Hopp |
b81f34 |
- lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
- else
|
|
Karsten Hopp |
b81f34 |
- luaV_pushbuffer(L, buf);
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
! else {
|
|
Karsten Hopp |
b81f34 |
buf = (lua_toboolean(L, 1)) ? firstbuf : curbuf; /* first buffer? */
|
|
Karsten Hopp |
b81f34 |
! luaV_pushbuffer(L, buf);
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
--- 1529,1538 ----
|
|
Karsten Hopp |
b81f34 |
break;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
! else
|
|
Karsten Hopp |
b81f34 |
buf = (lua_toboolean(L, 1)) ? firstbuf : curbuf; /* first buffer? */
|
|
Karsten Hopp |
b81f34 |
! luaV_pushbuffer(L, buf);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 1029,1043 ****
|
|
Karsten Hopp |
b81f34 |
int n = lua_tointeger(L, 1);
|
|
Karsten Hopp |
b81f34 |
for (win = firstwin; win != NULL; win = win->w_next, n--)
|
|
Karsten Hopp |
b81f34 |
if (n == 1) break;
|
|
Karsten Hopp |
b81f34 |
- if (win == NULL) /* not found? */
|
|
Karsten Hopp |
b81f34 |
- lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
- else
|
|
Karsten Hopp |
b81f34 |
- luaV_pushwindow(L, win);
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
! else {
|
|
Karsten Hopp |
b81f34 |
win = (lua_toboolean(L, 1)) ? firstwin : curwin; /* first window? */
|
|
Karsten Hopp |
b81f34 |
! luaV_pushwindow(L, win);
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
--- 1545,1554 ----
|
|
Karsten Hopp |
b81f34 |
int n = lua_tointeger(L, 1);
|
|
Karsten Hopp |
b81f34 |
for (win = firstwin; win != NULL; win = win->w_next, n--)
|
|
Karsten Hopp |
b81f34 |
if (n == 1) break;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
! else
|
|
Karsten Hopp |
b81f34 |
win = (lua_toboolean(L, 1)) ? firstwin : curwin; /* first window? */
|
|
Karsten Hopp |
b81f34 |
! luaV_pushwindow(L, win);
|
|
Karsten Hopp |
b81f34 |
return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 1054,1086 ****
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
! luaV_isbuffer(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! lua_pushboolean(L, luaV_toudata(L, 1, LUAVIM_BUFFER) != NULL);
|
|
Karsten Hopp |
b81f34 |
! return 1;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! static int
|
|
Karsten Hopp |
b81f34 |
! luaV_iswindow(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! lua_pushboolean(L, luaV_toudata(L, 1, LUAVIM_WINDOW) != NULL);
|
|
Karsten Hopp |
b81f34 |
! return 1;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! /* for freeing buffer and window objects; lightuserdata as arg */
|
|
Karsten Hopp |
b81f34 |
! static int
|
|
Karsten Hopp |
b81f34 |
! luaV_free(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! lua_pushvalue(L, 1); /* lightudata */
|
|
Karsten Hopp |
b81f34 |
! lua_rawget(L, LUA_ENVIRONINDEX);
|
|
Karsten Hopp |
b81f34 |
! if (!lua_isnil(L, -1))
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
! lua_rawset(L, LUA_ENVIRONINDEX); /* env[udata] = nil */
|
|
Karsten Hopp |
b81f34 |
! lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
! lua_rawset(L, LUA_ENVIRONINDEX); /* env[lightudata] = nil */
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
! return 0;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static const luaL_Reg luaV_module[] = {
|
|
Karsten Hopp |
b81f34 |
--- 1565,1606 ----
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
! luaV_type(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! luaL_checkany(L, 1);
|
|
Karsten Hopp |
b81f34 |
! if (lua_type(L, 1) == LUA_TUSERDATA) /* check vim udata? */
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! lua_settop(L, 1);
|
|
Karsten Hopp |
b81f34 |
! if (lua_getmetatable(L, 1))
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! luaV_getfield(L, LUAVIM_LIST);
|
|
Karsten Hopp |
b81f34 |
! if (lua_rawequal(L, -1, 2))
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! lua_pushstring(L, "list");
|
|
Karsten Hopp |
b81f34 |
! return 1;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! luaV_getfield(L, LUAVIM_DICT);
|
|
Karsten Hopp |
b81f34 |
! if (lua_rawequal(L, -1, 2))
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! lua_pushstring(L, "dict");
|
|
Karsten Hopp |
b81f34 |
! return 1;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! luaV_getfield(L, LUAVIM_BUFFER);
|
|
Karsten Hopp |
b81f34 |
! if (lua_rawequal(L, -1, 2))
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! lua_pushstring(L, "buffer");
|
|
Karsten Hopp |
b81f34 |
! return 1;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! luaV_getfield(L, LUAVIM_WINDOW);
|
|
Karsten Hopp |
b81f34 |
! if (lua_rawequal(L, -1, 2))
|
|
Karsten Hopp |
b81f34 |
! {
|
|
Karsten Hopp |
b81f34 |
! lua_pushstring(L, "window");
|
|
Karsten Hopp |
b81f34 |
! return 1;
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
! lua_pushstring(L, luaL_typename(L, 1)); /* fallback */
|
|
Karsten Hopp |
b81f34 |
! return 1;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static const luaL_Reg luaV_module[] = {
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 1088,1111 ****
|
|
Karsten Hopp |
b81f34 |
{"eval", luaV_eval},
|
|
Karsten Hopp |
b81f34 |
{"beep", luaV_beep},
|
|
Karsten Hopp |
b81f34 |
{"line", luaV_line},
|
|
Karsten Hopp |
b81f34 |
{"buffer", luaV_buffer},
|
|
Karsten Hopp |
b81f34 |
{"window", luaV_window},
|
|
Karsten Hopp |
b81f34 |
{"open", luaV_open},
|
|
Karsten Hopp |
b81f34 |
! {"isbuffer", luaV_isbuffer},
|
|
Karsten Hopp |
b81f34 |
! {"iswindow", luaV_iswindow},
|
|
Karsten Hopp |
b81f34 |
{NULL, NULL}
|
|
Karsten Hopp |
b81f34 |
};
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaopen_vim(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! /* set environment */
|
|
Karsten Hopp |
b81f34 |
lua_newtable(L);
|
|
Karsten Hopp |
b81f34 |
lua_newtable(L);
|
|
Karsten Hopp |
b81f34 |
! lua_pushliteral(L, "v");
|
|
Karsten Hopp |
b81f34 |
lua_setfield(L, -2, "__mode");
|
|
Karsten Hopp |
b81f34 |
! lua_setmetatable(L, -2);
|
|
Karsten Hopp |
b81f34 |
! lua_replace(L, LUA_ENVIRONINDEX);
|
|
Karsten Hopp |
b81f34 |
/* print */
|
|
Karsten Hopp |
b81f34 |
lua_pushcfunction(L, luaV_print);
|
|
Karsten Hopp |
b81f34 |
lua_setglobal(L, "print");
|
|
Karsten Hopp |
b81f34 |
--- 1608,1695 ----
|
|
Karsten Hopp |
b81f34 |
{"eval", luaV_eval},
|
|
Karsten Hopp |
b81f34 |
{"beep", luaV_beep},
|
|
Karsten Hopp |
b81f34 |
{"line", luaV_line},
|
|
Karsten Hopp |
b81f34 |
+ {"list", luaV_list},
|
|
Karsten Hopp |
b81f34 |
+ {"dict", luaV_dict},
|
|
Karsten Hopp |
b81f34 |
{"buffer", luaV_buffer},
|
|
Karsten Hopp |
b81f34 |
{"window", luaV_window},
|
|
Karsten Hopp |
b81f34 |
{"open", luaV_open},
|
|
Karsten Hopp |
b81f34 |
! {"type", luaV_type},
|
|
Karsten Hopp |
b81f34 |
{NULL, NULL}
|
|
Karsten Hopp |
b81f34 |
};
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
+ /* for freeing list, dict, buffer and window objects; lightuserdata as arg */
|
|
Karsten Hopp |
b81f34 |
+ static int
|
|
Karsten Hopp |
b81f34 |
+ luaV_free(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
+ luaV_setudata(L, lua_touserdata(L, 1));
|
|
Karsten Hopp |
b81f34 |
+ return 0;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ static int
|
|
Karsten Hopp |
b81f34 |
+ luaV_luaeval (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ luaL_Buffer b;
|
|
Karsten Hopp |
b81f34 |
+ size_t l;
|
|
Karsten Hopp |
b81f34 |
+ const char *str = lua_tolstring(L, 1, &l);
|
|
Karsten Hopp |
b81f34 |
+ typval_T *arg = (typval_T *) lua_touserdata(L, 2);
|
|
Karsten Hopp |
b81f34 |
+ typval_T *rettv = (typval_T *) lua_touserdata(L, 3);
|
|
Karsten Hopp |
b81f34 |
+ luaL_buffinit(L, &b);
|
|
Karsten Hopp |
b81f34 |
+ luaL_addlstring(&b, LUAVIM_EVALHEADER, sizeof(LUAVIM_EVALHEADER) - 1);
|
|
Karsten Hopp |
b81f34 |
+ luaL_addlstring(&b, str, l);
|
|
Karsten Hopp |
b81f34 |
+ luaL_pushresult(&b);
|
|
Karsten Hopp |
b81f34 |
+ str = lua_tolstring(L, -1, &l);
|
|
Karsten Hopp |
b81f34 |
+ if (luaL_loadbuffer(L, str, l, LUAVIM_EVALNAME)) /* compile error? */
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ luaV_emsg(L);
|
|
Karsten Hopp |
b81f34 |
+ return 0;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+ luaV_pushtypval(L, arg);
|
|
Karsten Hopp |
b81f34 |
+ if (lua_pcall(L, 1, 1, 0)) /* running error? */
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ luaV_emsg(L);
|
|
Karsten Hopp |
b81f34 |
+ return 0;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+ luaV_totypval(L, -1, rettv);
|
|
Karsten Hopp |
b81f34 |
+ return 0;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
+ static int
|
|
Karsten Hopp |
b81f34 |
+ luaV_setref (lua_State *L)
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ int copyID = lua_tointeger(L, 1);
|
|
Karsten Hopp |
b81f34 |
+ typval_T tv;
|
|
Karsten Hopp |
b81f34 |
+ luaV_getfield(L, LUAVIM_LIST);
|
|
Karsten Hopp |
b81f34 |
+ luaV_getfield(L, LUAVIM_DICT);
|
|
Karsten Hopp |
b81f34 |
+ lua_pushnil(L);
|
|
Karsten Hopp |
b81f34 |
+ while (lua_next(L, lua_upvalueindex(1)) != 0) /* traverse cache table */
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ lua_getmetatable(L, -1);
|
|
Karsten Hopp |
b81f34 |
+ if (lua_rawequal(L, -1, 2)) /* list? */
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ tv.v_type = VAR_LIST;
|
|
Karsten Hopp |
b81f34 |
+ tv.vval.v_list = (list_T *) lua_touserdata(L, 4); /* key */
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+ else if (lua_rawequal(L, -1, 3)) /* dict? */
|
|
Karsten Hopp |
b81f34 |
+ {
|
|
Karsten Hopp |
b81f34 |
+ tv.v_type = VAR_DICT;
|
|
Karsten Hopp |
b81f34 |
+ tv.vval.v_dict = (dict_T *) lua_touserdata(L, 4); /* key */
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+ lua_pop(L, 2); /* metatable and value */
|
|
Karsten Hopp |
b81f34 |
+ set_ref_in_tv(&tv, copyID);
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+ return 0;
|
|
Karsten Hopp |
b81f34 |
+ }
|
|
Karsten Hopp |
b81f34 |
+
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
luaopen_vim(lua_State *L)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! /* set cache table */
|
|
Karsten Hopp |
b81f34 |
lua_newtable(L);
|
|
Karsten Hopp |
b81f34 |
lua_newtable(L);
|
|
Karsten Hopp |
b81f34 |
! lua_pushstring(L, "v");
|
|
Karsten Hopp |
b81f34 |
lua_setfield(L, -2, "__mode");
|
|
Karsten Hopp |
b81f34 |
! lua_setmetatable(L, -2); /* cache is weak-valued */
|
|
Karsten Hopp |
b81f34 |
/* print */
|
|
Karsten Hopp |
b81f34 |
lua_pushcfunction(L, luaV_print);
|
|
Karsten Hopp |
b81f34 |
lua_setglobal(L, "print");
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 1116,1129 ****
|
|
Karsten Hopp |
b81f34 |
lua_pop(L, 1);
|
|
Karsten Hopp |
b81f34 |
/* free */
|
|
Karsten Hopp |
b81f34 |
lua_pushlightuserdata(L, (void *) LUAVIM_FREE);
|
|
Karsten Hopp |
b81f34 |
! lua_pushcfunction(L, luaV_free);
|
|
Karsten Hopp |
b81f34 |
lua_rawset(L, LUA_REGISTRYINDEX);
|
|
Karsten Hopp |
b81f34 |
/* register */
|
|
Karsten Hopp |
b81f34 |
luaV_newmetatable(L, LUAVIM_BUFFER);
|
|
Karsten Hopp |
b81f34 |
! luaL_register(L, NULL, luaV_Buffer_mt);
|
|
Karsten Hopp |
b81f34 |
luaV_newmetatable(L, LUAVIM_WINDOW);
|
|
Karsten Hopp |
b81f34 |
! luaL_register(L, NULL, luaV_Window_mt);
|
|
Karsten Hopp |
b81f34 |
! luaL_register(L, LUAVIM_NAME, luaV_module);
|
|
Karsten Hopp |
b81f34 |
return 0;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
--- 1700,1735 ----
|
|
Karsten Hopp |
b81f34 |
lua_pop(L, 1);
|
|
Karsten Hopp |
b81f34 |
/* free */
|
|
Karsten Hopp |
b81f34 |
lua_pushlightuserdata(L, (void *) LUAVIM_FREE);
|
|
Karsten Hopp |
b81f34 |
! lua_pushvalue(L, 1); /* cache table */
|
|
Karsten Hopp |
b81f34 |
! lua_pushcclosure(L, luaV_free, 1);
|
|
Karsten Hopp |
b81f34 |
! lua_rawset(L, LUA_REGISTRYINDEX);
|
|
Karsten Hopp |
b81f34 |
! /* luaeval */
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) LUAVIM_LUAEVAL);
|
|
Karsten Hopp |
b81f34 |
! lua_pushvalue(L, 1); /* cache table */
|
|
Karsten Hopp |
b81f34 |
! lua_pushcclosure(L, luaV_luaeval, 1);
|
|
Karsten Hopp |
b81f34 |
! lua_rawset(L, LUA_REGISTRYINDEX);
|
|
Karsten Hopp |
b81f34 |
! /* setref */
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) LUAVIM_SETREF);
|
|
Karsten Hopp |
b81f34 |
! lua_pushvalue(L, 1); /* cache table */
|
|
Karsten Hopp |
b81f34 |
! lua_pushcclosure(L, luaV_setref, 1);
|
|
Karsten Hopp |
b81f34 |
lua_rawset(L, LUA_REGISTRYINDEX);
|
|
Karsten Hopp |
b81f34 |
/* register */
|
|
Karsten Hopp |
b81f34 |
+ luaV_newmetatable(L, LUAVIM_LIST);
|
|
Karsten Hopp |
b81f34 |
+ lua_pushvalue(L, 1);
|
|
Karsten Hopp |
b81f34 |
+ luaV_openlib(L, luaV_List_mt, 1);
|
|
Karsten Hopp |
b81f34 |
+ luaV_newmetatable(L, LUAVIM_DICT);
|
|
Karsten Hopp |
b81f34 |
+ lua_pushvalue(L, 1);
|
|
Karsten Hopp |
b81f34 |
+ luaV_openlib(L, luaV_Dict_mt, 1);
|
|
Karsten Hopp |
b81f34 |
luaV_newmetatable(L, LUAVIM_BUFFER);
|
|
Karsten Hopp |
b81f34 |
! lua_pushvalue(L, 1); /* cache table */
|
|
Karsten Hopp |
b81f34 |
! luaV_openlib(L, luaV_Buffer_mt, 1);
|
|
Karsten Hopp |
b81f34 |
luaV_newmetatable(L, LUAVIM_WINDOW);
|
|
Karsten Hopp |
b81f34 |
! lua_pushvalue(L, 1); /* cache table */
|
|
Karsten Hopp |
b81f34 |
! luaV_openlib(L, luaV_Window_mt, 1);
|
|
Karsten Hopp |
b81f34 |
! lua_newtable(L); /* vim table */
|
|
Karsten Hopp |
b81f34 |
! lua_pushvalue(L, 1); /* cache table */
|
|
Karsten Hopp |
b81f34 |
! luaV_openlib(L, luaV_module, 1);
|
|
Karsten Hopp |
b81f34 |
! lua_setglobal(L, LUAVIM_NAME);
|
|
Karsten Hopp |
b81f34 |
return 0;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 1154,1160 ****
|
|
Karsten Hopp |
b81f34 |
static lua_State *L = NULL;
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
! lua_is_open(void)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
return L != NULL;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
--- 1760,1766 ----
|
|
Karsten Hopp |
b81f34 |
static lua_State *L = NULL;
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
! lua_isopen(void)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
return L != NULL;
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 1162,1168 ****
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
lua_init(void)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! if (L == NULL)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
#ifdef DYNAMIC_LUA
|
|
Karsten Hopp |
b81f34 |
if (!lua_enabled(TRUE))
|
|
Karsten Hopp |
b81f34 |
--- 1768,1774 ----
|
|
Karsten Hopp |
b81f34 |
static int
|
|
Karsten Hopp |
b81f34 |
lua_init(void)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! if (!lua_isopen())
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
#ifdef DYNAMIC_LUA
|
|
Karsten Hopp |
b81f34 |
if (!lua_enabled(TRUE))
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 1179,1185 ****
|
|
Karsten Hopp |
b81f34 |
void
|
|
Karsten Hopp |
b81f34 |
lua_end(void)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! if (L != NULL)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
lua_close(L);
|
|
Karsten Hopp |
b81f34 |
L = NULL;
|
|
Karsten Hopp |
b81f34 |
--- 1785,1791 ----
|
|
Karsten Hopp |
b81f34 |
void
|
|
Karsten Hopp |
b81f34 |
lua_end(void)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! if (lua_isopen())
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
lua_close(L);
|
|
Karsten Hopp |
b81f34 |
L = NULL;
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 1273,1295 ****
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! /* buffer */
|
|
Karsten Hopp |
b81f34 |
void
|
|
Karsten Hopp |
b81f34 |
! lua_buffer_free(buf_T *buf)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! if (!lua_is_open()) return;
|
|
Karsten Hopp |
b81f34 |
! luaV_getfield(L, LUAVIM_FREE);
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) buf);
|
|
Karsten Hopp |
b81f34 |
! lua_call(L, 1, 0);
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
- /* window */
|
|
Karsten Hopp |
b81f34 |
void
|
|
Karsten Hopp |
b81f34 |
! lua_window_free(win_T *win)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! if (!lua_is_open()) return;
|
|
Karsten Hopp |
b81f34 |
! luaV_getfield(L, LUAVIM_FREE);
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) win);
|
|
Karsten Hopp |
b81f34 |
lua_call(L, 1, 0);
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
--- 1879,1914 ----
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
! #define luaV_freetype(typ,tname) \
|
|
Karsten Hopp |
b81f34 |
! void \
|
|
Karsten Hopp |
b81f34 |
! lua_##tname##_free(typ *o) \
|
|
Karsten Hopp |
b81f34 |
! { \
|
|
Karsten Hopp |
b81f34 |
! if (!lua_isopen()) return; \
|
|
Karsten Hopp |
b81f34 |
! luaV_getfield(L, LUAVIM_FREE); \
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) o); \
|
|
Karsten Hopp |
b81f34 |
! lua_call(L, 1, 0); \
|
|
Karsten Hopp |
b81f34 |
! }
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
! luaV_freetype(buf_T, buffer)
|
|
Karsten Hopp |
b81f34 |
! luaV_freetype(win_T, window)
|
|
Karsten Hopp |
b81f34 |
!
|
|
Karsten Hopp |
b81f34 |
void
|
|
Karsten Hopp |
b81f34 |
! do_luaeval (char_u *str, typval_T *arg, typval_T *rettv)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! lua_init();
|
|
Karsten Hopp |
b81f34 |
! luaV_getfield(L, LUAVIM_LUAEVAL);
|
|
Karsten Hopp |
b81f34 |
! lua_pushstring(L, (char *) str);
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) arg);
|
|
Karsten Hopp |
b81f34 |
! lua_pushlightuserdata(L, (void *) rettv);
|
|
Karsten Hopp |
b81f34 |
! lua_call(L, 3, 0);
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
void
|
|
Karsten Hopp |
b81f34 |
! set_ref_in_lua (int copyID)
|
|
Karsten Hopp |
b81f34 |
{
|
|
Karsten Hopp |
b81f34 |
! if (!lua_isopen()) return;
|
|
Karsten Hopp |
b81f34 |
! luaV_getfield(L, LUAVIM_SETREF);
|
|
Karsten Hopp |
b81f34 |
! lua_pushinteger(L, copyID);
|
|
Karsten Hopp |
b81f34 |
lua_call(L, 1, 0);
|
|
Karsten Hopp |
b81f34 |
}
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
*** ../vim-7.3.489/src/proto/if_lua.pro 2010-08-15 21:57:28.000000000 +0200
|
|
Karsten Hopp |
b81f34 |
--- src/proto/if_lua.pro 2012-04-05 16:41:35.000000000 +0200
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 6,9 ****
|
|
Karsten Hopp |
b81f34 |
--- 6,11 ----
|
|
Karsten Hopp |
b81f34 |
void ex_luafile __ARGS((exarg_T *eap));
|
|
Karsten Hopp |
b81f34 |
void lua_buffer_free __ARGS((buf_T *buf));
|
|
Karsten Hopp |
b81f34 |
void lua_window_free __ARGS((win_T *win));
|
|
Karsten Hopp |
b81f34 |
+ void do_luaeval __ARGS((char_u *str, typval_T *arg, typval_T *rettv));
|
|
Karsten Hopp |
b81f34 |
+ void set_ref_in_lua __ARGS((int copyID));
|
|
Karsten Hopp |
b81f34 |
/* vim: set ft=c : */
|
|
Karsten Hopp |
b81f34 |
*** ../vim-7.3.489/src/version.c 2012-04-05 16:07:01.000000000 +0200
|
|
Karsten Hopp |
b81f34 |
--- src/version.c 2012-04-05 16:52:08.000000000 +0200
|
|
Karsten Hopp |
b81f34 |
***************
|
|
Karsten Hopp |
b81f34 |
*** 716,717 ****
|
|
Karsten Hopp |
b81f34 |
--- 716,719 ----
|
|
Karsten Hopp |
b81f34 |
{ /* Add new patch number below this line */
|
|
Karsten Hopp |
b81f34 |
+ /**/
|
|
Karsten Hopp |
b81f34 |
+ 490,
|
|
Karsten Hopp |
b81f34 |
/**/
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
--
|
|
Karsten Hopp |
b81f34 |
Even got a Datapoint 3600(?) with a DD50 connector instead of the
|
|
Karsten Hopp |
b81f34 |
usual DB25... what a nightmare trying to figure out the pinout
|
|
Karsten Hopp |
b81f34 |
for *that* with no spex...
|
|
Karsten Hopp |
b81f34 |
|
|
Karsten Hopp |
b81f34 |
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
|
|
Karsten Hopp |
b81f34 |
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
|
|
Karsten Hopp |
b81f34 |
\\\ an exciting new programming language -- http://www.Zimbu.org ///
|
|
Karsten Hopp |
b81f34 |
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|