annotate src/if_lua.c @ 15979:72987a858c96 v8.1.0995

patch 8.1.0995: a getchar() call resets the reg_executing() result commit https://github.com/vim/vim/commit/f0fab3046c2b5c4115979347464a802853011220 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Mar 5 12:24:10 2019 +0100 patch 8.1.0995: a getchar() call resets the reg_executing() result Problem: A getchar() call while executing a register resets the reg_executing() result. Solution: Save and restore reg_executing. (closes #406
author Bram Moolenaar <Bram@vim.org>
date Tue, 05 Mar 2019 12:30:08 +0100
parents 7fad90423bd2
children 3b524e8110ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2 *
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4 *
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5 * Lua interface by Luis Carvalho
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6 *
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
7 * Do ":help uganda" in Vim to read copying and usage conditions.
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
8 * Do ":help credits" in Vim to see a list of people who contributed.
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
9 * See README.txt for an overview of the Vim source code.
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
10 */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
11
2683
0c7d6d01e058 updated for version 7.3.101
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
12 #include "vim.h"
0c7d6d01e058 updated for version 7.3.101
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
13
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 #include <lua.h>
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15 #include <lualib.h>
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
16 #include <lauxlib.h>
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
17
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
18 /* Only do the following when the feature is enabled. Needed for "make
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
19 * depend". */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
20 #if defined(FEAT_LUA) || defined(PROTO)
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22 #define LUAVIM_CHUNKNAME "vim chunk"
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
23 #define LUAVIM_NAME "vim"
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
24 #define LUAVIM_EVALNAME "luaeval"
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
25 #define LUAVIM_EVALHEADER "local _A=select(1,...) return "
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
26
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27 typedef buf_T *luaV_Buffer;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
28 typedef win_T *luaV_Window;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
29 typedef dict_T *luaV_Dict;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
30 typedef list_T *luaV_List;
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
31 typedef struct {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
32 typval_T tv; // funcref
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
33 typval_T args;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
34 dict_T *self; // selfdict
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
35 } luaV_Funcref;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36 typedef void (*msgfunc_T)(char_u *);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
38 static const char LUAVIM_DICT[] = "dict";
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
39 static const char LUAVIM_LIST[] = "list";
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
40 static const char LUAVIM_FUNCREF[] = "funcref";
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
41 static const char LUAVIM_BUFFER[] = "buffer";
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
42 static const char LUAVIM_WINDOW[] = "window";
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43 static const char LUAVIM_FREE[] = "luaV_free";
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
44 static const char LUAVIM_LUAEVAL[] = "luaV_luaeval";
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
45 static const char LUAVIM_SETREF[] = "luaV_setref";
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
47 /* most functions are closures with a cache table as first upvalue;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
48 * get/setudata manage references to vim userdata in cache table through
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
49 * object pointers (light userdata) */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
50 #define luaV_getudata(L, v) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
51 lua_pushlightuserdata((L), (void *) (v)); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
52 lua_rawget((L), lua_upvalueindex(1))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
53 #define luaV_setudata(L, v) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
54 lua_pushlightuserdata((L), (void *) (v)); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
55 lua_pushvalue((L), -2); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
56 lua_rawset((L), lua_upvalueindex(1))
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57 #define luaV_getfield(L, s) \
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 lua_pushlightuserdata((L), (void *)(s)); \
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59 lua_rawget((L), LUA_REGISTRYINDEX)
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60 #define luaV_checksandbox(L) \
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 if (sandbox) luaL_error((L), "not allowed in sandbox")
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62 #define luaV_msg(L) luaV_msgfunc((L), (msgfunc_T) msg)
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 #define luaV_emsg(L) luaV_msgfunc((L), (msgfunc_T) emsg)
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
64 #define luaV_checktypval(L, a, v, msg) \
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
65 do { \
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
66 if (luaV_totypval(L, a, v) == FAIL) \
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
67 luaL_error(L, msg ": cannot convert value"); \
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
68 } while (0)
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
70 static luaV_List *luaV_pushlist(lua_State *L, list_T *lis);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
71 static luaV_Dict *luaV_pushdict(lua_State *L, dict_T *dic);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
72 static luaV_Funcref *luaV_pushfuncref(lua_State *L, typval_T *tv);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
73
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
74 #if LUA_VERSION_NUM <= 501
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
75 #define luaV_openlib(L, l, n) luaL_openlib(L, NULL, l, n)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
76 #define luaL_typeerror luaL_typerror
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
77 #else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
78 #define luaV_openlib luaL_setfuncs
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
79 #endif
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
80
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
81 #ifdef DYNAMIC_LUA
2373
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
82
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
83 #ifndef MSWIN
2373
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
84 # include <dlfcn.h>
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
85 # define HANDLE void*
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
86 # define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
87 # define symbol_from_dll dlsym
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
88 # define close_dll dlclose
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
89 #else
2612
fa5dee44df3f updated for version 7.3.034
Bram Moolenaar <bram@vim.org>
parents: 2543
diff changeset
90 # define load_dll vimLoadLib
2373
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
91 # define symbol_from_dll GetProcAddress
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
92 # define close_dll FreeLibrary
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
93 #endif
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
94
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
95 /* lauxlib */
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
96 #if LUA_VERSION_NUM <= 501
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
97 #define luaL_register dll_luaL_register
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
98 #define luaL_prepbuffer dll_luaL_prepbuffer
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
99 #define luaL_openlib dll_luaL_openlib
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
100 #define luaL_typerror dll_luaL_typerror
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
101 #define luaL_loadfile dll_luaL_loadfile
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
102 #define luaL_loadbuffer dll_luaL_loadbuffer
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
103 #else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
104 #define luaL_prepbuffsize dll_luaL_prepbuffsize
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
105 #define luaL_setfuncs dll_luaL_setfuncs
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
106 #define luaL_loadfilex dll_luaL_loadfilex
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
107 #define luaL_loadbufferx dll_luaL_loadbufferx
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
108 #define luaL_argerror dll_luaL_argerror
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
109 #endif
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
110 #define luaL_checkany dll_luaL_checkany
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
111 #define luaL_checklstring dll_luaL_checklstring
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
112 #define luaL_checkinteger dll_luaL_checkinteger
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
113 #define luaL_optinteger dll_luaL_optinteger
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
114 #define luaL_checktype dll_luaL_checktype
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
115 #define luaL_error dll_luaL_error
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
116 #define luaL_newstate dll_luaL_newstate
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
117 #define luaL_buffinit dll_luaL_buffinit
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
118 #define luaL_addlstring dll_luaL_addlstring
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
119 #define luaL_pushresult dll_luaL_pushresult
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
120 /* lua */
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
121 #if LUA_VERSION_NUM <= 501
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
122 #define lua_tonumber dll_lua_tonumber
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
123 #define lua_tointeger dll_lua_tointeger
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
124 #define lua_call dll_lua_call
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
125 #define lua_pcall dll_lua_pcall
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
126 #else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
127 #define lua_tonumberx dll_lua_tonumberx
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
128 #define lua_tointegerx dll_lua_tointegerx
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
129 #define lua_callk dll_lua_callk
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
130 #define lua_pcallk dll_lua_pcallk
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
131 #define lua_getglobal dll_lua_getglobal
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
132 #define lua_setglobal dll_lua_setglobal
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
133 #endif
6887
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
134 #if LUA_VERSION_NUM <= 502
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
135 #define lua_replace dll_lua_replace
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
136 #define lua_remove dll_lua_remove
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
137 #endif
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
138 #if LUA_VERSION_NUM >= 503
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
139 #define lua_rotate dll_lua_rotate
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
140 #define lua_copy dll_lua_copy
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
141 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
142 #define lua_typename dll_lua_typename
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
143 #define lua_close dll_lua_close
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
144 #define lua_gettop dll_lua_gettop
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
145 #define lua_settop dll_lua_settop
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
146 #define lua_pushvalue dll_lua_pushvalue
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
147 #define lua_isnumber dll_lua_isnumber
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
148 #define lua_isstring dll_lua_isstring
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
149 #define lua_type dll_lua_type
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
150 #define lua_rawequal dll_lua_rawequal
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
151 #define lua_toboolean dll_lua_toboolean
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
152 #define lua_tolstring dll_lua_tolstring
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
153 #define lua_touserdata dll_lua_touserdata
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
154 #define lua_pushnil dll_lua_pushnil
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
155 #define lua_pushnumber dll_lua_pushnumber
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
156 #define lua_pushinteger dll_lua_pushinteger
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
157 #define lua_pushlstring dll_lua_pushlstring
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
158 #define lua_pushstring dll_lua_pushstring
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
159 #define lua_pushfstring dll_lua_pushfstring
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
160 #define lua_pushcclosure dll_lua_pushcclosure
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
161 #define lua_pushboolean dll_lua_pushboolean
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
162 #define lua_pushlightuserdata dll_lua_pushlightuserdata
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
163 #define lua_getfield dll_lua_getfield
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
164 #define lua_rawget dll_lua_rawget
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
165 #define lua_rawgeti dll_lua_rawgeti
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
166 #define lua_createtable dll_lua_createtable
14583
42eaac6eb4e4 patch 8.1.0305: missing support for Lua 5.4 32 bits on Unix
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
167 #if LUA_VERSION_NUM >= 504
42eaac6eb4e4 patch 8.1.0305: missing support for Lua 5.4 32 bits on Unix
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
168 #define lua_newuserdatauv dll_lua_newuserdatauv
42eaac6eb4e4 patch 8.1.0305: missing support for Lua 5.4 32 bits on Unix
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
169 #else
42eaac6eb4e4 patch 8.1.0305: missing support for Lua 5.4 32 bits on Unix
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
170 #define lua_newuserdata dll_lua_newuserdata
42eaac6eb4e4 patch 8.1.0305: missing support for Lua 5.4 32 bits on Unix
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
171 #endif
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
172 #define lua_getmetatable dll_lua_getmetatable
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
173 #define lua_setfield dll_lua_setfield
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
174 #define lua_rawset dll_lua_rawset
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
175 #define lua_rawseti dll_lua_rawseti
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
176 #define lua_setmetatable dll_lua_setmetatable
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
177 #define lua_next dll_lua_next
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
178 /* libs */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
179 #define luaopen_base dll_luaopen_base
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
180 #define luaopen_table dll_luaopen_table
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
181 #define luaopen_string dll_luaopen_string
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
182 #define luaopen_math dll_luaopen_math
2431
7b764999f9b9 Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2373
diff changeset
183 #define luaopen_io dll_luaopen_io
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
184 #define luaopen_os dll_luaopen_os
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
185 #define luaopen_package dll_luaopen_package
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
186 #define luaopen_debug dll_luaopen_debug
2431
7b764999f9b9 Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2373
diff changeset
187 #define luaL_openlibs dll_luaL_openlibs
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
188
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
189 /* lauxlib */
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
190 #if LUA_VERSION_NUM <= 501
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
191 void (*dll_luaL_register) (lua_State *L, const char *libname, const luaL_Reg *l);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
192 char *(*dll_luaL_prepbuffer) (luaL_Buffer *B);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
193 void (*dll_luaL_openlib) (lua_State *L, const char *libname, const luaL_Reg *l, int nup);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
194 int (*dll_luaL_typerror) (lua_State *L, int narg, const char *tname);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
195 int (*dll_luaL_loadfile) (lua_State *L, const char *filename);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
196 int (*dll_luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, const char *name);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
197 #else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
198 char *(*dll_luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
199 void (*dll_luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
200 int (*dll_luaL_loadfilex) (lua_State *L, const char *filename, const char *mode);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
201 int (*dll_luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, const char *name, const char *mode);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
202 int (*dll_luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
203 #endif
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
204 void (*dll_luaL_checkany) (lua_State *L, int narg);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
205 const char *(*dll_luaL_checklstring) (lua_State *L, int numArg, size_t *l);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
206 lua_Integer (*dll_luaL_checkinteger) (lua_State *L, int numArg);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
207 lua_Integer (*dll_luaL_optinteger) (lua_State *L, int nArg, lua_Integer def);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
208 void (*dll_luaL_checktype) (lua_State *L, int narg, int t);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
209 int (*dll_luaL_error) (lua_State *L, const char *fmt, ...);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
210 lua_State *(*dll_luaL_newstate) (void);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
211 void (*dll_luaL_buffinit) (lua_State *L, luaL_Buffer *B);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
212 void (*dll_luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
213 void (*dll_luaL_pushresult) (luaL_Buffer *B);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
214 /* lua */
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
215 #if LUA_VERSION_NUM <= 501
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
216 lua_Number (*dll_lua_tonumber) (lua_State *L, int idx);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
217 lua_Integer (*dll_lua_tointeger) (lua_State *L, int idx);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
218 void (*dll_lua_call) (lua_State *L, int nargs, int nresults);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
219 int (*dll_lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
220 #else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
221 lua_Number (*dll_lua_tonumberx) (lua_State *L, int idx, int *isnum);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
222 lua_Integer (*dll_lua_tointegerx) (lua_State *L, int idx, int *isnum);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
223 void (*dll_lua_callk) (lua_State *L, int nargs, int nresults, int ctx,
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3459
diff changeset
224 lua_CFunction k);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
225 int (*dll_lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3459
diff changeset
226 int ctx, lua_CFunction k);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
227 void (*dll_lua_getglobal) (lua_State *L, const char *var);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
228 void (*dll_lua_setglobal) (lua_State *L, const char *var);
6887
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
229 #endif
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
230 #if LUA_VERSION_NUM <= 502
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
231 void (*dll_lua_replace) (lua_State *L, int idx);
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
232 void (*dll_lua_remove) (lua_State *L, int idx);
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
233 #endif
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
234 #if LUA_VERSION_NUM >= 503
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
235 void (*dll_lua_rotate) (lua_State *L, int idx, int n);
6878
02466bf84bab patch 7.4.759
Bram Moolenaar <bram@vim.org>
parents: 6625
diff changeset
236 void (*dll_lua_copy) (lua_State *L, int fromidx, int toidx);
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
237 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
238 const char *(*dll_lua_typename) (lua_State *L, int tp);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
239 void (*dll_lua_close) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
240 int (*dll_lua_gettop) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
241 void (*dll_lua_settop) (lua_State *L, int idx);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
242 void (*dll_lua_pushvalue) (lua_State *L, int idx);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
243 int (*dll_lua_isnumber) (lua_State *L, int idx);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
244 int (*dll_lua_isstring) (lua_State *L, int idx);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
245 int (*dll_lua_type) (lua_State *L, int idx);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
246 int (*dll_lua_rawequal) (lua_State *L, int idx1, int idx2);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
247 int (*dll_lua_toboolean) (lua_State *L, int idx);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
248 const char *(*dll_lua_tolstring) (lua_State *L, int idx, size_t *len);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
249 void *(*dll_lua_touserdata) (lua_State *L, int idx);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
250 void (*dll_lua_pushnil) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
251 void (*dll_lua_pushnumber) (lua_State *L, lua_Number n);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
252 void (*dll_lua_pushinteger) (lua_State *L, lua_Integer n);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
253 void (*dll_lua_pushlstring) (lua_State *L, const char *s, size_t l);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
254 void (*dll_lua_pushstring) (lua_State *L, const char *s);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
255 const char *(*dll_lua_pushfstring) (lua_State *L, const char *fmt, ...);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
256 void (*dll_lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
257 void (*dll_lua_pushboolean) (lua_State *L, int b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
258 void (*dll_lua_pushlightuserdata) (lua_State *L, void *p);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
259 void (*dll_lua_getfield) (lua_State *L, int idx, const char *k);
14335
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
260 #if LUA_VERSION_NUM <= 502
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
261 void (*dll_lua_rawget) (lua_State *L, int idx);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
262 void (*dll_lua_rawgeti) (lua_State *L, int idx, int n);
14335
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
263 #else
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
264 int (*dll_lua_rawget) (lua_State *L, int idx);
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
265 int (*dll_lua_rawgeti) (lua_State *L, int idx, lua_Integer n);
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
266 #endif
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
267 void (*dll_lua_createtable) (lua_State *L, int narr, int nrec);
14583
42eaac6eb4e4 patch 8.1.0305: missing support for Lua 5.4 32 bits on Unix
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
268 #if LUA_VERSION_NUM >= 504
42eaac6eb4e4 patch 8.1.0305: missing support for Lua 5.4 32 bits on Unix
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
269 void *(*dll_lua_newuserdatauv) (lua_State *L, size_t sz, int nuvalue);
42eaac6eb4e4 patch 8.1.0305: missing support for Lua 5.4 32 bits on Unix
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
270 #else
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
271 void *(*dll_lua_newuserdata) (lua_State *L, size_t sz);
14583
42eaac6eb4e4 patch 8.1.0305: missing support for Lua 5.4 32 bits on Unix
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
272 #endif
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
273 int (*dll_lua_getmetatable) (lua_State *L, int objindex);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
274 void (*dll_lua_setfield) (lua_State *L, int idx, const char *k);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
275 void (*dll_lua_rawset) (lua_State *L, int idx);
14335
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
276 #if LUA_VERSION_NUM <= 502
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
277 void (*dll_lua_rawseti) (lua_State *L, int idx, int n);
14335
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
278 #else
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
279 void (*dll_lua_rawseti) (lua_State *L, int idx, lua_Integer n);
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
280 #endif
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
281 int (*dll_lua_setmetatable) (lua_State *L, int objindex);
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
282 int (*dll_lua_next) (lua_State *L, int idx);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
283 /* libs */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
284 int (*dll_luaopen_base) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
285 int (*dll_luaopen_table) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
286 int (*dll_luaopen_string) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
287 int (*dll_luaopen_math) (lua_State *L);
2431
7b764999f9b9 Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2373
diff changeset
288 int (*dll_luaopen_io) (lua_State *L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
289 int (*dll_luaopen_os) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
290 int (*dll_luaopen_package) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
291 int (*dll_luaopen_debug) (lua_State *L);
2431
7b764999f9b9 Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2373
diff changeset
292 void (*dll_luaL_openlibs) (lua_State *L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
293
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
294 typedef void **luaV_function;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
295 typedef struct {
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
296 const char *name;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
297 luaV_function func;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
298 } luaV_Reg;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
299
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
300 static const luaV_Reg luaV_dll[] = {
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
301 /* lauxlib */
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
302 #if LUA_VERSION_NUM <= 501
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
303 {"luaL_register", (luaV_function) &dll_luaL_register},
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
304 {"luaL_prepbuffer", (luaV_function) &dll_luaL_prepbuffer},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
305 {"luaL_openlib", (luaV_function) &dll_luaL_openlib},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
306 {"luaL_typerror", (luaV_function) &dll_luaL_typerror},
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
307 {"luaL_loadfile", (luaV_function) &dll_luaL_loadfile},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
308 {"luaL_loadbuffer", (luaV_function) &dll_luaL_loadbuffer},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
309 #else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
310 {"luaL_prepbuffsize", (luaV_function) &dll_luaL_prepbuffsize},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
311 {"luaL_setfuncs", (luaV_function) &dll_luaL_setfuncs},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
312 {"luaL_loadfilex", (luaV_function) &dll_luaL_loadfilex},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
313 {"luaL_loadbufferx", (luaV_function) &dll_luaL_loadbufferx},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
314 {"luaL_argerror", (luaV_function) &dll_luaL_argerror},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
315 #endif
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
316 {"luaL_checkany", (luaV_function) &dll_luaL_checkany},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
317 {"luaL_checklstring", (luaV_function) &dll_luaL_checklstring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
318 {"luaL_checkinteger", (luaV_function) &dll_luaL_checkinteger},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
319 {"luaL_optinteger", (luaV_function) &dll_luaL_optinteger},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
320 {"luaL_checktype", (luaV_function) &dll_luaL_checktype},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
321 {"luaL_error", (luaV_function) &dll_luaL_error},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
322 {"luaL_newstate", (luaV_function) &dll_luaL_newstate},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
323 {"luaL_buffinit", (luaV_function) &dll_luaL_buffinit},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
324 {"luaL_addlstring", (luaV_function) &dll_luaL_addlstring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
325 {"luaL_pushresult", (luaV_function) &dll_luaL_pushresult},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
326 /* lua */
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
327 #if LUA_VERSION_NUM <= 501
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
328 {"lua_tonumber", (luaV_function) &dll_lua_tonumber},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
329 {"lua_tointeger", (luaV_function) &dll_lua_tointeger},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
330 {"lua_call", (luaV_function) &dll_lua_call},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
331 {"lua_pcall", (luaV_function) &dll_lua_pcall},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
332 #else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
333 {"lua_tonumberx", (luaV_function) &dll_lua_tonumberx},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
334 {"lua_tointegerx", (luaV_function) &dll_lua_tointegerx},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
335 {"lua_callk", (luaV_function) &dll_lua_callk},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
336 {"lua_pcallk", (luaV_function) &dll_lua_pcallk},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
337 {"lua_getglobal", (luaV_function) &dll_lua_getglobal},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
338 {"lua_setglobal", (luaV_function) &dll_lua_setglobal},
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
339 #endif
6887
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
340 #if LUA_VERSION_NUM <= 502
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
341 {"lua_replace", (luaV_function) &dll_lua_replace},
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
342 {"lua_remove", (luaV_function) &dll_lua_remove},
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
343 #endif
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
344 #if LUA_VERSION_NUM >= 503
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
345 {"lua_rotate", (luaV_function) &dll_lua_rotate},
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
346 {"lua_copy", (luaV_function) &dll_lua_copy},
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
347 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
348 {"lua_typename", (luaV_function) &dll_lua_typename},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
349 {"lua_close", (luaV_function) &dll_lua_close},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
350 {"lua_gettop", (luaV_function) &dll_lua_gettop},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
351 {"lua_settop", (luaV_function) &dll_lua_settop},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
352 {"lua_pushvalue", (luaV_function) &dll_lua_pushvalue},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
353 {"lua_isnumber", (luaV_function) &dll_lua_isnumber},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
354 {"lua_isstring", (luaV_function) &dll_lua_isstring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
355 {"lua_type", (luaV_function) &dll_lua_type},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
356 {"lua_rawequal", (luaV_function) &dll_lua_rawequal},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
357 {"lua_toboolean", (luaV_function) &dll_lua_toboolean},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
358 {"lua_tolstring", (luaV_function) &dll_lua_tolstring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
359 {"lua_touserdata", (luaV_function) &dll_lua_touserdata},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
360 {"lua_pushnil", (luaV_function) &dll_lua_pushnil},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
361 {"lua_pushnumber", (luaV_function) &dll_lua_pushnumber},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
362 {"lua_pushinteger", (luaV_function) &dll_lua_pushinteger},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
363 {"lua_pushlstring", (luaV_function) &dll_lua_pushlstring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
364 {"lua_pushstring", (luaV_function) &dll_lua_pushstring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
365 {"lua_pushfstring", (luaV_function) &dll_lua_pushfstring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
366 {"lua_pushcclosure", (luaV_function) &dll_lua_pushcclosure},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
367 {"lua_pushboolean", (luaV_function) &dll_lua_pushboolean},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
368 {"lua_pushlightuserdata", (luaV_function) &dll_lua_pushlightuserdata},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
369 {"lua_getfield", (luaV_function) &dll_lua_getfield},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
370 {"lua_rawget", (luaV_function) &dll_lua_rawget},
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
371 {"lua_rawgeti", (luaV_function) &dll_lua_rawgeti},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
372 {"lua_createtable", (luaV_function) &dll_lua_createtable},
14583
42eaac6eb4e4 patch 8.1.0305: missing support for Lua 5.4 32 bits on Unix
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
373 #if LUA_VERSION_NUM >= 504
42eaac6eb4e4 patch 8.1.0305: missing support for Lua 5.4 32 bits on Unix
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
374 {"lua_newuserdatauv", (luaV_function) &dll_lua_newuserdatauv},
42eaac6eb4e4 patch 8.1.0305: missing support for Lua 5.4 32 bits on Unix
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
375 #else
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
376 {"lua_newuserdata", (luaV_function) &dll_lua_newuserdata},
14583
42eaac6eb4e4 patch 8.1.0305: missing support for Lua 5.4 32 bits on Unix
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
377 #endif
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
378 {"lua_getmetatable", (luaV_function) &dll_lua_getmetatable},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
379 {"lua_setfield", (luaV_function) &dll_lua_setfield},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
380 {"lua_rawset", (luaV_function) &dll_lua_rawset},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
381 {"lua_rawseti", (luaV_function) &dll_lua_rawseti},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
382 {"lua_setmetatable", (luaV_function) &dll_lua_setmetatable},
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
383 {"lua_next", (luaV_function) &dll_lua_next},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
384 /* libs */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
385 {"luaopen_base", (luaV_function) &dll_luaopen_base},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
386 {"luaopen_table", (luaV_function) &dll_luaopen_table},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
387 {"luaopen_string", (luaV_function) &dll_luaopen_string},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
388 {"luaopen_math", (luaV_function) &dll_luaopen_math},
2431
7b764999f9b9 Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2373
diff changeset
389 {"luaopen_io", (luaV_function) &dll_luaopen_io},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
390 {"luaopen_os", (luaV_function) &dll_luaopen_os},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
391 {"luaopen_package", (luaV_function) &dll_luaopen_package},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
392 {"luaopen_debug", (luaV_function) &dll_luaopen_debug},
2431
7b764999f9b9 Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2373
diff changeset
393 {"luaL_openlibs", (luaV_function) &dll_luaL_openlibs},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
394 {NULL, NULL}
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
395 };
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
396
2373
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
397 static HANDLE hinstLua = NULL;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
398
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
399 static void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
400 end_dynamic_lua(void)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
401 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
402 if (hinstLua)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
403 {
2373
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
404 close_dll(hinstLua);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
405 hinstLua = 0;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
406 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
407 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
408
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
409 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
410 lua_link_init(char *libname, int verbose)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
411 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
412 const luaV_Reg *reg;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
413 if (hinstLua) return OK;
2373
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
414 hinstLua = load_dll(libname);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
415 if (!hinstLua)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
416 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
417 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15328
diff changeset
418 semsg(_(e_loadlib), libname);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
419 return FAIL;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
420 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
421 for (reg = luaV_dll; reg->func; reg++)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
422 {
2373
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
423 if ((*reg->func = symbol_from_dll(hinstLua, reg->name)) == NULL)
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
424 {
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
425 close_dll(hinstLua);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
426 hinstLua = 0;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
427 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15328
diff changeset
428 semsg(_(e_loadfunc), reg->name);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
429 return FAIL;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
430 }
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
431 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
432 return OK;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
433 }
10025
068f397d0da4 commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
434 #endif /* DYNAMIC_LUA */
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
435
10025
068f397d0da4 commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
436 #if defined(DYNAMIC_LUA) || defined(PROTO)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
437 int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
438 lua_enabled(int verbose)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
439 {
7528
53163e4d9e4f commit https://github.com/vim/vim/commit/25e4fcde767084d1a79e0926bc301c92987c0cce
Christian Brabandt <cb@256bit.org>
parents: 7297
diff changeset
440 return lua_link_init((char *)p_luadll, verbose) == OK;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
441 }
10025
068f397d0da4 commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
442 #endif
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
443
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
444 #if LUA_VERSION_NUM > 501
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
445 static int
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
446 luaL_typeerror (lua_State *L, int narg, const char *tname)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
447 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
448 const char *msg = lua_pushfstring(L, "%s expected, got %s",
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3459
diff changeset
449 tname, luaL_typename(L, narg));
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
450 return luaL_argerror(L, narg, msg);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
451 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
452 #endif
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
453
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
454
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
455 /* ======= Internal ======= */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
456
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
457 static void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
458 luaV_newmetatable(lua_State *L, const char *tname)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
459 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
460 lua_newtable(L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
461 lua_pushlightuserdata(L, (void *) tname);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
462 lua_pushvalue(L, -2);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
463 lua_rawset(L, LUA_REGISTRYINDEX);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
464 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
465
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
466 static void *
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
467 luaV_toudata(lua_State *L, int ud, const char *tname)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
468 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
469 void *p = lua_touserdata(L, ud);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
470
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
471 if (p != NULL) /* value is userdata? */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
472 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
473 if (lua_getmetatable(L, ud)) /* does it have a metatable? */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
474 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
475 luaV_getfield(L, tname); /* get metatable */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
476 if (lua_rawequal(L, -1, -2)) /* MTs match? */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
477 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
478 lua_pop(L, 2); /* MTs */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
479 return p;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
480 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
481 }
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
482 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
483 return NULL;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
484 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
485
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
486 static void *
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
487 luaV_checkcache(lua_State *L, void *p)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
488 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
489 luaV_getudata(L, p);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
490 if (lua_isnil(L, -1)) luaL_error(L, "invalid object");
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
491 lua_pop(L, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
492 return p;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
493 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
494
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
495 #define luaV_unbox(L,luatyp,ud) (*((luatyp *) lua_touserdata((L),(ud))))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
496
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
497 #define luaV_checkvalid(L,luatyp,ud) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
498 luaV_checkcache((L), (void *) luaV_unbox((L),luatyp,(ud)))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
499
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
500 static void *
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
501 luaV_checkudata(lua_State *L, int ud, const char *tname)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
502 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
503 void *p = luaV_toudata(L, ud, tname);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
504 if (p == NULL) luaL_typeerror(L, ud, tname);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
505 return p;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
506 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
507
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
508 static void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
509 luaV_pushtypval(lua_State *L, typval_T *tv)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
510 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
511 if (tv == NULL)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
512 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
513 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
514 return;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
515 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
516 switch (tv->v_type)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
517 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
518 case VAR_STRING:
3865
3c072c1cb873 updated for version 7.3.689
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
519 lua_pushstring(L, tv->vval.v_string == NULL
3c072c1cb873 updated for version 7.3.689
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
520 ? "" : (char *)tv->vval.v_string);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
521 break;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
522 case VAR_NUMBER:
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
523 lua_pushinteger(L, (int) tv->vval.v_number);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
524 break;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
525 #ifdef FEAT_FLOAT
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
526 case VAR_FLOAT:
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
527 lua_pushnumber(L, (lua_Number) tv->vval.v_float);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
528 break;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
529 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
530 case VAR_LIST:
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
531 luaV_pushlist(L, tv->vval.v_list);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
532 break;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
533 case VAR_DICT:
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
534 luaV_pushdict(L, tv->vval.v_dict);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
535 break;
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7528
diff changeset
536 case VAR_SPECIAL:
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7528
diff changeset
537 if (tv->vval.v_number <= VVAL_TRUE)
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7528
diff changeset
538 lua_pushinteger(L, (int) tv->vval.v_number);
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7528
diff changeset
539 else
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7528
diff changeset
540 lua_pushnil(L);
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7528
diff changeset
541 break;
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
542 case VAR_FUNC:
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
543 luaV_pushfuncref(L, tv);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
544 break;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
545 default:
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
546 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
547 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
548 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
549
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
550 /*
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
551 * Converts lua value at 'pos' to typval 'tv'.
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
552 * Returns OK or FAIL.
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
553 */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
554 static int
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
555 luaV_totypval(lua_State *L, int pos, typval_T *tv)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
556 {
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
557 int status = OK;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
558
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
559 switch (lua_type(L, pos))
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
560 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
561 case LUA_TBOOLEAN:
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7528
diff changeset
562 tv->v_type = VAR_SPECIAL;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
563 tv->vval.v_number = (varnumber_T) lua_toboolean(L, pos);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
564 break;
15328
f7130bc17248 patch 8.1.0672: the Lua interface doesn't know about v:null
Bram Moolenaar <Bram@vim.org>
parents: 14583
diff changeset
565 case LUA_TNIL:
f7130bc17248 patch 8.1.0672: the Lua interface doesn't know about v:null
Bram Moolenaar <Bram@vim.org>
parents: 14583
diff changeset
566 tv->v_type = VAR_SPECIAL;
f7130bc17248 patch 8.1.0672: the Lua interface doesn't know about v:null
Bram Moolenaar <Bram@vim.org>
parents: 14583
diff changeset
567 tv->vval.v_number = VVAL_NULL;
f7130bc17248 patch 8.1.0672: the Lua interface doesn't know about v:null
Bram Moolenaar <Bram@vim.org>
parents: 14583
diff changeset
568 break;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
569 case LUA_TSTRING:
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
570 tv->v_type = VAR_STRING;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
571 tv->vval.v_string = vim_strsave((char_u *) lua_tostring(L, pos));
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
572 break;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
573 case LUA_TNUMBER:
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
574 #ifdef FEAT_FLOAT
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
575 tv->v_type = VAR_FLOAT;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
576 tv->vval.v_float = (float_T) lua_tonumber(L, pos);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
577 #else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
578 tv->v_type = VAR_NUMBER;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
579 tv->vval.v_number = (varnumber_T) lua_tointeger(L, pos);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
580 #endif
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
581 break;
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
582 case LUA_TUSERDATA:
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
583 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
584 void *p = lua_touserdata(L, pos);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
585
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
586 if (lua_getmetatable(L, pos)) /* has metatable? */
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
587 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
588 /* check list */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
589 luaV_getfield(L, LUAVIM_LIST);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
590 if (lua_rawequal(L, -1, -2))
2373
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
591 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
592 tv->v_type = VAR_LIST;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
593 tv->vval.v_list = *((luaV_List *) p);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
594 ++tv->vval.v_list->lv_refcount;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
595 lua_pop(L, 2); /* MTs */
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
596 break;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
597 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
598 /* check dict */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
599 luaV_getfield(L, LUAVIM_DICT);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
600 if (lua_rawequal(L, -1, -3))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
601 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
602 tv->v_type = VAR_DICT;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
603 tv->vval.v_dict = *((luaV_Dict *) p);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
604 ++tv->vval.v_dict->dv_refcount;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
605 lua_pop(L, 3); /* MTs */
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
606 break;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
607 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
608 /* check funcref */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
609 luaV_getfield(L, LUAVIM_FUNCREF);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
610 if (lua_rawequal(L, -1, -4))
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
611 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
612 luaV_Funcref *f = (luaV_Funcref *) p;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
613 copy_tv(&f->tv, tv);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
614 lua_pop(L, 4); /* MTs */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
615 break;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
616 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
617 lua_pop(L, 4); /* MTs */
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
618 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
619 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
620 /* FALLTHROUGH */
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
621 default:
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
622 tv->v_type = VAR_NUMBER;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
623 tv->vval.v_number = 0;
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
624 status = FAIL;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
625 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
626 return status;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
627 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
628
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
629 /* similar to luaL_addlstring, but replaces \0 with \n if toline and
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
630 * \n with \0 otherwise */
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
631 static void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
632 luaV_addlstring(luaL_Buffer *b, const char *s, size_t l, int toline)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
633 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
634 while (l--)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
635 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
636 if (*s == '\0' && toline)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
637 luaL_addchar(b, '\n');
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
638 else if (*s == '\n' && !toline)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
639 luaL_addchar(b, '\0');
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
640 else
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
641 luaL_addchar(b, *s);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
642 s++;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
643 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
644 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
645
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
646 static void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
647 luaV_pushline(lua_State *L, buf_T *buf, linenr_T n)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
648 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
649 const char *s = (const char *) ml_get_buf(buf, n, FALSE);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
650 luaL_Buffer b;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
651 luaL_buffinit(L, &b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
652 luaV_addlstring(&b, s, strlen(s), 0);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
653 luaL_pushresult(&b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
654 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
655
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
656 static char_u *
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
657 luaV_toline(lua_State *L, int pos)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
658 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
659 size_t l;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
660 const char *s = lua_tolstring(L, pos, &l);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
661
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
662 luaL_Buffer b;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
663 luaL_buffinit(L, &b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
664 luaV_addlstring(&b, s, l, 1);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
665 luaL_pushresult(&b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
666 return (char_u *) lua_tostring(L, -1);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
667 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
668
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
669 /* pops a string s from the top of the stack and calls mf(t) for pieces t of
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
670 * s separated by newlines */
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
671 static void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
672 luaV_msgfunc(lua_State *L, msgfunc_T mf)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
673 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
674 luaL_Buffer b;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
675 size_t l;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
676 const char *p, *s = lua_tolstring(L, -1, &l);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
677 luaL_buffinit(L, &b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
678 luaV_addlstring(&b, s, l, 0);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
679 luaL_pushresult(&b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
680 /* break string */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
681 p = s = lua_tolstring(L, -1, &l);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
682 while (l--)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
683 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
684 if (*p++ == '\0') /* break? */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
685 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
686 mf((char_u *) s);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
687 s = p;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
688 }
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
689 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
690 mf((char_u *) s);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
691 lua_pop(L, 2); /* original and modified strings */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
692 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
693
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
694 #define luaV_newtype(typ,tname,luatyp,luatname) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
695 static luatyp * \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
696 luaV_new##tname (lua_State *L, typ *obj) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
697 { \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
698 luatyp *o = (luatyp *) lua_newuserdata(L, sizeof(luatyp)); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
699 *o = obj; \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
700 luaV_setudata(L, obj); /* cache[obj] = udata */ \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
701 luaV_getfield(L, luatname); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
702 lua_setmetatable(L, -2); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
703 return o; \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
704 }
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
705
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
706 #define luaV_pushtype(typ,tname,luatyp) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
707 static luatyp * \
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
708 luaV_push##tname(lua_State *L, typ *obj) \
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
709 { \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
710 luatyp *o = NULL; \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
711 if (obj == NULL) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
712 lua_pushnil(L); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
713 else { \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
714 luaV_getudata(L, obj); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
715 if (lua_isnil(L, -1)) /* not interned? */ \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
716 { \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
717 lua_pop(L, 1); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
718 o = luaV_new##tname(L, obj); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
719 } \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
720 else \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
721 o = (luatyp *) lua_touserdata(L, -1); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
722 } \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
723 return o; \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
724 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
725
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
726 #define luaV_type_tostring(tname,luatname) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
727 static int \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
728 luaV_##tname##_tostring (lua_State *L) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
729 { \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
730 lua_pushfstring(L, "%s: %p", luatname, lua_touserdata(L, 1)); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
731 return 1; \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
732 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
733
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
734 /* ======= List type ======= */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
735
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
736 static luaV_List *
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
737 luaV_newlist (lua_State *L, list_T *lis)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
738 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
739 luaV_List *l = (luaV_List *) lua_newuserdata(L, sizeof(luaV_List));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
740 *l = lis;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
741 lis->lv_refcount++; /* reference in Lua */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
742 luaV_setudata(L, lis); /* cache[lis] = udata */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
743 luaV_getfield(L, LUAVIM_LIST);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
744 lua_setmetatable(L, -2);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
745 return l;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
746 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
747
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
748 luaV_pushtype(list_T, list, luaV_List)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
749 luaV_type_tostring(list, LUAVIM_LIST)
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
750
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
751 static int
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
752 luaV_list_len (lua_State *L)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
753 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
754 list_T *l = luaV_unbox(L, luaV_List, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
755 lua_pushinteger(L, (l == NULL) ? 0 : (int) l->lv_len);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
756 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
757 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
758
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
759 static int
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
760 luaV_list_iter (lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
761 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
762 listitem_T *li = (listitem_T *) lua_touserdata(L, lua_upvalueindex(2));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
763 if (li == NULL) return 0;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
764 luaV_pushtypval(L, &li->li_tv);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
765 lua_pushlightuserdata(L, (void *) li->li_next);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
766 lua_replace(L, lua_upvalueindex(2));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
767 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
768 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
769
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
770 static int
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
771 luaV_list_call (lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
772 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
773 list_T *l = luaV_unbox(L, luaV_List, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
774 lua_pushvalue(L, lua_upvalueindex(1)); /* pass cache table along */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
775 lua_pushlightuserdata(L, (void *) l->lv_first);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
776 lua_pushcclosure(L, luaV_list_iter, 2);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
777 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
778 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
779
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
780 static int
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
781 luaV_list_index (lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
782 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
783 list_T *l = luaV_unbox(L, luaV_List, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
784 if (lua_isnumber(L, 2)) /* list item? */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
785 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
786 listitem_T *li = list_find(l, (long) luaL_checkinteger(L, 2));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
787 if (li == NULL)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
788 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
789 else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
790 luaV_pushtypval(L, &li->li_tv);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
791 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
792 else if (lua_isstring(L, 2)) /* method? */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
793 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
794 const char *s = lua_tostring(L, 2);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
795 if (strncmp(s, "add", 3) == 0
4293
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
796 || strncmp(s, "insert", 6) == 0)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
797 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
798 lua_getmetatable(L, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
799 lua_getfield(L, -1, s);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
800 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
801 else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
802 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
803 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
804 else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
805 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
806 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
807 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
808
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
809 static int
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
810 luaV_list_newindex (lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
811 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
812 list_T *l = luaV_unbox(L, luaV_List, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
813 long n = (long) luaL_checkinteger(L, 2);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
814 listitem_T *li;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
815 if (l->lv_lock)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
816 luaL_error(L, "list is locked");
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
817 li = list_find(l, n);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
818 if (li == NULL) return 0;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
819 if (lua_isnil(L, 3)) /* remove? */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
820 {
5871
b4ce0e1fb5a6 updated for version 7.4.278
Bram Moolenaar <bram@vim.org>
parents: 4293
diff changeset
821 vimlist_remove(l, li, li);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
822 clear_tv(&li->li_tv);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
823 vim_free(li);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
824 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
825 else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
826 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
827 typval_T v;
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
828 luaV_checktypval(L, 3, &v, "setting list item");
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
829 clear_tv(&li->li_tv);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
830 copy_tv(&v, &li->li_tv);
4293
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
831 clear_tv(&v);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
832 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
833 return 0;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
834 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
835
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
836 static int
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
837 luaV_list_add (lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
838 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
839 luaV_List *lis = luaV_checkudata(L, 1, LUAVIM_LIST);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
840 list_T *l = (list_T *) luaV_checkcache(L, (void *) *lis);
4293
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
841 typval_T v;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
842 if (l->lv_lock)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
843 luaL_error(L, "list is locked");
4293
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
844 lua_settop(L, 2);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
845 luaV_checktypval(L, 2, &v, "adding list item");
4293
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
846 if (list_append_tv(l, &v) == FAIL)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
847 {
4293
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
848 clear_tv(&v);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
849 luaL_error(L, "failed to add item to list");
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
850 }
4293
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
851 clear_tv(&v);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
852 lua_settop(L, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
853 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
854 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
855
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
856 static int
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
857 luaV_list_insert (lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
858 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
859 luaV_List *lis = luaV_checkudata(L, 1, LUAVIM_LIST);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
860 list_T *l = (list_T *) luaV_checkcache(L, (void *) *lis);
6625
199ce895e162 updated for version 7.4.638
Bram Moolenaar <bram@vim.org>
parents: 6590
diff changeset
861 long pos = (long) luaL_optinteger(L, 3, 0);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
862 listitem_T *li = NULL;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
863 typval_T v;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
864 if (l->lv_lock)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
865 luaL_error(L, "list is locked");
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
866 if (pos < l->lv_len)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
867 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
868 li = list_find(l, pos);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
869 if (li == NULL)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
870 luaL_error(L, "invalid position");
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
871 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
872 lua_settop(L, 2);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
873 luaV_checktypval(L, 2, &v, "inserting list item");
4293
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
874 if (list_insert_tv(l, &v, li) == FAIL)
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
875 {
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
876 clear_tv(&v);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
877 luaL_error(L, "failed to add item to list");
4293
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
878 }
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
879 clear_tv(&v);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
880 lua_settop(L, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
881 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
882 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
883
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
884 static const luaL_Reg luaV_List_mt[] = {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
885 {"__tostring", luaV_list_tostring},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
886 {"__len", luaV_list_len},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
887 {"__call", luaV_list_call},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
888 {"__index", luaV_list_index},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
889 {"__newindex", luaV_list_newindex},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
890 {"add", luaV_list_add},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
891 {"insert", luaV_list_insert},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
892 {NULL, NULL}
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
893 };
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
894
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
895
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
896 /* ======= Dict type ======= */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
897
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
898 static luaV_Dict *
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
899 luaV_newdict (lua_State *L, dict_T *dic)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
900 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
901 luaV_Dict *d = (luaV_Dict *) lua_newuserdata(L, sizeof(luaV_Dict));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
902 *d = dic;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
903 dic->dv_refcount++; /* reference in Lua */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
904 luaV_setudata(L, dic); /* cache[dic] = udata */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
905 luaV_getfield(L, LUAVIM_DICT);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
906 lua_setmetatable(L, -2);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
907 return d;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
908 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
909
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
910 luaV_pushtype(dict_T, dict, luaV_Dict)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
911 luaV_type_tostring(dict, LUAVIM_DICT)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
912
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
913 static int
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
914 luaV_dict_len (lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
915 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
916 dict_T *d = luaV_unbox(L, luaV_Dict, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
917 lua_pushinteger(L, (d == NULL) ? 0 : (int) d->dv_hashtab.ht_used);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
918 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
919 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
920
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
921 static int
4135
688da4d486a0 updated for version 7.3.820
Bram Moolenaar <bram@vim.org>
parents: 3865
diff changeset
922 luaV_dict_iter (lua_State *L UNUSED)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
923 {
4135
688da4d486a0 updated for version 7.3.820
Bram Moolenaar <bram@vim.org>
parents: 3865
diff changeset
924 #ifdef FEAT_EVAL
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
925 hashitem_T *hi = (hashitem_T *) lua_touserdata(L, lua_upvalueindex(2));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
926 int n = lua_tointeger(L, lua_upvalueindex(3));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
927 dictitem_T *di;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
928 if (n <= 0) return 0;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
929 while (HASHITEM_EMPTY(hi)) hi++;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
930 di = dict_lookup(hi);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
931 lua_pushstring(L, (char *) hi->hi_key);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
932 luaV_pushtypval(L, &di->di_tv);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
933 lua_pushlightuserdata(L, (void *) (hi + 1));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
934 lua_replace(L, lua_upvalueindex(2));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
935 lua_pushinteger(L, n - 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
936 lua_replace(L, lua_upvalueindex(3));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
937 return 2;
4135
688da4d486a0 updated for version 7.3.820
Bram Moolenaar <bram@vim.org>
parents: 3865
diff changeset
938 #else
688da4d486a0 updated for version 7.3.820
Bram Moolenaar <bram@vim.org>
parents: 3865
diff changeset
939 return 0;
688da4d486a0 updated for version 7.3.820
Bram Moolenaar <bram@vim.org>
parents: 3865
diff changeset
940 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
941 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
942
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
943 static int
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
944 luaV_dict_call (lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
945 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
946 dict_T *d = luaV_unbox(L, luaV_Dict, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
947 hashtab_T *ht = &d->dv_hashtab;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
948 lua_pushvalue(L, lua_upvalueindex(1)); /* pass cache table along */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
949 lua_pushlightuserdata(L, (void *) ht->ht_array);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
950 lua_pushinteger(L, ht->ht_used); /* # remaining items */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
951 lua_pushcclosure(L, luaV_dict_iter, 3);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
952 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
953 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
954
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
955 static int
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
956 luaV_dict_index(lua_State *L)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
957 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
958 dict_T *d = luaV_unbox(L, luaV_Dict, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
959 char_u *key = (char_u *) luaL_checkstring(L, 2);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
960 dictitem_T *di = dict_find(d, key, -1);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
961
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
962 if (di == NULL)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
963 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
964 else
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
965 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
966 luaV_pushtypval(L, &di->di_tv);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
967 if (di->di_tv.v_type == VAR_FUNC) /* funcref? */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
968 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
969 luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, -1);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
970 f->self = d; /* keep "self" reference */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
971 d->dv_refcount++;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
972 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
973 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
974 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
975 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
976
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
977 static int
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
978 luaV_dict_newindex(lua_State *L)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
979 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
980 dict_T *d = luaV_unbox(L, luaV_Dict, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
981 char_u *key = (char_u *) luaL_checkstring(L, 2);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
982 dictitem_T *di;
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
983 typval_T v;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
984 if (d->dv_lock)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
985 luaL_error(L, "dict is locked");
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
986 if (key == NULL)
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
987 return 0;
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
988 if (*key == NUL)
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
989 luaL_error(L, "empty key");
14335
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
990 if (!lua_isnil(L, 3)) /* read value? */
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
991 {
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
992 luaV_checktypval(L, 3, &v, "setting dict item");
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
993 if (d->dv_scope == VAR_DEF_SCOPE && v.v_type == VAR_FUNC)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
994 luaL_error(L, "cannot assign funcref to builtin scope");
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
995 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
996 di = dict_find(d, key, -1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
997 if (di == NULL) /* non-existing key? */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
998 {
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
999 if (lua_isnil(L, 3))
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1000 return 0;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1001 di = dictitem_alloc(key);
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1002 if (di == NULL)
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1003 return 0;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1004 if (dict_add(d, di) == FAIL)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1005 {
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1006 vim_free(di);
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1007 return 0;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1008 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1009 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1010 else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1011 clear_tv(&di->di_tv);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1012 if (lua_isnil(L, 3)) /* remove? */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1013 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1014 hashitem_T *hi = hash_find(&d->dv_hashtab, di->di_key);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1015 hash_remove(&d->dv_hashtab, hi);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1016 dictitem_free(di);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1017 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1018 else
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1019 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1020 copy_tv(&v, &di->di_tv);
4293
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
1021 clear_tv(&v);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1022 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1023 return 0;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1024 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1025
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1026 static const luaL_Reg luaV_Dict_mt[] = {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1027 {"__tostring", luaV_dict_tostring},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1028 {"__len", luaV_dict_len},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1029 {"__call", luaV_dict_call},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1030 {"__index", luaV_dict_index},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1031 {"__newindex", luaV_dict_newindex},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1032 {NULL, NULL}
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1033 };
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1034
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1035
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1036 /* ======= Funcref type ======= */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1037
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1038 static luaV_Funcref *
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1039 luaV_newfuncref(lua_State *L, char_u *name)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1040 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1041 luaV_Funcref *f = (luaV_Funcref *)lua_newuserdata(L, sizeof(luaV_Funcref));
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1042
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1043 if (name != NULL)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1044 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1045 func_ref(name); /* as in copy_tv */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1046 f->tv.vval.v_string = vim_strsave(name);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1047 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1048 f->tv.v_type = VAR_FUNC;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1049 f->args.v_type = VAR_LIST;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1050 f->self = NULL;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1051 luaV_getfield(L, LUAVIM_FUNCREF);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1052 lua_setmetatable(L, -2);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1053 return f;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1054 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1055
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1056 static luaV_Funcref *
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1057 luaV_pushfuncref(lua_State *L, typval_T *tv)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1058 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1059 luaV_Funcref *f = luaV_newfuncref(L, NULL);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1060 copy_tv(tv, &f->tv);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1061 clear_tv(tv);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1062 return f;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1063 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1064
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1065
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1066 luaV_type_tostring(funcref, LUAVIM_FUNCREF)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1067
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1068 static int
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1069 luaV_funcref_gc(lua_State *L)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1070 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1071 luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, 1);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1072
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1073 func_unref(f->tv.vval.v_string);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1074 vim_free(f->tv.vval.v_string);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1075 dict_unref(f->self);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1076 return 0;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1077 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1078
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1079 /* equivalent to string(funcref) */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1080 static int
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1081 luaV_funcref_len(lua_State *L)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1082 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1083 luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, 1);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1084
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1085 lua_pushstring(L, (const char *) f->tv.vval.v_string);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1086 return 1;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1087 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1088
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1089 static int
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1090 luaV_funcref_call(lua_State *L)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1091 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1092 luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, 1);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1093 int i, n = lua_gettop(L) - 1; /* #args */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1094 int status;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1095 typval_T v, rettv;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1096
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1097 f->args.vval.v_list = list_alloc();
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1098 rettv.v_type = VAR_UNKNOWN; /* as in clear_tv */
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1099 if (f->args.vval.v_list == NULL)
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1100 status = FAIL;
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1101 else
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1102 {
14335
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
1103 for (i = 0; i < n; i++)
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
1104 {
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1105 luaV_checktypval(L, i + 2, &v, "calling funcref");
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1106 list_append_tv(f->args.vval.v_list, &v);
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1107 }
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1108 status = func_call(f->tv.vval.v_string, &f->args,
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1109 NULL, f->self, &rettv);
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1110 if (status == OK)
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1111 luaV_pushtypval(L, &rettv);
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1112 clear_tv(&f->args);
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1113 clear_tv(&rettv);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1114 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1115 if (status != OK)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1116 luaL_error(L, "cannot call funcref");
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1117 return 1;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1118 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1119
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1120 static const luaL_Reg luaV_Funcref_mt[] = {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1121 {"__tostring", luaV_funcref_tostring},
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1122 {"__gc", luaV_funcref_gc},
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1123 {"__len", luaV_funcref_len},
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1124 {"__call", luaV_funcref_call},
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1125 {NULL, NULL}
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1126 };
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1127
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1128
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1129 /* ======= Buffer type ======= */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1130
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1131 luaV_newtype(buf_T, buffer, luaV_Buffer, LUAVIM_BUFFER)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1132 luaV_pushtype(buf_T, buffer, luaV_Buffer)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1133 luaV_type_tostring(buffer, LUAVIM_BUFFER)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1134
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1135 static int
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1136 luaV_buffer_len(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1137 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1138 buf_T *b = (buf_T *) luaV_checkvalid(L, luaV_Buffer, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1139 lua_pushinteger(L, b->b_ml.ml_line_count);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1140 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1141 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1142
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1143 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1144 luaV_buffer_call(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1145 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1146 buf_T *b = (buf_T *) luaV_checkvalid(L, luaV_Buffer, 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1147 lua_settop(L, 1);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1148 set_curbuf(b, DOBUF_SPLIT);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1149 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1150 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1151
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1152 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1153 luaV_buffer_index(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1154 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1155 buf_T *b = (buf_T *) luaV_checkvalid(L, luaV_Buffer, 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1156 linenr_T n = (linenr_T) lua_tointeger(L, 2);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1157 if (n > 0 && n <= b->b_ml.ml_line_count)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1158 luaV_pushline(L, b, n);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1159 else if (lua_isstring(L, 2))
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1160 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1161 const char *s = lua_tostring(L, 2);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1162 if (strncmp(s, "name", 4) == 0)
14296
396b71b242b2 patch 8.1.0164: luaeval('vim.buffer().name') returns an error
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
1163 lua_pushstring(L, (b->b_sfname == NULL)
396b71b242b2 patch 8.1.0164: luaeval('vim.buffer().name') returns an error
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
1164 ? "" : (char *) b->b_sfname);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1165 else if (strncmp(s, "fname", 5) == 0)
14296
396b71b242b2 patch 8.1.0164: luaeval('vim.buffer().name') returns an error
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
1166 lua_pushstring(L, (b->b_ffname == NULL)
396b71b242b2 patch 8.1.0164: luaeval('vim.buffer().name') returns an error
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
1167 ? "" : (char *) b->b_ffname);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1168 else if (strncmp(s, "number", 6) == 0)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1169 lua_pushinteger(L, b->b_fnum);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1170 /* methods */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1171 else if (strncmp(s, "insert", 6) == 0
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1172 || strncmp(s, "next", 4) == 0
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1173 || strncmp(s, "previous", 8) == 0
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1174 || strncmp(s, "isvalid", 7) == 0)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1175 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1176 lua_getmetatable(L, 1);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1177 lua_getfield(L, -1, s);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1178 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1179 else
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1180 lua_pushnil(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1181 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1182 else
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1183 lua_pushnil(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1184 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1185 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1186
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1187 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1188 luaV_buffer_newindex(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1189 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1190 buf_T *b = (buf_T *) luaV_checkvalid(L, luaV_Buffer, 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1191 linenr_T n = (linenr_T) luaL_checkinteger(L, 2);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1192 #ifdef HAVE_SANDBOX
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1193 luaV_checksandbox(L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1194 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1195 if (n < 1 || n > b->b_ml.ml_line_count)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1196 luaL_error(L, "invalid line number");
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1197 if (lua_isnil(L, 3)) /* delete line */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1198 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1199 buf_T *buf = curbuf;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1200 curbuf = b;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1201 if (u_savedel(n, 1L) == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1202 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1203 curbuf = buf;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1204 luaL_error(L, "cannot save undo information");
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1205 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1206 else if (ml_delete(n, FALSE) == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1207 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1208 curbuf = buf;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1209 luaL_error(L, "cannot delete line");
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1210 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1211 else
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1212 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1213 deleted_lines_mark(n, 1L);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1214 if (b == curwin->w_buffer) /* fix cursor in current window? */
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1215 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1216 if (curwin->w_cursor.lnum >= n)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1217 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1218 if (curwin->w_cursor.lnum > n)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1219 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1220 curwin->w_cursor.lnum -= 1;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1221 check_cursor_col();
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1222 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1223 else check_cursor();
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1224 changed_cline_bef_curs();
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1225 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1226 invalidate_botline();
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1227 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1228 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1229 curbuf = buf;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1230 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1231 else if (lua_isstring(L, 3)) /* update line */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1232 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1233 buf_T *buf = curbuf;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1234 curbuf = b;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1235 if (u_savesub(n) == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1236 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1237 curbuf = buf;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1238 luaL_error(L, "cannot save undo information");
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1239 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1240 else if (ml_replace(n, luaV_toline(L, 3), TRUE) == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1241 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1242 curbuf = buf;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1243 luaL_error(L, "cannot replace line");
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1244 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1245 else changed_bytes(n, 0);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1246 curbuf = buf;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1247 if (b == curwin->w_buffer)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1248 check_cursor_col();
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1249 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1250 else
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1251 luaL_error(L, "wrong argument to change line");
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1252 return 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1253 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1254
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1255 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1256 luaV_buffer_insert(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1257 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1258 luaV_Buffer *lb = luaV_checkudata(L, 1, LUAVIM_BUFFER);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1259 buf_T *b = (buf_T *) luaV_checkcache(L, (void *) *lb);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1260 linenr_T last = b->b_ml.ml_line_count;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1261 linenr_T n = (linenr_T) luaL_optinteger(L, 3, last);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1262 buf_T *buf;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1263 luaL_checktype(L, 2, LUA_TSTRING);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1264 #ifdef HAVE_SANDBOX
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1265 luaV_checksandbox(L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1266 #endif
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1267 /* fix insertion line */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1268 if (n < 0) n = 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1269 if (n > last) n = last;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1270 /* insert */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1271 buf = curbuf;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1272 curbuf = b;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1273 if (u_save(n, n + 1) == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1274 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1275 curbuf = buf;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1276 luaL_error(L, "cannot save undo information");
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1277 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1278 else if (ml_append(n, luaV_toline(L, 2), 0, FALSE) == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1279 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1280 curbuf = buf;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1281 luaL_error(L, "cannot insert line");
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1282 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1283 else
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1284 appended_lines_mark(n, 1L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1285 curbuf = buf;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1286 update_screen(VALID);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1287 return 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1288 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1289
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1290 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1291 luaV_buffer_next(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1292 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1293 luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1294 buf_T *buf = (buf_T *) luaV_checkcache(L, (void *) *b);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1295 luaV_pushbuffer(L, buf->b_next);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1296 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1297 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1298
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1299 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1300 luaV_buffer_previous(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1301 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1302 luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1303 buf_T *buf = (buf_T *) luaV_checkcache(L, (void *) *b);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1304 luaV_pushbuffer(L, buf->b_prev);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1305 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1306 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1307
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1308 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1309 luaV_buffer_isvalid(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1310 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1311 luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1312 luaV_getudata(L, *b);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1313 lua_pushboolean(L, !lua_isnil(L, -1));
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1314 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1315 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1316
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1317 static const luaL_Reg luaV_Buffer_mt[] = {
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1318 {"__tostring", luaV_buffer_tostring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1319 {"__len", luaV_buffer_len},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1320 {"__call", luaV_buffer_call},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1321 {"__index", luaV_buffer_index},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1322 {"__newindex", luaV_buffer_newindex},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1323 {"insert", luaV_buffer_insert},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1324 {"next", luaV_buffer_next},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1325 {"previous", luaV_buffer_previous},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1326 {"isvalid", luaV_buffer_isvalid},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1327 {NULL, NULL}
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1328 };
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1329
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1330
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1331 /* ======= Window type ======= */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1332
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1333 luaV_newtype(win_T, window, luaV_Window, LUAVIM_WINDOW)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1334 luaV_pushtype(win_T, window, luaV_Window)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1335 luaV_type_tostring(window, LUAVIM_WINDOW)
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1336
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1337 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1338 luaV_window_call(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1339 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1340 win_T *w = (win_T *) luaV_checkvalid(L, luaV_Window, 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1341 lua_settop(L, 1);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1342 win_goto(w);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1343 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1344 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1345
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1346 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1347 luaV_window_index(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1348 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1349 win_T *w = (win_T *) luaV_checkvalid(L, luaV_Window, 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1350 const char *s = luaL_checkstring(L, 2);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1351 if (strncmp(s, "buffer", 6) == 0)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1352 luaV_pushbuffer(L, w->w_buffer);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1353 else if (strncmp(s, "line", 4) == 0)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1354 lua_pushinteger(L, w->w_cursor.lnum);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1355 else if (strncmp(s, "col", 3) == 0)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1356 lua_pushinteger(L, w->w_cursor.col + 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1357 else if (strncmp(s, "width", 5) == 0)
12515
972ea22c946f patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents: 12477
diff changeset
1358 lua_pushinteger(L, w->w_width);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1359 else if (strncmp(s, "height", 6) == 0)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1360 lua_pushinteger(L, w->w_height);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1361 /* methods */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1362 else if (strncmp(s, "next", 4) == 0
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1363 || strncmp(s, "previous", 8) == 0
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1364 || strncmp(s, "isvalid", 7) == 0)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1365 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1366 lua_getmetatable(L, 1);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1367 lua_getfield(L, -1, s);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1368 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1369 else
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1370 lua_pushnil(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1371 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1372 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1373
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1374 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1375 luaV_window_newindex (lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1376 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1377 win_T *w = (win_T *) luaV_checkvalid(L, luaV_Window, 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1378 const char *s = luaL_checkstring(L, 2);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1379 int v = luaL_checkinteger(L, 3);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1380 if (strncmp(s, "line", 4) == 0)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1381 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1382 #ifdef HAVE_SANDBOX
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1383 luaV_checksandbox(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1384 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1385 if (v < 1 || v > w->w_buffer->b_ml.ml_line_count)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1386 luaL_error(L, "line out of range");
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1387 w->w_cursor.lnum = v;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1388 update_screen(VALID);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1389 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1390 else if (strncmp(s, "col", 3) == 0)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1391 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1392 #ifdef HAVE_SANDBOX
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1393 luaV_checksandbox(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1394 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1395 w->w_cursor.col = v - 1;
14395
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 14335
diff changeset
1396 w->w_set_curswant = TRUE;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1397 update_screen(VALID);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1398 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1399 else if (strncmp(s, "width", 5) == 0)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1400 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1401 win_T *win = curwin;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1402 #ifdef FEAT_GUI
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1403 need_mouse_correct = TRUE;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1404 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1405 curwin = w;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1406 win_setwidth(v);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1407 curwin = win;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1408 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1409 else if (strncmp(s, "height", 6) == 0)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1410 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1411 win_T *win = curwin;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1412 #ifdef FEAT_GUI
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1413 need_mouse_correct = TRUE;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1414 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1415 curwin = w;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1416 win_setheight(v);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1417 curwin = win;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1418 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1419 else
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1420 luaL_error(L, "invalid window property: `%s'", s);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1421 return 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1422 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1423
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1424 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1425 luaV_window_next(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1426 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1427 luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1428 win_T *win = (win_T *) luaV_checkcache(L, (void *) *w);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1429 luaV_pushwindow(L, win->w_next);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1430 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1431 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1432
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1433 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1434 luaV_window_previous(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1435 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1436 luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1437 win_T *win = (win_T *) luaV_checkcache(L, (void *) *w);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1438 luaV_pushwindow(L, win->w_prev);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1439 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1440 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1441
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1442 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1443 luaV_window_isvalid(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1444 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1445 luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1446 luaV_getudata(L, *w);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1447 lua_pushboolean(L, !lua_isnil(L, -1));
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1448 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1449 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1450
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1451 static const luaL_Reg luaV_Window_mt[] = {
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1452 {"__tostring", luaV_window_tostring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1453 {"__call", luaV_window_call},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1454 {"__index", luaV_window_index},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1455 {"__newindex", luaV_window_newindex},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1456 {"next", luaV_window_next},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1457 {"previous", luaV_window_previous},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1458 {"isvalid", luaV_window_isvalid},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1459 {NULL, NULL}
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1460 };
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1461
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1462
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1463 /* ======= Vim module ======= */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1464
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1465 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1466 luaV_print(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1467 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1468 int i, n = lua_gettop(L); /* nargs */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1469 const char *s;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1470 size_t l;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1471 luaL_Buffer b;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1472 luaL_buffinit(L, &b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1473 lua_getglobal(L, "tostring");
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1474 for (i = 1; i <= n; i++)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1475 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1476 lua_pushvalue(L, -1); /* tostring */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1477 lua_pushvalue(L, i); /* arg */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1478 lua_call(L, 1, 1);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1479 s = lua_tolstring(L, -1, &l);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1480 if (s == NULL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1481 return luaL_error(L, "cannot convert to string");
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1482 if (i > 1) luaL_addchar(&b, ' '); /* use space instead of tab */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1483 luaV_addlstring(&b, s, l, 0);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1484 lua_pop(L, 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1485 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1486 luaL_pushresult(&b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1487 luaV_msg(L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1488 return 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1489 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1490
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1491 static int
3091
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1492 luaV_debug(lua_State *L)
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1493 {
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1494 lua_settop(L, 0);
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1495 lua_getglobal(L, "vim");
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1496 lua_getfield(L, -1, "eval");
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1497 lua_remove(L, -2); /* vim.eval at position 1 */
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1498 for (;;)
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1499 {
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1500 const char *input;
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1501 size_t l;
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1502 lua_pushvalue(L, 1); /* vim.eval */
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1503 lua_pushliteral(L, "input('lua_debug> ')");
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1504 lua_call(L, 1, 1); /* return string */
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1505 input = lua_tolstring(L, -1, &l);
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1506 if (l == 0 || strcmp(input, "cont") == 0)
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1507 return 0;
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1508 msg_putchar('\n'); /* avoid outputting on input line */
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1509 if (luaL_loadbuffer(L, input, l, "=(debug command)")
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1510 || lua_pcall(L, 0, 0, 0))
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1511 luaV_emsg(L);
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1512 lua_settop(L, 1); /* remove eventual returns, but keep vim.eval */
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1513 }
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1514 }
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1515
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1516 static int
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1517 luaV_command(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1518 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1519 do_cmdline_cmd((char_u *) luaL_checkstring(L, 1));
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1520 update_screen(VALID);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1521 return 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1522 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1523
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1524 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1525 luaV_eval(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1526 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1527 typval_T *tv = eval_expr((char_u *) luaL_checkstring(L, 1), NULL);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1528 if (tv == NULL) luaL_error(L, "invalid expression");
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1529 luaV_pushtypval(L, tv);
4293
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
1530 free_tv(tv);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1531 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1532 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1533
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1534 static int
2331
3840b7508835 Make it easier to build with Lua. Remove compiler warnings.
Bram Moolenaar <bram@vim.org>
parents: 2330
diff changeset
1535 luaV_beep(lua_State *L UNUSED)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1536 {
6949
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6887
diff changeset
1537 vim_beep(BO_LANG);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1538 return 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1539 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1540
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1541 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1542 luaV_line(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1543 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1544 luaV_pushline(L, curbuf, curwin->w_cursor.lnum);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1545 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1546 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1547
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1548 static int
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1549 luaV_list(lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1550 {
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1551 list_T *l;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1552 int initarg = !lua_isnoneornil(L, 1);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1553
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1554 if (initarg && lua_type(L, 1) != LUA_TTABLE)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1555 luaL_error(L, "table expected, got %s", luaL_typename(L, 1));
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1556 l = list_alloc();
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1557 if (l == NULL)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1558 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1559 else
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1560 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1561 luaV_newlist(L, l);
14335
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
1562 if (initarg) /* traverse table to init list */
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
1563 {
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1564 int notnil, i = 0;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1565 typval_T v;
14335
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
1566 do
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
1567 {
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1568 lua_rawgeti(L, 1, ++i);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1569 notnil = !lua_isnil(L, -1);
14335
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
1570 if (notnil)
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
1571 {
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1572 luaV_checktypval(L, -1, &v, "vim.list");
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1573 list_append_tv(l, &v);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1574 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1575 lua_pop(L, 1); /* value */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1576 } while (notnil);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1577 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1578 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1579 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1580 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1581
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1582 static int
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1583 luaV_dict(lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1584 {
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1585 dict_T *d;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1586 int initarg = !lua_isnoneornil(L, 1);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1587
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1588 if (initarg && lua_type(L, 1) != LUA_TTABLE)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1589 luaL_error(L, "table expected, got %s", luaL_typename(L, 1));
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1590 d = dict_alloc();
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1591 if (d == NULL)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1592 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1593 else
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1594 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1595 luaV_newdict(L, d);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1596 if (initarg) /* traverse table to init dict */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1597 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1598 lua_pushnil(L);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1599 while (lua_next(L, 1))
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1600 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1601 char_u *key;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1602 dictitem_T *di;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1603 typval_T v;
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1604
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1605 lua_pushvalue(L, -2); /* dup key in case it's a number */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1606 key = (char_u *) lua_tostring(L, -1);
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1607 if (key == NULL)
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1608 {
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1609 lua_pushnil(L);
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1610 return 1;
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1611 }
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1612 if (*key == NUL)
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1613 luaL_error(L, "table has empty key");
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1614 luaV_checktypval(L, -2, &v, "vim.dict"); /* value */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1615 di = dictitem_alloc(key);
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1616 if (di == NULL || dict_add(d, di) == FAIL)
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1617 {
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1618 vim_free(di);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1619 lua_pushnil(L);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1620 return 1;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1621 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1622 copy_tv(&v, &di->di_tv);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1623 clear_tv(&v);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1624 lua_pop(L, 2); /* key copy and value */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1625 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1626 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1627 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1628 return 1;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1629 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1630
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1631 static int
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1632 luaV_funcref(lua_State *L)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1633 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1634 const char *name = luaL_checkstring(L, 1);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1635 /* note: not checking if function exists (needs function_exists) */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1636 if (name == NULL || *name == NUL || VIM_ISDIGIT(*name))
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1637 luaL_error(L, "invalid function name: %s", name);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1638 luaV_newfuncref(L, (char_u *) name);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1639 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1640 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1641
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1642 static int
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1643 luaV_buffer(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1644 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1645 buf_T *buf;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1646 if (lua_isstring(L, 1)) /* get by number or name? */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1647 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1648 if (lua_isnumber(L, 1)) /* by number? */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1649 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1650 int n = lua_tointeger(L, 1);
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
1651 FOR_ALL_BUFFERS(buf)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1652 if (buf->b_fnum == n) break;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1653 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1654 else // by name
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1655 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1656 size_t l;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1657 const char *s = lua_tolstring(L, 1, &l);
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
1658 FOR_ALL_BUFFERS(buf)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1659 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1660 if (buf->b_ffname == NULL || buf->b_sfname == NULL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1661 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1662 if (l == 0) break;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1663 }
2331
3840b7508835 Make it easier to build with Lua. Remove compiler warnings.
Bram Moolenaar <bram@vim.org>
parents: 2330
diff changeset
1664 else if (strncmp(s, (char *)buf->b_ffname, l) == 0
3840b7508835 Make it easier to build with Lua. Remove compiler warnings.
Bram Moolenaar <bram@vim.org>
parents: 2330
diff changeset
1665 || strncmp(s, (char *)buf->b_sfname, l) == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1666 break;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1667 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1668 }
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1669 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1670 else
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1671 buf = (lua_toboolean(L, 1)) ? firstbuf : curbuf; /* first buffer? */
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1672 luaV_pushbuffer(L, buf);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1673 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1674 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1675
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1676 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1677 luaV_window(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1678 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1679 win_T *win;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1680 if (lua_isnumber(L, 1)) /* get by number? */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1681 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1682 int n = lua_tointeger(L, 1);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1683 for (win = firstwin; win != NULL; win = win->w_next, n--)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1684 if (n == 1) break;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1685 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1686 else
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1687 win = (lua_toboolean(L, 1)) ? firstwin : curwin; /* first window? */
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1688 luaV_pushwindow(L, win);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1689 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1690 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1691
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1692 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1693 luaV_open(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1694 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1695 char_u *s = NULL;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1696 #ifdef HAVE_SANDBOX
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1697 luaV_checksandbox(L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1698 #endif
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1699 if (lua_isstring(L, 1)) s = (char_u *) lua_tostring(L, 1);
3200
3801e4811b0e updated for version 7.3.370
Bram Moolenaar <bram@vim.org>
parents: 3091
diff changeset
1700 luaV_pushbuffer(L, buflist_new(s, NULL, 1L, BLN_LISTED));
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1701 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1702 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1703
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1704 static int
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1705 luaV_type(lua_State *L)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1706 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1707 luaL_checkany(L, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1708 if (lua_type(L, 1) == LUA_TUSERDATA) /* check vim udata? */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1709 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1710 lua_settop(L, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1711 if (lua_getmetatable(L, 1))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1712 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1713 luaV_getfield(L, LUAVIM_LIST);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1714 if (lua_rawequal(L, -1, 2))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1715 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1716 lua_pushstring(L, "list");
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1717 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1718 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1719 luaV_getfield(L, LUAVIM_DICT);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1720 if (lua_rawequal(L, -1, 2))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1721 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1722 lua_pushstring(L, "dict");
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1723 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1724 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1725 luaV_getfield(L, LUAVIM_FUNCREF);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1726 if (lua_rawequal(L, -1, 2))
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1727 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1728 lua_pushstring(L, "funcref");
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1729 return 1;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1730 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1731 luaV_getfield(L, LUAVIM_BUFFER);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1732 if (lua_rawequal(L, -1, 2))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1733 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1734 lua_pushstring(L, "buffer");
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1735 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1736 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1737 luaV_getfield(L, LUAVIM_WINDOW);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1738 if (lua_rawequal(L, -1, 2))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1739 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1740 lua_pushstring(L, "window");
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1741 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1742 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1743 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1744 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1745 lua_pushstring(L, luaL_typename(L, 1)); /* fallback */
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1746 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1747 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1748
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1749 static const luaL_Reg luaV_module[] = {
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1750 {"command", luaV_command},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1751 {"eval", luaV_eval},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1752 {"beep", luaV_beep},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1753 {"line", luaV_line},
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1754 {"list", luaV_list},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1755 {"dict", luaV_dict},
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1756 {"funcref", luaV_funcref},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1757 {"buffer", luaV_buffer},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1758 {"window", luaV_window},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1759 {"open", luaV_open},
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1760 {"type", luaV_type},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1761 {NULL, NULL}
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1762 };
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1763
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1764 /* for freeing list, dict, buffer and window objects; lightuserdata as arg */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1765 static int
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1766 luaV_free(lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1767 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1768 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1769 luaV_setudata(L, lua_touserdata(L, 1));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1770 return 0;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1771 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1772
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1773 static int
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1774 luaV_luaeval (lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1775 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1776 luaL_Buffer b;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1777 size_t l;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1778 const char *str = lua_tolstring(L, 1, &l);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1779 typval_T *arg = (typval_T *) lua_touserdata(L, 2);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1780 typval_T *rettv = (typval_T *) lua_touserdata(L, 3);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1781 luaL_buffinit(L, &b);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1782 luaL_addlstring(&b, LUAVIM_EVALHEADER, sizeof(LUAVIM_EVALHEADER) - 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1783 luaL_addlstring(&b, str, l);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1784 luaL_pushresult(&b);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1785 str = lua_tolstring(L, -1, &l);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1786 if (luaL_loadbuffer(L, str, l, LUAVIM_EVALNAME)) /* compile error? */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1787 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1788 luaV_emsg(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1789 return 0;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1790 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1791 luaV_pushtypval(L, arg);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1792 if (lua_pcall(L, 1, 1, 0)) /* running error? */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1793 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1794 luaV_emsg(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1795 return 0;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1796 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1797 if (luaV_totypval(L, -1, rettv) == FAIL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15328
diff changeset
1798 emsg("luaeval: cannot convert value");
6590
f884a1140a0a updated for version 7.4.621
Bram Moolenaar <bram@vim.org>
parents: 6586
diff changeset
1799 return 0;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1800 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1801
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1802 static int
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1803 luaV_setref (lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1804 {
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
1805 int copyID = lua_tointeger(L, 1);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
1806 int abort = FALSE;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
1807 typval_T tv;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
1808
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1809 luaV_getfield(L, LUAVIM_LIST);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1810 luaV_getfield(L, LUAVIM_DICT);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1811 lua_pushnil(L);
6586
9ac723b9f54d updated for version 7.4.619
Bram Moolenaar <bram@vim.org>
parents: 6584
diff changeset
1812 /* traverse cache table */
9ac723b9f54d updated for version 7.4.619
Bram Moolenaar <bram@vim.org>
parents: 6584
diff changeset
1813 while (!abort && lua_next(L, lua_upvalueindex(1)) != 0)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1814 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1815 lua_getmetatable(L, -1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1816 if (lua_rawequal(L, -1, 2)) /* list? */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1817 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1818 tv.v_type = VAR_LIST;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1819 tv.vval.v_list = (list_T *) lua_touserdata(L, 4); /* key */
7297
67c7a524b84f commit https://github.com/vim/vim/commit/f609dcf8c1094f6fc95f4fc36321a1fb08a7110c
Christian Brabandt <cb@256bit.org>
parents: 7196
diff changeset
1820 abort = set_ref_in_item(&tv, copyID, NULL, NULL);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1821 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1822 else if (lua_rawequal(L, -1, 3)) /* dict? */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1823 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1824 tv.v_type = VAR_DICT;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1825 tv.vval.v_dict = (dict_T *) lua_touserdata(L, 4); /* key */
7297
67c7a524b84f commit https://github.com/vim/vim/commit/f609dcf8c1094f6fc95f4fc36321a1fb08a7110c
Christian Brabandt <cb@256bit.org>
parents: 7196
diff changeset
1826 abort = set_ref_in_item(&tv, copyID, NULL, NULL);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1827 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1828 lua_pop(L, 2); /* metatable and value */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1829 }
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
1830 lua_pushinteger(L, abort);
6590
f884a1140a0a updated for version 7.4.621
Bram Moolenaar <bram@vim.org>
parents: 6586
diff changeset
1831 return 1;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1832 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1833
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1834 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1835 luaopen_vim(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1836 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1837 /* set cache table */
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1838 lua_newtable(L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1839 lua_newtable(L);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1840 lua_pushstring(L, "v");
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1841 lua_setfield(L, -2, "__mode");
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1842 lua_setmetatable(L, -2); /* cache is weak-valued */
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1843 /* print */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1844 lua_pushcfunction(L, luaV_print);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1845 lua_setglobal(L, "print");
3091
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1846 /* debug.debug */
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1847 lua_getglobal(L, "debug");
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1848 lua_pushcfunction(L, luaV_debug);
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1849 lua_setfield(L, -2, "debug");
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1850 lua_pop(L, 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1851 /* free */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1852 lua_pushlightuserdata(L, (void *) LUAVIM_FREE);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1853 lua_pushvalue(L, 1); /* cache table */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1854 lua_pushcclosure(L, luaV_free, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1855 lua_rawset(L, LUA_REGISTRYINDEX);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1856 /* luaeval */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1857 lua_pushlightuserdata(L, (void *) LUAVIM_LUAEVAL);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1858 lua_pushvalue(L, 1); /* cache table */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1859 lua_pushcclosure(L, luaV_luaeval, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1860 lua_rawset(L, LUA_REGISTRYINDEX);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1861 /* setref */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1862 lua_pushlightuserdata(L, (void *) LUAVIM_SETREF);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1863 lua_pushvalue(L, 1); /* cache table */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1864 lua_pushcclosure(L, luaV_setref, 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1865 lua_rawset(L, LUA_REGISTRYINDEX);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1866 /* register */
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1867 luaV_newmetatable(L, LUAVIM_LIST);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1868 lua_pushvalue(L, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1869 luaV_openlib(L, luaV_List_mt, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1870 luaV_newmetatable(L, LUAVIM_DICT);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1871 lua_pushvalue(L, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1872 luaV_openlib(L, luaV_Dict_mt, 1);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1873 luaV_newmetatable(L, LUAVIM_FUNCREF);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1874 lua_pushvalue(L, 1);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1875 luaV_openlib(L, luaV_Funcref_mt, 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1876 luaV_newmetatable(L, LUAVIM_BUFFER);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1877 lua_pushvalue(L, 1); /* cache table */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1878 luaV_openlib(L, luaV_Buffer_mt, 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1879 luaV_newmetatable(L, LUAVIM_WINDOW);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1880 lua_pushvalue(L, 1); /* cache table */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1881 luaV_openlib(L, luaV_Window_mt, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1882 lua_newtable(L); /* vim table */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1883 lua_pushvalue(L, 1); /* cache table */
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1884 luaV_openlib(L, luaV_module, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1885 lua_setglobal(L, LUAVIM_NAME);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1886 return 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1887 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1888
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1889 static lua_State *
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1890 luaV_newstate(void)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1891 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1892 lua_State *L = luaL_newstate();
2431
7b764999f9b9 Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2373
diff changeset
1893 luaL_openlibs(L); /* core libs */
7b764999f9b9 Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2373
diff changeset
1894 lua_pushcfunction(L, luaopen_vim); /* vim */
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1895 lua_call(L, 0, 0);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1896 return L;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1897 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1898
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1899 static void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1900 luaV_setrange(lua_State *L, int line1, int line2)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1901 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1902 lua_getglobal(L, LUAVIM_NAME);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1903 lua_pushinteger(L, line1);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1904 lua_setfield(L, -2, "firstline");
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1905 lua_pushinteger(L, line2);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1906 lua_setfield(L, -2, "lastline");
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1907 lua_pop(L, 1); /* vim table */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1908 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1909
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1910
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1911 /* ======= Interface ======= */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1912
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1913 static lua_State *L = NULL;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1914
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1915 static int
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1916 lua_isopen(void)
2543
8c512e2c7cb5 Fix: Lua interface tried to load the library when closing a buffer or window.
Bram Moolenaar <bram@vim.org>
parents: 2431
diff changeset
1917 {
8c512e2c7cb5 Fix: Lua interface tried to load the library when closing a buffer or window.
Bram Moolenaar <bram@vim.org>
parents: 2431
diff changeset
1918 return L != NULL;
8c512e2c7cb5 Fix: Lua interface tried to load the library when closing a buffer or window.
Bram Moolenaar <bram@vim.org>
parents: 2431
diff changeset
1919 }
8c512e2c7cb5 Fix: Lua interface tried to load the library when closing a buffer or window.
Bram Moolenaar <bram@vim.org>
parents: 2431
diff changeset
1920
8c512e2c7cb5 Fix: Lua interface tried to load the library when closing a buffer or window.
Bram Moolenaar <bram@vim.org>
parents: 2431
diff changeset
1921 static int
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1922 lua_init(void)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1923 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1924 if (!lua_isopen())
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1925 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1926 #ifdef DYNAMIC_LUA
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1927 if (!lua_enabled(TRUE))
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1928 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15328
diff changeset
1929 emsg(_("Lua library cannot be loaded."));
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1930 return FAIL;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1931 }
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1932 #endif
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1933 L = luaV_newstate();
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1934 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1935 return OK;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1936 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1937
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1938 void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1939 lua_end(void)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1940 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1941 if (lua_isopen())
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1942 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1943 lua_close(L);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1944 L = NULL;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1945 #ifdef DYNAMIC_LUA
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1946 end_dynamic_lua();
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1947 #endif
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1948 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1949 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1950
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1951 /* ex commands */
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1952 void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1953 ex_lua(exarg_T *eap)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1954 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1955 char *script;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1956 if (lua_init() == FAIL) return;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1957 script = (char *) script_get(eap, eap->arg);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1958 if (!eap->skip)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1959 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1960 char *s = (script) ? script : (char *) eap->arg;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1961 luaV_setrange(L, eap->line1, eap->line2);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1962 if (luaL_loadbuffer(L, s, strlen(s), LUAVIM_CHUNKNAME)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1963 || lua_pcall(L, 0, 0, 0))
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1964 luaV_emsg(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1965 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1966 if (script != NULL) vim_free(script);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1967 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1968
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1969 void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1970 ex_luado(exarg_T *eap)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1971 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1972 linenr_T l;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1973 const char *s = (const char *) eap->arg;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1974 luaL_Buffer b;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1975 size_t len;
10757
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10025
diff changeset
1976 buf_T *was_curbuf = curbuf;
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10025
diff changeset
1977
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1978 if (lua_init() == FAIL) return;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1979 if (u_save(eap->line1 - 1, eap->line2 + 1) == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1980 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15328
diff changeset
1981 emsg(_("cannot save undo information"));
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1982 return;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1983 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1984 luaV_setrange(L, eap->line1, eap->line2);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1985 luaL_buffinit(L, &b);
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
1986 luaL_addlstring(&b, "return function(line, linenr) ", 30); /* header */
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1987 luaL_addlstring(&b, s, strlen(s));
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1988 luaL_addlstring(&b, " end", 4); /* footer */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1989 luaL_pushresult(&b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1990 s = lua_tolstring(L, -1, &len);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1991 if (luaL_loadbuffer(L, s, len, LUAVIM_CHUNKNAME))
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1992 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1993 luaV_emsg(L);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1994 lua_pop(L, 1); /* function body */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1995 return;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1996 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1997 lua_call(L, 0, 1);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1998 lua_replace(L, -2); /* function -> body */
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1999 for (l = eap->line1; l <= eap->line2; l++)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2000 {
10757
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10025
diff changeset
2001 /* Check the line number, the command my have deleted lines. */
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10025
diff changeset
2002 if (l > curbuf->b_ml.ml_line_count)
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10025
diff changeset
2003 break;
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10025
diff changeset
2004
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2005 lua_pushvalue(L, -1); /* function */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2006 luaV_pushline(L, curbuf, l); /* current line as arg */
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
2007 lua_pushinteger(L, l); /* current line number as arg */
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
2008 if (lua_pcall(L, 2, 1, 0))
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2009 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2010 luaV_emsg(L);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2011 break;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2012 }
10757
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10025
diff changeset
2013 /* Catch the command switching to another buffer. */
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10025
diff changeset
2014 if (curbuf != was_curbuf)
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10025
diff changeset
2015 break;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2016 if (lua_isstring(L, -1)) /* update line? */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2017 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2018 #ifdef HAVE_SANDBOX
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2019 luaV_checksandbox(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2020 #endif
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2021 ml_replace(l, luaV_toline(L, -1), TRUE);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2022 changed_bytes(l, 0);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2023 lua_pop(L, 1); /* result from luaV_toline */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2024 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2025 lua_pop(L, 1); /* line */
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2026 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2027 lua_pop(L, 1); /* function */
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2028 check_cursor();
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2029 update_screen(NOT_VALID);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2030 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2031
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2032 void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2033 ex_luafile(exarg_T *eap)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2034 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2035 if (lua_init() == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2036 return;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2037 if (!eap->skip)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2038 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2039 luaV_setrange(L, eap->line1, eap->line2);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2040 if (luaL_loadfile(L, (char *) eap->arg) || lua_pcall(L, 0, 0, 0))
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2041 luaV_emsg(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2042 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2043 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2044
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2045 #define luaV_freetype(typ,tname) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2046 void \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2047 lua_##tname##_free(typ *o) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2048 { \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2049 if (!lua_isopen()) return; \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2050 luaV_getfield(L, LUAVIM_FREE); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2051 lua_pushlightuserdata(L, (void *) o); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2052 lua_call(L, 1, 0); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2053 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2054
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2055 luaV_freetype(buf_T, buffer)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2056 luaV_freetype(win_T, window)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2057
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2058 void
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2059 do_luaeval (char_u *str, typval_T *arg, typval_T *rettv)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2060 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2061 lua_init();
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2062 luaV_getfield(L, LUAVIM_LUAEVAL);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2063 lua_pushstring(L, (char *) str);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2064 lua_pushlightuserdata(L, (void *) arg);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2065 lua_pushlightuserdata(L, (void *) rettv);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2066 lua_call(L, 3, 0);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2067 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2068
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2069 int
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2070 set_ref_in_lua (int copyID)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2071 {
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2072 int aborted = 0;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2073
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2074 if (lua_isopen())
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2075 {
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2076 luaV_getfield(L, LUAVIM_SETREF);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2077 /* call the function with 1 arg, getting 1 result back */
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2078 lua_pushinteger(L, copyID);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2079 lua_call(L, 1, 1);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2080 /* get the result */
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2081 aborted = lua_tointeger(L, -1);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2082 /* pop result off the stack */
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2083 lua_pop(L, 1);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2084 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2085 return aborted;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2086 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2087
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2088 #endif