annotate src/if_lua.c @ 21766:283490dee44d

Added tag v8.2.1432 for changeset 08940efa6b4eb93d0213eac46ba3c7f2e7a4d575
author Bram Moolenaar <Bram@vim.org>
date Wed, 12 Aug 2020 19:00:09 +0200
parents f9d87868d77f
children 8da5e18effc5
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
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
18 // Only do the following when the feature is enabled. Needed for "make
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
19 // depend".
2320
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;
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
31 typedef blob_T *luaV_Blob;
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
32 typedef struct {
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
33 char_u *name; // funcref
14235
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
21006
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
38 typedef struct {
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
39 int lua_funcref; // ref to a lua func
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
40 int lua_tableref; // ref to a lua table if metatable else LUA_NOREF. used
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
41 // for __call
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
42 lua_State *L;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
43 } luaV_CFuncState;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
44
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
45 static const char LUAVIM_DICT[] = "dict";
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
46 static const char LUAVIM_LIST[] = "list";
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
47 static const char LUAVIM_BLOB[] = "blob";
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
48 static const char LUAVIM_FUNCREF[] = "funcref";
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 static const char LUAVIM_BUFFER[] = "buffer";
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 static const char LUAVIM_WINDOW[] = "window";
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 static const char LUAVIM_FREE[] = "luaV_free";
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
52 static const char LUAVIM_LUAEVAL[] = "luaV_luaeval";
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
53 static const char LUAVIM_SETREF[] = "luaV_setref";
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54
21006
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
55 static const char LUA___CALL[] = "__call";
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
56
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
57 // most functions are closures with a cache table as first upvalue;
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
58 // get/setudata manage references to vim userdata in cache table through
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
59 // object pointers (light userdata)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
60 #define luaV_getudata(L, v) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
61 lua_pushlightuserdata((L), (void *) (v)); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
62 lua_rawget((L), lua_upvalueindex(1))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
63 #define luaV_setudata(L, v) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
64 lua_pushlightuserdata((L), (void *) (v)); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
65 lua_pushvalue((L), -2); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
66 lua_rawset((L), lua_upvalueindex(1))
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
67 #define luaV_getfield(L, s) \
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68 lua_pushlightuserdata((L), (void *)(s)); \
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69 lua_rawget((L), LUA_REGISTRYINDEX)
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
70 #define luaV_checksandbox(L) \
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71 if (sandbox) luaL_error((L), "not allowed in sandbox")
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
72 #define luaV_msg(L) luaV_msgfunc((L), (msgfunc_T) msg)
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
73 #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
74 #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
75 do { \
21006
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
76 if (luaV_totypval(L, a, v) == FAIL) \
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
77 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
78 } while (0)
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
79
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
80 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
81 static luaV_Dict *luaV_pushdict(lua_State *L, dict_T *dic);
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
82 static luaV_Blob *luaV_pushblob(lua_State *L, blob_T *blo);
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
83 static luaV_Funcref *luaV_pushfuncref(lua_State *L, char_u *name);
21006
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
84 static int luaV_call_lua_func(int argcount, typval_T *argvars, typval_T *rettv, void *state);
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
85 static void luaV_call_lua_func_free(void *state);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
86
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
87 #if LUA_VERSION_NUM <= 501
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
88 #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
89 #define luaL_typeerror luaL_typerror
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
90 #else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
91 #define luaV_openlib luaL_setfuncs
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
92 #endif
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
93
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
94 #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
95
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
96 #ifndef MSWIN
2373
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
97 # include <dlfcn.h>
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
98 # define HANDLE void*
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
99 # 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
100 # 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
101 # 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
102 #else
2612
fa5dee44df3f updated for version 7.3.034
Bram Moolenaar <bram@vim.org>
parents: 2543
diff changeset
103 # 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
104 # 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
105 # 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
106 #endif
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
107
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
108 // lauxlib
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
109 #if LUA_VERSION_NUM <= 501
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
110 #define luaL_register dll_luaL_register
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
111 #define luaL_prepbuffer dll_luaL_prepbuffer
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
112 #define luaL_openlib dll_luaL_openlib
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
113 #define luaL_typerror dll_luaL_typerror
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
114 #define luaL_loadfile dll_luaL_loadfile
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
115 #define luaL_loadbuffer dll_luaL_loadbuffer
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
116 #else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
117 #define luaL_prepbuffsize dll_luaL_prepbuffsize
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
118 #define luaL_setfuncs dll_luaL_setfuncs
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
119 #define luaL_loadfilex dll_luaL_loadfilex
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
120 #define luaL_loadbufferx dll_luaL_loadbufferx
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
121 #define luaL_argerror dll_luaL_argerror
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
122 #endif
21323
5b0bbc5d4e74 patch 8.2.1212: cannot build with Lua 5.4
Bram Moolenaar <Bram@vim.org>
parents: 21132
diff changeset
123 #if LUA_VERSION_NUM >= 504
5b0bbc5d4e74 patch 8.2.1212: cannot build with Lua 5.4
Bram Moolenaar <Bram@vim.org>
parents: 21132
diff changeset
124 #define luaL_typeerror dll_luaL_typeerror
5b0bbc5d4e74 patch 8.2.1212: cannot build with Lua 5.4
Bram Moolenaar <Bram@vim.org>
parents: 21132
diff changeset
125 #endif
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
126 #define luaL_checkany dll_luaL_checkany
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
127 #define luaL_checklstring dll_luaL_checklstring
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
128 #define luaL_checkinteger dll_luaL_checkinteger
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
129 #define luaL_optinteger dll_luaL_optinteger
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
130 #define luaL_checktype dll_luaL_checktype
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
131 #define luaL_error dll_luaL_error
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
132 #define luaL_newstate dll_luaL_newstate
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
133 #define luaL_buffinit dll_luaL_buffinit
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
134 #define luaL_addlstring dll_luaL_addlstring
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
135 #define luaL_pushresult dll_luaL_pushresult
20456
25392efa9039 patch 8.2.0782: cannot build with Lua on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 20454
diff changeset
136 #define luaL_loadstring dll_luaL_loadstring
21012
380923b96878 patch 8.2.1057: cannot build with dynamic Lua
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
137 #define luaL_ref dll_luaL_ref
380923b96878 patch 8.2.1057: cannot build with dynamic Lua
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
138 #define luaL_unref dll_luaL_unref
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
139 // lua
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
140 #if LUA_VERSION_NUM <= 501
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
141 #define lua_tonumber dll_lua_tonumber
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
142 #define lua_tointeger dll_lua_tointeger
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
143 #define lua_call dll_lua_call
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
144 #define lua_pcall dll_lua_pcall
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
145 #else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
146 #define lua_tonumberx dll_lua_tonumberx
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
147 #define lua_tointegerx dll_lua_tointegerx
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
148 #define lua_callk dll_lua_callk
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
149 #define lua_pcallk dll_lua_pcallk
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
150 #define lua_getglobal dll_lua_getglobal
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
151 #define lua_setglobal dll_lua_setglobal
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
152 #endif
6887
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
153 #if LUA_VERSION_NUM <= 502
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
154 #define lua_replace dll_lua_replace
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
155 #define lua_remove dll_lua_remove
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
156 #endif
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
157 #if LUA_VERSION_NUM >= 503
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
158 #define lua_rotate dll_lua_rotate
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
159 #define lua_copy dll_lua_copy
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
160 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
161 #define lua_typename dll_lua_typename
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
162 #define lua_close dll_lua_close
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
163 #define lua_gettop dll_lua_gettop
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
164 #define lua_settop dll_lua_settop
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
165 #define lua_pushvalue dll_lua_pushvalue
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
166 #define lua_isnumber dll_lua_isnumber
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
167 #define lua_isstring dll_lua_isstring
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
168 #define lua_type dll_lua_type
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
169 #define lua_rawequal dll_lua_rawequal
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
170 #define lua_toboolean dll_lua_toboolean
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
171 #define lua_tolstring dll_lua_tolstring
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
172 #define lua_touserdata dll_lua_touserdata
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
173 #define lua_pushnil dll_lua_pushnil
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
174 #define lua_pushnumber dll_lua_pushnumber
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
175 #define lua_pushinteger dll_lua_pushinteger
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
176 #define lua_pushlstring dll_lua_pushlstring
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
177 #define lua_pushstring dll_lua_pushstring
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
178 #define lua_pushfstring dll_lua_pushfstring
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
179 #define lua_pushcclosure dll_lua_pushcclosure
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
180 #define lua_pushboolean dll_lua_pushboolean
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
181 #define lua_pushlightuserdata dll_lua_pushlightuserdata
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
182 #define lua_getfield dll_lua_getfield
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
183 #define lua_rawget dll_lua_rawget
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
184 #define lua_rawgeti dll_lua_rawgeti
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
185 #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
186 #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
187 #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
188 #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
189 #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
190 #endif
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
191 #define lua_getmetatable dll_lua_getmetatable
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
192 #define lua_setfield dll_lua_setfield
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
193 #define lua_rawset dll_lua_rawset
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
194 #define lua_rawseti dll_lua_rawseti
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
195 #define lua_setmetatable dll_lua_setmetatable
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
196 #define lua_next dll_lua_next
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
197 // libs
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
198 #define luaopen_base dll_luaopen_base
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
199 #define luaopen_table dll_luaopen_table
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
200 #define luaopen_string dll_luaopen_string
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
201 #define luaopen_math dll_luaopen_math
2431
7b764999f9b9 Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2373
diff changeset
202 #define luaopen_io dll_luaopen_io
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
203 #define luaopen_os dll_luaopen_os
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
204 #define luaopen_package dll_luaopen_package
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
205 #define luaopen_debug dll_luaopen_debug
2431
7b764999f9b9 Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2373
diff changeset
206 #define luaL_openlibs dll_luaL_openlibs
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
207
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
208 // lauxlib
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
209 #if LUA_VERSION_NUM <= 501
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
210 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
211 char *(*dll_luaL_prepbuffer) (luaL_Buffer *B);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
212 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
213 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
214 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
215 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
216 #else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
217 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
218 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
219 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
220 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
221 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
222 #endif
21323
5b0bbc5d4e74 patch 8.2.1212: cannot build with Lua 5.4
Bram Moolenaar <Bram@vim.org>
parents: 21132
diff changeset
223 #if LUA_VERSION_NUM >= 504
5b0bbc5d4e74 patch 8.2.1212: cannot build with Lua 5.4
Bram Moolenaar <Bram@vim.org>
parents: 21132
diff changeset
224 int (*dll_luaL_typeerror) (lua_State *L, int narg, const char *tname);
5b0bbc5d4e74 patch 8.2.1212: cannot build with Lua 5.4
Bram Moolenaar <Bram@vim.org>
parents: 21132
diff changeset
225 #endif
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
226 void (*dll_luaL_checkany) (lua_State *L, int narg);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
227 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
228 lua_Integer (*dll_luaL_checkinteger) (lua_State *L, int numArg);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
229 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
230 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
231 int (*dll_luaL_error) (lua_State *L, const char *fmt, ...);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
232 lua_State *(*dll_luaL_newstate) (void);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
233 void (*dll_luaL_buffinit) (lua_State *L, luaL_Buffer *B);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
234 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
235 void (*dll_luaL_pushresult) (luaL_Buffer *B);
20456
25392efa9039 patch 8.2.0782: cannot build with Lua on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 20454
diff changeset
236 int (*dll_luaL_loadstring) (lua_State *L, const char *s);
21012
380923b96878 patch 8.2.1057: cannot build with dynamic Lua
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
237 int (*dll_luaL_ref) (lua_State *L, int idx);
380923b96878 patch 8.2.1057: cannot build with dynamic Lua
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
238 #if LUA_VERSION_NUM <= 502
380923b96878 patch 8.2.1057: cannot build with dynamic Lua
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
239 void (*dll_luaL_unref) (lua_State *L, int idx, int n);
380923b96878 patch 8.2.1057: cannot build with dynamic Lua
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
240 #else
380923b96878 patch 8.2.1057: cannot build with dynamic Lua
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
241 void (*dll_luaL_unref) (lua_State *L, int idx, lua_Integer n);
380923b96878 patch 8.2.1057: cannot build with dynamic Lua
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
242 #endif
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
243 // lua
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
244 #if LUA_VERSION_NUM <= 501
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
245 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
246 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
247 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
248 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
249 #else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
250 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
251 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
252 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
253 lua_CFunction k);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
254 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
255 int ctx, lua_CFunction k);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
256 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
257 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
258 #endif
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
259 #if LUA_VERSION_NUM <= 502
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
260 void (*dll_lua_replace) (lua_State *L, int idx);
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
261 void (*dll_lua_remove) (lua_State *L, int idx);
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
262 #endif
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
263 #if LUA_VERSION_NUM >= 503
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
264 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
265 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
266 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
267 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
268 void (*dll_lua_close) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
269 int (*dll_lua_gettop) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
270 void (*dll_lua_settop) (lua_State *L, int idx);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
271 void (*dll_lua_pushvalue) (lua_State *L, int idx);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
272 int (*dll_lua_isnumber) (lua_State *L, int idx);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
273 int (*dll_lua_isstring) (lua_State *L, int idx);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
274 int (*dll_lua_type) (lua_State *L, int idx);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
275 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
276 int (*dll_lua_toboolean) (lua_State *L, int idx);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
277 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
278 void *(*dll_lua_touserdata) (lua_State *L, int idx);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
279 void (*dll_lua_pushnil) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
280 void (*dll_lua_pushnumber) (lua_State *L, lua_Number n);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
281 void (*dll_lua_pushinteger) (lua_State *L, lua_Integer n);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
282 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
283 void (*dll_lua_pushstring) (lua_State *L, const char *s);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
284 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
285 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
286 void (*dll_lua_pushboolean) (lua_State *L, int b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
287 void (*dll_lua_pushlightuserdata) (lua_State *L, void *p);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
288 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
289 #if LUA_VERSION_NUM <= 502
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
290 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
291 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
292 #else
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
293 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
294 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
295 #endif
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
296 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
297 #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
298 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
299 #else
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
300 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
301 #endif
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
302 int (*dll_lua_getmetatable) (lua_State *L, int objindex);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
303 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
304 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
305 #if LUA_VERSION_NUM <= 502
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
306 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
307 #else
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
308 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
309 #endif
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
310 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
311 int (*dll_lua_next) (lua_State *L, int idx);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
312 // libs
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
313 int (*dll_luaopen_base) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
314 int (*dll_luaopen_table) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
315 int (*dll_luaopen_string) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
316 int (*dll_luaopen_math) (lua_State *L);
2431
7b764999f9b9 Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2373
diff changeset
317 int (*dll_luaopen_io) (lua_State *L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
318 int (*dll_luaopen_os) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
319 int (*dll_luaopen_package) (lua_State *L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
320 int (*dll_luaopen_debug) (lua_State *L);
2431
7b764999f9b9 Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2373
diff changeset
321 void (*dll_luaL_openlibs) (lua_State *L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
322
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
323 typedef void **luaV_function;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
324 typedef struct {
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
325 const char *name;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
326 luaV_function func;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
327 } luaV_Reg;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
328
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
329 static const luaV_Reg luaV_dll[] = {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
330 // lauxlib
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
331 #if LUA_VERSION_NUM <= 501
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
332 {"luaL_register", (luaV_function) &dll_luaL_register},
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
333 {"luaL_prepbuffer", (luaV_function) &dll_luaL_prepbuffer},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
334 {"luaL_openlib", (luaV_function) &dll_luaL_openlib},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
335 {"luaL_typerror", (luaV_function) &dll_luaL_typerror},
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
336 {"luaL_loadfile", (luaV_function) &dll_luaL_loadfile},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
337 {"luaL_loadbuffer", (luaV_function) &dll_luaL_loadbuffer},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
338 #else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
339 {"luaL_prepbuffsize", (luaV_function) &dll_luaL_prepbuffsize},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
340 {"luaL_setfuncs", (luaV_function) &dll_luaL_setfuncs},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
341 {"luaL_loadfilex", (luaV_function) &dll_luaL_loadfilex},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
342 {"luaL_loadbufferx", (luaV_function) &dll_luaL_loadbufferx},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
343 {"luaL_argerror", (luaV_function) &dll_luaL_argerror},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
344 #endif
21323
5b0bbc5d4e74 patch 8.2.1212: cannot build with Lua 5.4
Bram Moolenaar <Bram@vim.org>
parents: 21132
diff changeset
345 #if LUA_VERSION_NUM >= 504
5b0bbc5d4e74 patch 8.2.1212: cannot build with Lua 5.4
Bram Moolenaar <Bram@vim.org>
parents: 21132
diff changeset
346 {"luaL_typeerror", (luaV_function) &dll_luaL_typeerror},
5b0bbc5d4e74 patch 8.2.1212: cannot build with Lua 5.4
Bram Moolenaar <Bram@vim.org>
parents: 21132
diff changeset
347 #endif
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
348 {"luaL_checkany", (luaV_function) &dll_luaL_checkany},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
349 {"luaL_checklstring", (luaV_function) &dll_luaL_checklstring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
350 {"luaL_checkinteger", (luaV_function) &dll_luaL_checkinteger},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
351 {"luaL_optinteger", (luaV_function) &dll_luaL_optinteger},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
352 {"luaL_checktype", (luaV_function) &dll_luaL_checktype},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
353 {"luaL_error", (luaV_function) &dll_luaL_error},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
354 {"luaL_newstate", (luaV_function) &dll_luaL_newstate},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
355 {"luaL_buffinit", (luaV_function) &dll_luaL_buffinit},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
356 {"luaL_addlstring", (luaV_function) &dll_luaL_addlstring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
357 {"luaL_pushresult", (luaV_function) &dll_luaL_pushresult},
20456
25392efa9039 patch 8.2.0782: cannot build with Lua on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 20454
diff changeset
358 {"luaL_loadstring", (luaV_function) &dll_luaL_loadstring},
21012
380923b96878 patch 8.2.1057: cannot build with dynamic Lua
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
359 {"luaL_ref", (luaV_function) &dll_luaL_ref},
380923b96878 patch 8.2.1057: cannot build with dynamic Lua
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
360 {"luaL_unref", (luaV_function) &dll_luaL_unref},
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
361 // lua
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
362 #if LUA_VERSION_NUM <= 501
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
363 {"lua_tonumber", (luaV_function) &dll_lua_tonumber},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
364 {"lua_tointeger", (luaV_function) &dll_lua_tointeger},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
365 {"lua_call", (luaV_function) &dll_lua_call},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
366 {"lua_pcall", (luaV_function) &dll_lua_pcall},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
367 #else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
368 {"lua_tonumberx", (luaV_function) &dll_lua_tonumberx},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
369 {"lua_tointegerx", (luaV_function) &dll_lua_tointegerx},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
370 {"lua_callk", (luaV_function) &dll_lua_callk},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
371 {"lua_pcallk", (luaV_function) &dll_lua_pcallk},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
372 {"lua_getglobal", (luaV_function) &dll_lua_getglobal},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
373 {"lua_setglobal", (luaV_function) &dll_lua_setglobal},
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
374 #endif
6887
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
375 #if LUA_VERSION_NUM <= 502
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
376 {"lua_replace", (luaV_function) &dll_lua_replace},
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
377 {"lua_remove", (luaV_function) &dll_lua_remove},
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
378 #endif
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
379 #if LUA_VERSION_NUM >= 503
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
380 {"lua_rotate", (luaV_function) &dll_lua_rotate},
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
381 {"lua_copy", (luaV_function) &dll_lua_copy},
2b7e36955265 patch 7.4.763
Bram Moolenaar <bram@vim.org>
parents: 6878
diff changeset
382 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
383 {"lua_typename", (luaV_function) &dll_lua_typename},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
384 {"lua_close", (luaV_function) &dll_lua_close},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
385 {"lua_gettop", (luaV_function) &dll_lua_gettop},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
386 {"lua_settop", (luaV_function) &dll_lua_settop},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
387 {"lua_pushvalue", (luaV_function) &dll_lua_pushvalue},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
388 {"lua_isnumber", (luaV_function) &dll_lua_isnumber},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
389 {"lua_isstring", (luaV_function) &dll_lua_isstring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
390 {"lua_type", (luaV_function) &dll_lua_type},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
391 {"lua_rawequal", (luaV_function) &dll_lua_rawequal},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
392 {"lua_toboolean", (luaV_function) &dll_lua_toboolean},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
393 {"lua_tolstring", (luaV_function) &dll_lua_tolstring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
394 {"lua_touserdata", (luaV_function) &dll_lua_touserdata},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
395 {"lua_pushnil", (luaV_function) &dll_lua_pushnil},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
396 {"lua_pushnumber", (luaV_function) &dll_lua_pushnumber},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
397 {"lua_pushinteger", (luaV_function) &dll_lua_pushinteger},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
398 {"lua_pushlstring", (luaV_function) &dll_lua_pushlstring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
399 {"lua_pushstring", (luaV_function) &dll_lua_pushstring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
400 {"lua_pushfstring", (luaV_function) &dll_lua_pushfstring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
401 {"lua_pushcclosure", (luaV_function) &dll_lua_pushcclosure},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
402 {"lua_pushboolean", (luaV_function) &dll_lua_pushboolean},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
403 {"lua_pushlightuserdata", (luaV_function) &dll_lua_pushlightuserdata},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
404 {"lua_getfield", (luaV_function) &dll_lua_getfield},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
405 {"lua_rawget", (luaV_function) &dll_lua_rawget},
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
406 {"lua_rawgeti", (luaV_function) &dll_lua_rawgeti},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
407 {"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
408 #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
409 {"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
410 #else
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
411 {"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
412 #endif
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
413 {"lua_getmetatable", (luaV_function) &dll_lua_getmetatable},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
414 {"lua_setfield", (luaV_function) &dll_lua_setfield},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
415 {"lua_rawset", (luaV_function) &dll_lua_rawset},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
416 {"lua_rawseti", (luaV_function) &dll_lua_rawseti},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
417 {"lua_setmetatable", (luaV_function) &dll_lua_setmetatable},
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
418 {"lua_next", (luaV_function) &dll_lua_next},
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
419 // libs
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
420 {"luaopen_base", (luaV_function) &dll_luaopen_base},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
421 {"luaopen_table", (luaV_function) &dll_luaopen_table},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
422 {"luaopen_string", (luaV_function) &dll_luaopen_string},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
423 {"luaopen_math", (luaV_function) &dll_luaopen_math},
2431
7b764999f9b9 Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2373
diff changeset
424 {"luaopen_io", (luaV_function) &dll_luaopen_io},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
425 {"luaopen_os", (luaV_function) &dll_luaopen_os},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
426 {"luaopen_package", (luaV_function) &dll_luaopen_package},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
427 {"luaopen_debug", (luaV_function) &dll_luaopen_debug},
2431
7b764999f9b9 Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2373
diff changeset
428 {"luaL_openlibs", (luaV_function) &dll_luaL_openlibs},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
429 {NULL, NULL}
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
430 };
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
431
2373
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
432 static HANDLE hinstLua = NULL;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
433
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
434 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
435 lua_link_init(char *libname, int verbose)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
436 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
437 const luaV_Reg *reg;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
438 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
439 hinstLua = load_dll(libname);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
440 if (!hinstLua)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
441 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
442 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15328
diff changeset
443 semsg(_(e_loadlib), libname);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
444 return FAIL;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
445 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
446 for (reg = luaV_dll; reg->func; reg++)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
447 {
2373
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
448 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
449 {
f149bb1cf5be Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents: 2331
diff changeset
450 close_dll(hinstLua);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
451 hinstLua = 0;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
452 if (verbose)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15328
diff changeset
453 semsg(_(e_loadfunc), reg->name);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
454 return FAIL;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
455 }
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
456 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
457 return OK;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
458 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
459 #endif // DYNAMIC_LUA
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
460
10025
068f397d0da4 commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
461 #if defined(DYNAMIC_LUA) || defined(PROTO)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
462 int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
463 lua_enabled(int verbose)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
464 {
7528
53163e4d9e4f commit https://github.com/vim/vim/commit/25e4fcde767084d1a79e0926bc301c92987c0cce
Christian Brabandt <cb@256bit.org>
parents: 7297
diff changeset
465 return lua_link_init((char *)p_luadll, verbose) == OK;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
466 }
10025
068f397d0da4 commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
467 #endif
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
468
21323
5b0bbc5d4e74 patch 8.2.1212: cannot build with Lua 5.4
Bram Moolenaar <Bram@vim.org>
parents: 21132
diff changeset
469 #if LUA_VERSION_NUM > 501 && LUA_VERSION_NUM < 504
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
470 static int
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
471 luaL_typeerror(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
472 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
473 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
474 tname, luaL_typename(L, narg));
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
475 return luaL_argerror(L, narg, msg);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
476 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
477 #endif
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
478
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
479
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
480 // ======= Internal =======
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
481
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
482 static void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
483 luaV_newmetatable(lua_State *L, const char *tname)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
484 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
485 lua_newtable(L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
486 lua_pushlightuserdata(L, (void *) tname);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
487 lua_pushvalue(L, -2);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
488 lua_rawset(L, LUA_REGISTRYINDEX);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
489 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
490
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
491 static void *
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
492 luaV_toudata(lua_State *L, int ud, const char *tname)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
493 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
494 void *p = lua_touserdata(L, ud);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
495
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
496 if (p != NULL) // value is userdata?
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
497 {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
498 if (lua_getmetatable(L, ud)) // does it have a metatable?
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
499 {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
500 luaV_getfield(L, tname); // get metatable
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
501 if (lua_rawequal(L, -1, -2)) // MTs match?
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
502 {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
503 lua_pop(L, 2); // MTs
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
504 return p;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
505 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
506 }
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
507 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
508 return NULL;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
509 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
510
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
511 static void *
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
512 luaV_checkcache(lua_State *L, void *p)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
513 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
514 luaV_getudata(L, p);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
515 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
516 lua_pop(L, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
517 return p;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
518 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
519
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
520 #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
521
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
522 #define luaV_checkvalid(L,luatyp,ud) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
523 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
524
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
525 static void *
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
526 luaV_checkudata(lua_State *L, int ud, const char *tname)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
527 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
528 void *p = luaV_toudata(L, ud, tname);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
529 if (p == NULL) luaL_typeerror(L, ud, tname);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
530 return p;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
531 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
532
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
533 static void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
534 luaV_pushtypval(lua_State *L, typval_T *tv)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
535 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
536 if (tv == NULL)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
537 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
538 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
539 return;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
540 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
541 switch (tv->v_type)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
542 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
543 case VAR_STRING:
3865
3c072c1cb873 updated for version 7.3.689
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
544 lua_pushstring(L, tv->vval.v_string == NULL
3c072c1cb873 updated for version 7.3.689
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
545 ? "" : (char *)tv->vval.v_string);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
546 break;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
547 case VAR_NUMBER:
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
548 lua_pushinteger(L, (int) tv->vval.v_number);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
549 break;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
550 #ifdef FEAT_FLOAT
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
551 case VAR_FLOAT:
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
552 lua_pushnumber(L, (lua_Number) tv->vval.v_float);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
553 break;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
554 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
555 case VAR_LIST:
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
556 luaV_pushlist(L, tv->vval.v_list);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
557 break;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
558 case VAR_DICT:
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
559 luaV_pushdict(L, tv->vval.v_dict);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
560 break;
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 18798
diff changeset
561 case VAR_BOOL:
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7528
diff changeset
562 case VAR_SPECIAL:
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7528
diff changeset
563 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
564 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
565 else
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7528
diff changeset
566 lua_pushnil(L);
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7528
diff changeset
567 break;
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
568 case VAR_FUNC:
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
569 luaV_pushfuncref(L, tv->vval.v_string);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
570 break;
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
571 case VAR_BLOB:
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
572 luaV_pushblob(L, tv->vval.v_blob);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
573 break;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
574 default:
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
575 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
576 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
577 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
578
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
579 /*
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
580 * 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
581 * Returns OK or FAIL.
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
582 */
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
583 static int
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
584 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
585 {
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
586 int status = OK;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
587
21132
985e61894bb4 patch 8.2.1117: Coverity warns for unsing unitialized field
Bram Moolenaar <Bram@vim.org>
parents: 21108
diff changeset
588 tv->v_lock = 0;
985e61894bb4 patch 8.2.1117: Coverity warns for unsing unitialized field
Bram Moolenaar <Bram@vim.org>
parents: 21108
diff changeset
589
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
590 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
591 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
592 case LUA_TBOOLEAN:
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 18798
diff changeset
593 tv->v_type = VAR_BOOL;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
594 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
595 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
596 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
597 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
598 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
599 break;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
600 case LUA_TSTRING:
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
601 tv->v_type = VAR_STRING;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
602 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
603 break;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
604 case LUA_TNUMBER:
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
605 #ifdef FEAT_FLOAT
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
606 {
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
607 const lua_Number n = lua_tonumber(L, pos);
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
608
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
609 if (n > (lua_Number)INT64_MAX || n < (lua_Number)INT64_MIN
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
610 || ((lua_Number)((varnumber_T)n)) != n)
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
611 {
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
612 tv->v_type = VAR_FLOAT;
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
613 tv->vval.v_float = (float_T)n;
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
614 }
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
615 else
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
616 {
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
617 tv->v_type = VAR_NUMBER;
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
618 tv->vval.v_number = (varnumber_T)n;
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
619 }
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
620 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
621 #else
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 = (varnumber_T) lua_tointeger(L, pos);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
624 #endif
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
625 break;
21006
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
626 case LUA_TFUNCTION:
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
627 {
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
628 char_u *name;
21367
f9d87868d77f patch 8.2.1234: Lua build problem with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 21323
diff changeset
629 luaV_CFuncState *state;
f9d87868d77f patch 8.2.1234: Lua build problem with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 21323
diff changeset
630
21006
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
631 lua_pushvalue(L, pos);
21367
f9d87868d77f patch 8.2.1234: Lua build problem with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 21323
diff changeset
632 state = ALLOC_CLEAR_ONE(luaV_CFuncState);
21006
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
633 state->lua_funcref = luaL_ref(L, LUA_REGISTRYINDEX);
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
634 state->L = L;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
635 state->lua_tableref = LUA_NOREF;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
636 name = register_cfunc(&luaV_call_lua_func,
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
637 &luaV_call_lua_func_free, state);
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
638 tv->v_type = VAR_FUNC;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
639 tv->vval.v_string = vim_strsave(name);
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
640 break;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
641 }
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
642 case LUA_TTABLE:
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
643 {
21367
f9d87868d77f patch 8.2.1234: Lua build problem with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 21323
diff changeset
644 int lua_tableref;
f9d87868d77f patch 8.2.1234: Lua build problem with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 21323
diff changeset
645
21006
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
646 lua_pushvalue(L, pos);
21367
f9d87868d77f patch 8.2.1234: Lua build problem with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 21323
diff changeset
647 lua_tableref = luaL_ref(L, LUA_REGISTRYINDEX);
21006
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
648 if (lua_getmetatable(L, pos)) {
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
649 lua_getfield(L, -1, LUA___CALL);
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
650 if (lua_isfunction(L, -1)) {
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
651 char_u *name;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
652 int lua_funcref = luaL_ref(L, LUA_REGISTRYINDEX);
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
653 luaV_CFuncState *state = ALLOC_CLEAR_ONE(luaV_CFuncState);
21367
f9d87868d77f patch 8.2.1234: Lua build problem with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 21323
diff changeset
654
21006
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
655 state->lua_funcref = lua_funcref;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
656 state->L = L;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
657 state->lua_tableref = lua_tableref;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
658 name = register_cfunc(&luaV_call_lua_func,
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
659 &luaV_call_lua_func_free, state);
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
660 tv->v_type = VAR_FUNC;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
661 tv->vval.v_string = vim_strsave(name);
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
662 break;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
663 }
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
664 }
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
665 tv->v_type = VAR_NUMBER;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
666 tv->vval.v_number = 0;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
667 status = FAIL;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
668 break;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
669 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
670 case LUA_TUSERDATA:
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
671 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
672 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
673
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
674 if (lua_getmetatable(L, pos)) // has metatable?
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
675 {
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
676 // check list
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
677 luaV_getfield(L, LUAVIM_LIST);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
678 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
679 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
680 tv->v_type = VAR_LIST;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
681 tv->vval.v_list = *((luaV_List *) p);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
682 ++tv->vval.v_list->lv_refcount;
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
683 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
684 break;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
685 }
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
686 // check dict
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
687 luaV_getfield(L, LUAVIM_DICT);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
688 if (lua_rawequal(L, -1, -3))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
689 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
690 tv->v_type = VAR_DICT;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
691 tv->vval.v_dict = *((luaV_Dict *) p);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
692 ++tv->vval.v_dict->dv_refcount;
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
693 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
694 break;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
695 }
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
696 // check blob
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
697 luaV_getfield(L, LUAVIM_BLOB);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
698 if (lua_rawequal(L, -1, -4))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
699 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
700 tv->v_type = VAR_BLOB;
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
701 tv->vval.v_blob = *((luaV_Blob *) p);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
702 ++tv->vval.v_blob->bv_refcount;
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
703 lua_pop(L, 4); // MTs
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
704 break;
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
705 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
706 // check funcref
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
707 luaV_getfield(L, LUAVIM_FUNCREF);
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
708 if (lua_rawequal(L, -1, -5))
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
709 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
710 luaV_Funcref *f = (luaV_Funcref *) p;
21367
f9d87868d77f patch 8.2.1234: Lua build problem with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 21323
diff changeset
711
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
712 func_ref(f->name);
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
713 tv->v_type = VAR_FUNC;
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
714 tv->vval.v_string = vim_strsave(f->name);
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
715 lua_pop(L, 5); // MTs
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
716 break;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
717 }
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
718 lua_pop(L, 4); // MTs
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
719 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
720 }
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
721 // FALLTHROUGH
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
722 default:
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
723 tv->v_type = VAR_NUMBER;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
724 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
725 status = FAIL;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
726 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
727 return status;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
728 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
729
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
730 /*
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
731 * similar to luaL_addlstring, but replaces \0 with \n if toline and
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
732 * \n with \0 otherwise
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
733 */
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
734 static void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
735 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
736 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
737 while (l--)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
738 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
739 if (*s == '\0' && toline)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
740 luaL_addchar(b, '\n');
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
741 else if (*s == '\n' && !toline)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
742 luaL_addchar(b, '\0');
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
743 else
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
744 luaL_addchar(b, *s);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
745 s++;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
746 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
747 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
748
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
749 static void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
750 luaV_pushline(lua_State *L, buf_T *buf, linenr_T n)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
751 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
752 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
753 luaL_Buffer b;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
754 luaL_buffinit(L, &b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
755 luaV_addlstring(&b, s, strlen(s), 0);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
756 luaL_pushresult(&b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
757 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
758
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
759 static char_u *
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
760 luaV_toline(lua_State *L, int pos)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
761 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
762 size_t l;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
763 const char *s = lua_tolstring(L, pos, &l);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
764
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
765 luaL_Buffer b;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
766 luaL_buffinit(L, &b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
767 luaV_addlstring(&b, s, l, 1);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
768 luaL_pushresult(&b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
769 return (char_u *) lua_tostring(L, -1);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
770 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
771
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
772 /*
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
773 * pops a string s from the top of the stack and calls mf(t) for pieces t of
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
774 * s separated by newlines
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
775 */
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
776 static void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
777 luaV_msgfunc(lua_State *L, msgfunc_T mf)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
778 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
779 luaL_Buffer b;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
780 size_t l;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
781 const char *p, *s = lua_tolstring(L, -1, &l);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
782 luaL_buffinit(L, &b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
783 luaV_addlstring(&b, s, l, 0);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
784 luaL_pushresult(&b);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
785 // break string
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
786 p = s = lua_tolstring(L, -1, &l);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
787 while (l--)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
788 {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
789 if (*p++ == '\0') // break?
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
790 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
791 mf((char_u *) s);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
792 s = p;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
793 }
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
794 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
795 mf((char_u *) s);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
796 lua_pop(L, 2); // original and modified strings
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
797 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
798
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
799 #define luaV_newtype(typ,tname,luatyp,luatname) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
800 static luatyp * \
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
801 luaV_new##tname(lua_State *L, typ *obj) \
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
802 { \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
803 luatyp *o = (luatyp *) lua_newuserdata(L, sizeof(luatyp)); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
804 *o = obj; \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
805 luaV_setudata(L, obj); /* cache[obj] = udata */ \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
806 luaV_getfield(L, luatname); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
807 lua_setmetatable(L, -2); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
808 return o; \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
809 }
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
810
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
811 #define luaV_pushtype(typ,tname,luatyp) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
812 static luatyp * \
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
813 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
814 { \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
815 luatyp *o = NULL; \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
816 if (obj == NULL) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
817 lua_pushnil(L); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
818 else { \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
819 luaV_getudata(L, obj); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
820 if (lua_isnil(L, -1)) /* not interned? */ \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
821 { \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
822 lua_pop(L, 1); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
823 o = luaV_new##tname(L, obj); \
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 o = (luatyp *) lua_touserdata(L, -1); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
827 } \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
828 return o; \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
829 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
830
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
831 #define luaV_type_tostring(tname,luatname) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
832 static int \
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
833 luaV_##tname##_tostring(lua_State *L) \
3450
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 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
836 return 1; \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
837 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
838
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
839 // ======= List type =======
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
840
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
841 static luaV_List *
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
842 luaV_newlist(lua_State *L, list_T *lis)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
843 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
844 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
845 *l = lis;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
846 lis->lv_refcount++; // reference in Lua
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
847 luaV_setudata(L, lis); // cache[lis] = udata
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
848 luaV_getfield(L, LUAVIM_LIST);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
849 lua_setmetatable(L, -2);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
850 return l;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
851 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
852
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
853 luaV_pushtype(list_T, list, luaV_List)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
854 luaV_type_tostring(list, LUAVIM_LIST)
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
855
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
856 static int
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
857 luaV_list_len(lua_State *L)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
858 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
859 list_T *l = luaV_unbox(L, luaV_List, 1);
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
860 lua_pushinteger(L, (int) list_len(l));
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
861 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
862 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
863
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
864 static int
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
865 luaV_list_iter(lua_State *L)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
866 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
867 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
868 if (li == NULL) return 0;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
869 luaV_pushtypval(L, &li->li_tv);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
870 lua_pushlightuserdata(L, (void *) li->li_next);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
871 lua_replace(L, lua_upvalueindex(2));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
872 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
873 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
874
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
875 static int
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
876 luaV_list_call(lua_State *L)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
877 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
878 list_T *l = luaV_unbox(L, luaV_List, 1);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
879 lua_pushvalue(L, lua_upvalueindex(1)); // pass cache table along
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
880 lua_pushlightuserdata(L, (void *) l->lv_first);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
881 lua_pushcclosure(L, luaV_list_iter, 2);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
882 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
883 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
884
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
885 static int
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
886 luaV_list_index(lua_State *L)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
887 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
888 list_T *l = luaV_unbox(L, luaV_List, 1);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
889 if (lua_isnumber(L, 2)) // list item?
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
890 {
21030
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21012
diff changeset
891 long n = (long) luaL_checkinteger(L, 2);
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21012
diff changeset
892 listitem_T *li;
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21012
diff changeset
893
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21012
diff changeset
894 // Lua array index starts with 1 while Vim uses 0, subtract 1 to
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21012
diff changeset
895 // normalize.
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21012
diff changeset
896 n -= 1;
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21012
diff changeset
897 li = list_find(l, n);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
898 if (li == NULL)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
899 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
900 else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
901 luaV_pushtypval(L, &li->li_tv);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
902 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
903 else if (lua_isstring(L, 2)) // method?
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
904 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
905 const char *s = lua_tostring(L, 2);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
906 if (strncmp(s, "add", 3) == 0
4293
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
907 || strncmp(s, "insert", 6) == 0)
3450
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 lua_getmetatable(L, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
910 lua_getfield(L, -1, s);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
911 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
912 else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
913 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
914 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
915 else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
916 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
917 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
918 }
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 static int
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
921 luaV_list_newindex(lua_State *L)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
922 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
923 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
924 long n = (long) luaL_checkinteger(L, 2);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
925 listitem_T *li;
21030
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21012
diff changeset
926
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21012
diff changeset
927 // Lua array index starts with 1 while Vim uses 0, subtract 1 to normalize.
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21012
diff changeset
928 n -= 1;
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21012
diff changeset
929
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
930 if (l->lv_lock)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
931 luaL_error(L, "list is locked");
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
932 li = list_find(l, n);
21060
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
933 if (li == NULL)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
934 {
21060
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
935 if (!lua_isnil(L, 3))
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
936 {
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
937 typval_T v;
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
938 luaV_checktypval(L, 3, &v, "inserting list item");
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
939 if (list_insert_tv(l, &v, li) == FAIL)
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
940 luaL_error(L, "failed to add item to list");
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
941 clear_tv(&v);
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
942 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
943 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
944 else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
945 {
21060
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
946 if (lua_isnil(L, 3)) // remove?
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
947 {
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
948 vimlist_remove(l, li, li);
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
949 listitem_free(l, li);
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
950 }
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
951 else
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
952 {
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
953 typval_T v;
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
954 luaV_checktypval(L, 3, &v, "setting list item");
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
955 clear_tv(&li->li_tv);
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
956 li->li_tv = v;
21060
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
957 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
958 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
959 return 0;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
960 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
961
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
962 static int
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
963 luaV_list_add(lua_State *L)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
964 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
965 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
966 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
967 typval_T v;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
968 if (l->lv_lock)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
969 luaL_error(L, "list is locked");
4293
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
970 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
971 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
972 if (list_append_tv(l, &v) == FAIL)
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
973 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
974 clear_tv(&v);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
975 lua_settop(L, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
976 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
977 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
978
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
979 static int
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
980 luaV_list_insert(lua_State *L)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
981 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
982 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
983 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
984 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
985 listitem_T *li = NULL;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
986 typval_T v;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
987 if (l->lv_lock)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
988 luaL_error(L, "list is locked");
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
989 if (pos < l->lv_len)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
990 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
991 li = list_find(l, pos);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
992 if (li == NULL)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
993 luaL_error(L, "invalid position");
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
994 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
995 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
996 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
997 if (list_insert_tv(l, &v, li) == FAIL)
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
998 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
999 clear_tv(&v);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1000 lua_settop(L, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1001 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1002 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1003
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1004 static const luaL_Reg luaV_List_mt[] = {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1005 {"__tostring", luaV_list_tostring},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1006 {"__len", luaV_list_len},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1007 {"__call", luaV_list_call},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1008 {"__index", luaV_list_index},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1009 {"__newindex", luaV_list_newindex},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1010 {"add", luaV_list_add},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1011 {"insert", luaV_list_insert},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1012 {NULL, NULL}
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
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1015
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1016 // ======= Dict type =======
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1017
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1018 static luaV_Dict *
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1019 luaV_newdict(lua_State *L, dict_T *dic)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1020 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1021 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
1022 *d = dic;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1023 dic->dv_refcount++; // reference in Lua
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1024 luaV_setudata(L, dic); // cache[dic] = udata
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1025 luaV_getfield(L, LUAVIM_DICT);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1026 lua_setmetatable(L, -2);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1027 return d;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1028 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1029
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1030 luaV_pushtype(dict_T, dict, luaV_Dict)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1031 luaV_type_tostring(dict, LUAVIM_DICT)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1032
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1033 static int
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1034 luaV_dict_len(lua_State *L)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1035 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1036 dict_T *d = luaV_unbox(L, luaV_Dict, 1);
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1037 lua_pushinteger(L, (int) dict_len(d));
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1038 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1039 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1040
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1041 static int
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1042 luaV_dict_iter(lua_State *L UNUSED)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1043 {
4135
688da4d486a0 updated for version 7.3.820
Bram Moolenaar <bram@vim.org>
parents: 3865
diff changeset
1044 #ifdef FEAT_EVAL
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1045 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
1046 int n = lua_tointeger(L, lua_upvalueindex(3));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1047 dictitem_T *di;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1048 if (n <= 0) return 0;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1049 while (HASHITEM_EMPTY(hi)) hi++;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1050 di = dict_lookup(hi);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1051 lua_pushstring(L, (char *) hi->hi_key);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1052 luaV_pushtypval(L, &di->di_tv);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1053 lua_pushlightuserdata(L, (void *) (hi + 1));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1054 lua_replace(L, lua_upvalueindex(2));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1055 lua_pushinteger(L, n - 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1056 lua_replace(L, lua_upvalueindex(3));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1057 return 2;
4135
688da4d486a0 updated for version 7.3.820
Bram Moolenaar <bram@vim.org>
parents: 3865
diff changeset
1058 #else
688da4d486a0 updated for version 7.3.820
Bram Moolenaar <bram@vim.org>
parents: 3865
diff changeset
1059 return 0;
688da4d486a0 updated for version 7.3.820
Bram Moolenaar <bram@vim.org>
parents: 3865
diff changeset
1060 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1061 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1062
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1063 static int
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1064 luaV_dict_call(lua_State *L)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1065 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1066 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
1067 hashtab_T *ht = &d->dv_hashtab;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1068 lua_pushvalue(L, lua_upvalueindex(1)); // pass cache table along
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1069 lua_pushlightuserdata(L, (void *) ht->ht_array);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1070 lua_pushinteger(L, ht->ht_used); // # remaining items
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1071 lua_pushcclosure(L, luaV_dict_iter, 3);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1072 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1073 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1074
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1075 static int
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1076 luaV_dict_index(lua_State *L)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1077 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1078 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
1079 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
1080 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
1081
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1082 if (di == NULL)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1083 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1084 else
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1085 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1086 luaV_pushtypval(L, &di->di_tv);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1087 if (di->di_tv.v_type == VAR_FUNC) // funcref?
14235
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 luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, -1);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1090 f->self = d; // keep "self" reference
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1091 d->dv_refcount++;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1092 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1093 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1094 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1095 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1096
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1097 static int
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1098 luaV_dict_newindex(lua_State *L)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1099 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1100 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
1101 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
1102 dictitem_T *di;
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
1103 typval_T tv;
16009
3b524e8110ab patch 8.1.1010: Lua interface leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15868
diff changeset
1104
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1105 if (d->dv_lock)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1106 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
1107 if (key == NULL)
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1108 return 0;
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1109 if (*key == NUL)
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1110 luaL_error(L, "empty key");
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1111 if (!lua_isnil(L, 3)) // read value?
14335
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
1112 {
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
1113 luaV_checktypval(L, 3, &tv, "setting dict item");
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
1114 if (d->dv_scope == VAR_DEF_SCOPE && tv.v_type == VAR_FUNC)
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
1115 {
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
1116 clear_tv(&tv);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1117 luaL_error(L, "cannot assign funcref to builtin scope");
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
1118 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1119 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1120 di = dict_find(d, key, -1);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1121 if (di == NULL) // non-existing key?
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1122 {
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1123 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
1124 return 0;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1125 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
1126 if (di == NULL)
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
1127 {
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
1128 clear_tv(&tv);
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1129 return 0;
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
1130 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1131 if (dict_add(d, di) == FAIL)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1132 {
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1133 vim_free(di);
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
1134 clear_tv(&tv);
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1135 return 0;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1136 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1137 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1138 else
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1139 clear_tv(&di->di_tv);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1140 if (lua_isnil(L, 3)) // remove?
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1141 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1142 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
1143 hash_remove(&d->dv_hashtab, hi);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1144 dictitem_free(di);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1145 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1146 else
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
1147 di->di_tv = tv;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1148 return 0;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1149 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1150
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1151 static const luaL_Reg luaV_Dict_mt[] = {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1152 {"__tostring", luaV_dict_tostring},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1153 {"__len", luaV_dict_len},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1154 {"__call", luaV_dict_call},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1155 {"__index", luaV_dict_index},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1156 {"__newindex", luaV_dict_newindex},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1157 {NULL, NULL}
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1158 };
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1159
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1160
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1161 // ======= Blob type =======
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1162
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1163 static luaV_Blob *
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1164 luaV_newblob(lua_State *L, blob_T *blo)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1165 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1166 luaV_Blob *b = (luaV_Blob *) lua_newuserdata(L, sizeof(luaV_Blob));
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1167 *b = blo;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1168 blo->bv_refcount++; // reference in Lua
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1169 luaV_setudata(L, blo); // cache[blo] = udata
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1170 luaV_getfield(L, LUAVIM_BLOB);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1171 lua_setmetatable(L, -2);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1172 return b;
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1173 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1174
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1175 luaV_pushtype(blob_T, blob, luaV_Blob)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1176 luaV_type_tostring(blob, LUAVIM_BLOB)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1177
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1178 static int
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1179 luaV_blob_gc(lua_State *L)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1180 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1181 blob_T *b = luaV_unbox(L, luaV_Blob, 1);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1182 blob_unref(b);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1183 return 0;
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1184 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1185
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1186 static int
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1187 luaV_blob_len(lua_State *L)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1188 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1189 blob_T *b = luaV_unbox(L, luaV_Blob, 1);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1190 lua_pushinteger(L, (int) blob_len(b));
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1191 return 1;
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1192 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1193
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1194 static int
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1195 luaV_blob_index(lua_State *L)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1196 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1197 blob_T *b = luaV_unbox(L, luaV_Blob, 1);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1198 if (lua_isnumber(L, 2))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1199 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1200 int idx = luaL_checkinteger(L, 2);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1201 if (idx < blob_len(b))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1202 lua_pushnumber(L, (lua_Number) blob_get(b, idx));
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1203 else
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1204 lua_pushnil(L);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1205 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1206 else if (lua_isstring(L, 2))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1207 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1208 const char *s = lua_tostring(L, 2);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1209 if (strncmp(s, "add", 3) == 0)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1210 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1211 lua_getmetatable(L, 1);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1212 lua_getfield(L, -1, s);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1213 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1214 else
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1215 lua_pushnil(L);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1216 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1217 else
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1218 lua_pushnil(L);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1219 return 1;
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1220 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1221
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1222 static int
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1223 luaV_blob_newindex(lua_State *L)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1224 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1225 blob_T *b = luaV_unbox(L, luaV_Blob, 1);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1226 if (b->bv_lock)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1227 luaL_error(L, "blob is locked");
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1228 if (lua_isnumber(L, 2))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1229 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1230 long len = blob_len(b);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1231 int idx = luaL_checkinteger(L, 2);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1232 int val = luaL_checkinteger(L, 3);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1233 if (idx < len || (idx == len && ga_grow(&b->bv_ga, 1) == OK))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1234 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1235 blob_set(b, idx, (char_u) val);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1236 if (idx == len)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1237 ++b->bv_ga.ga_len;
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1238 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1239 else
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1240 luaL_error(L, "index out of range");
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1241 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1242 return 0;
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1243 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1244
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1245 static int
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1246 luaV_blob_add(lua_State *L)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1247 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1248 luaV_Blob *blo = luaV_checkudata(L, 1, LUAVIM_BLOB);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1249 blob_T *b = (blob_T *) luaV_checkcache(L, (void *) *blo);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1250 if (b->bv_lock)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1251 luaL_error(L, "blob is locked");
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1252 lua_settop(L, 2);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1253 if (!lua_isstring(L, 2))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1254 luaL_error(L, "string expected, got %s", luaL_typename(L, 2));
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1255 else
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1256 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1257 size_t i, l = 0;
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1258 const char *s = lua_tolstring(L, 2, &l);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1259
19372
967149bbd8d3 patch 8.2.0244: compiler warning in Lua interface
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
1260 if (ga_grow(&b->bv_ga, (int)l) == OK)
16099
643fe07aa0e2 patch 8.1.1054: not checking return value of ga_grow()
Bram Moolenaar <Bram@vim.org>
parents: 16076
diff changeset
1261 for (i = 0; i < l; ++i)
643fe07aa0e2 patch 8.1.1054: not checking return value of ga_grow()
Bram Moolenaar <Bram@vim.org>
parents: 16076
diff changeset
1262 ga_append(&b->bv_ga, s[i]);
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1263 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1264 lua_settop(L, 1);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1265 return 1;
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1266 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1267
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1268 static const luaL_Reg luaV_Blob_mt[] = {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1269 {"__tostring", luaV_blob_tostring},
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1270 {"__gc", luaV_blob_gc},
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1271 {"__len", luaV_blob_len},
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1272 {"__index", luaV_blob_index},
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1273 {"__newindex", luaV_blob_newindex},
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1274 {"add", luaV_blob_add},
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1275 {NULL, NULL}
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1276 };
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1277
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1278
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1279 // ======= Funcref type =======
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1280
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1281 static luaV_Funcref *
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1282 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
1283 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1284 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
1285
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1286 if (name != NULL)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1287 {
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1288 func_ref(name);
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1289 f->name = vim_strsave(name);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1290 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1291 f->self = NULL;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1292 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
1293 lua_setmetatable(L, -2);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1294 return f;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1295 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1296
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1297 static luaV_Funcref *
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1298 luaV_pushfuncref(lua_State *L, char_u *name)
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1299 {
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1300 return luaV_newfuncref(L, name);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1301 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1302
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1303
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1304 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
1305
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1306 static int
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1307 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
1308 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1309 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
1310
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1311 func_unref(f->name);
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1312 vim_free(f->name);
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1313 // NOTE: Don't call "dict_unref(f->self)", because the dict of "f->self"
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1314 // will be (or has been already) freed by Vim's garbage collection.
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1315 return 0;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1316 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1317
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1318 // equivalent to string(funcref)
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1319 static int
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1320 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
1321 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1322 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
1323
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1324 lua_pushstring(L, (const char *) f->name);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1325 return 1;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1326 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1327
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1328 static int
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1329 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
1330 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1331 luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, 1);
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1332 int i, n = lua_gettop(L) - 1; // #args
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1333 int status = FAIL;
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1334 typval_T args;
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1335 typval_T rettv;
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1336
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1337 args.v_type = VAR_LIST;
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1338 args.vval.v_list = list_alloc();
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1339 rettv.v_type = VAR_UNKNOWN; // as in clear_tv
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1340 if (args.vval.v_list != NULL)
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1341 {
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1342 typval_T v;
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1343
14335
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
1344 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
1345 {
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1346 luaV_checktypval(L, i + 2, &v, "calling funcref");
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1347 list_append_tv(args.vval.v_list, &v);
16009
3b524e8110ab patch 8.1.1010: Lua interface leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15868
diff changeset
1348 clear_tv(&v);
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1349 }
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1350 status = func_call(f->name, &args, NULL, f->self, &rettv);
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1351 if (status == OK)
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1352 luaV_pushtypval(L, &rettv);
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1353 clear_tv(&args);
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1354 clear_tv(&rettv);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1355 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1356 if (status != OK)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1357 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
1358 return 1;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1359 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1360
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1361 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
1362 {"__tostring", luaV_funcref_tostring},
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1363 {"__gc", luaV_funcref_gc},
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1364 {"__len", luaV_funcref_len},
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1365 {"__call", luaV_funcref_call},
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1366 {NULL, NULL}
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1367 };
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1368
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1369
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1370 // ======= Buffer type =======
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1371
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1372 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
1373 luaV_pushtype(buf_T, buffer, luaV_Buffer)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1374 luaV_type_tostring(buffer, LUAVIM_BUFFER)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1375
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1376 static int
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1377 luaV_buffer_len(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1378 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1379 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
1380 lua_pushinteger(L, b->b_ml.ml_line_count);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1381 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1382 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1383
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1384 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1385 luaV_buffer_call(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1386 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1387 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
1388 lua_settop(L, 1);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1389 set_curbuf(b, DOBUF_SPLIT);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1390 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1391 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1392
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1393 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1394 luaV_buffer_index(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1395 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1396 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
1397 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
1398 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
1399 luaV_pushline(L, b, n);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1400 else if (lua_isstring(L, 2))
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1401 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1402 const char *s = lua_tostring(L, 2);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1403 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
1404 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
1405 ? "" : (char *) b->b_sfname);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1406 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
1407 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
1408 ? "" : (char *) b->b_ffname);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1409 else if (strncmp(s, "number", 6) == 0)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1410 lua_pushinteger(L, b->b_fnum);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1411 // methods
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1412 else if (strncmp(s, "insert", 6) == 0
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1413 || strncmp(s, "next", 4) == 0
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1414 || strncmp(s, "previous", 8) == 0
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1415 || strncmp(s, "isvalid", 7) == 0)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1416 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1417 lua_getmetatable(L, 1);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1418 lua_getfield(L, -1, s);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1419 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1420 else
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1421 lua_pushnil(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1422 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1423 else
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1424 lua_pushnil(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1425 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1426 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1427
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1428 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1429 luaV_buffer_newindex(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1430 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1431 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
1432 linenr_T n = (linenr_T) luaL_checkinteger(L, 2);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1433 #ifdef HAVE_SANDBOX
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1434 luaV_checksandbox(L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1435 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1436 if (n < 1 || n > b->b_ml.ml_line_count)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1437 luaL_error(L, "invalid line number");
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1438 if (lua_isnil(L, 3)) // delete line
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1439 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1440 buf_T *buf = curbuf;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1441 curbuf = b;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1442 if (u_savedel(n, 1L) == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1443 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1444 curbuf = buf;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1445 luaL_error(L, "cannot save undo information");
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1446 }
20599
d571231175b4 patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents: 20456
diff changeset
1447 else if (ml_delete(n) == FAIL)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1448 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1449 curbuf = buf;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1450 luaL_error(L, "cannot delete line");
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1451 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1452 else
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1453 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1454 deleted_lines_mark(n, 1L);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1455 if (b == curwin->w_buffer) // fix cursor in current window?
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1456 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1457 if (curwin->w_cursor.lnum >= n)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1458 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1459 if (curwin->w_cursor.lnum > n)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1460 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1461 curwin->w_cursor.lnum -= 1;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1462 check_cursor_col();
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1463 }
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
1464 else
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
1465 check_cursor();
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1466 changed_cline_bef_curs();
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1467 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1468 invalidate_botline();
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1469 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1470 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1471 curbuf = buf;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1472 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1473 else if (lua_isstring(L, 3)) // update line
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1474 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1475 buf_T *buf = curbuf;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1476 curbuf = b;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1477 if (u_savesub(n) == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1478 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1479 curbuf = buf;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1480 luaL_error(L, "cannot save undo information");
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1481 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1482 else if (ml_replace(n, luaV_toline(L, 3), TRUE) == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1483 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1484 curbuf = buf;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1485 luaL_error(L, "cannot replace line");
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1486 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1487 else changed_bytes(n, 0);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1488 curbuf = buf;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1489 if (b == curwin->w_buffer)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1490 check_cursor_col();
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1491 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1492 else
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1493 luaL_error(L, "wrong argument to change line");
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1494 return 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1495 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1496
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1497 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1498 luaV_buffer_insert(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1499 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1500 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
1501 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
1502 linenr_T last = b->b_ml.ml_line_count;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1503 linenr_T n = (linenr_T) luaL_optinteger(L, 3, last);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1504 buf_T *buf;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1505 luaL_checktype(L, 2, LUA_TSTRING);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1506 #ifdef HAVE_SANDBOX
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1507 luaV_checksandbox(L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1508 #endif
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1509 // fix insertion line
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1510 if (n < 0) n = 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1511 if (n > last) n = last;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1512 // insert
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1513 buf = curbuf;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1514 curbuf = b;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1515 if (u_save(n, n + 1) == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1516 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1517 curbuf = buf;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1518 luaL_error(L, "cannot save undo information");
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1519 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1520 else if (ml_append(n, luaV_toline(L, 2), 0, FALSE) == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1521 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1522 curbuf = buf;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1523 luaL_error(L, "cannot insert line");
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1524 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1525 else
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1526 appended_lines_mark(n, 1L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1527 curbuf = buf;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1528 update_screen(VALID);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1529 return 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1530 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1531
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1532 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1533 luaV_buffer_next(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1534 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1535 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
1536 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
1537 luaV_pushbuffer(L, buf->b_next);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1538 return 1;
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_buffer_previous(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_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
1545 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
1546 luaV_pushbuffer(L, buf->b_prev);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1547 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1548 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1549
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1550 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1551 luaV_buffer_isvalid(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1552 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1553 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
1554 luaV_getudata(L, *b);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1555 lua_pushboolean(L, !lua_isnil(L, -1));
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1556 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1557 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1558
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1559 static const luaL_Reg luaV_Buffer_mt[] = {
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1560 {"__tostring", luaV_buffer_tostring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1561 {"__len", luaV_buffer_len},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1562 {"__call", luaV_buffer_call},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1563 {"__index", luaV_buffer_index},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1564 {"__newindex", luaV_buffer_newindex},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1565 {"insert", luaV_buffer_insert},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1566 {"next", luaV_buffer_next},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1567 {"previous", luaV_buffer_previous},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1568 {"isvalid", luaV_buffer_isvalid},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1569 {NULL, NULL}
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1570 };
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1571
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1572
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1573 // ======= Window type =======
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1574
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1575 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
1576 luaV_pushtype(win_T, window, luaV_Window)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1577 luaV_type_tostring(window, LUAVIM_WINDOW)
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1578
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1579 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1580 luaV_window_call(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1581 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1582 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
1583 lua_settop(L, 1);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1584 win_goto(w);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1585 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1586 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1587
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1588 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1589 luaV_window_index(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1590 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1591 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
1592 const char *s = luaL_checkstring(L, 2);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1593 if (strncmp(s, "buffer", 6) == 0)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1594 luaV_pushbuffer(L, w->w_buffer);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1595 else if (strncmp(s, "line", 4) == 0)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1596 lua_pushinteger(L, w->w_cursor.lnum);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1597 else if (strncmp(s, "col", 3) == 0)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1598 lua_pushinteger(L, w->w_cursor.col + 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1599 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
1600 lua_pushinteger(L, w->w_width);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1601 else if (strncmp(s, "height", 6) == 0)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1602 lua_pushinteger(L, w->w_height);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1603 // methods
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1604 else if (strncmp(s, "next", 4) == 0
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1605 || strncmp(s, "previous", 8) == 0
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1606 || strncmp(s, "isvalid", 7) == 0)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1607 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1608 lua_getmetatable(L, 1);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1609 lua_getfield(L, -1, s);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1610 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1611 else
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1612 lua_pushnil(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1613 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1614 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1615
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1616 static int
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
1617 luaV_window_newindex(lua_State *L)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1618 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1619 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
1620 const char *s = luaL_checkstring(L, 2);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1621 int v = luaL_checkinteger(L, 3);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1622 if (strncmp(s, "line", 4) == 0)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1623 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1624 #ifdef HAVE_SANDBOX
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1625 luaV_checksandbox(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1626 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1627 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
1628 luaL_error(L, "line out of range");
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1629 w->w_cursor.lnum = v;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1630 update_screen(VALID);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1631 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1632 else if (strncmp(s, "col", 3) == 0)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1633 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1634 #ifdef HAVE_SANDBOX
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1635 luaV_checksandbox(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1636 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1637 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
1638 w->w_set_curswant = TRUE;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1639 update_screen(VALID);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1640 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1641 else if (strncmp(s, "width", 5) == 0)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1642 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1643 win_T *win = curwin;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1644 #ifdef FEAT_GUI
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1645 need_mouse_correct = TRUE;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1646 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1647 curwin = w;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1648 win_setwidth(v);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1649 curwin = win;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1650 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1651 else if (strncmp(s, "height", 6) == 0)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1652 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1653 win_T *win = curwin;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1654 #ifdef FEAT_GUI
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1655 need_mouse_correct = TRUE;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1656 #endif
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1657 curwin = w;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1658 win_setheight(v);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1659 curwin = win;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1660 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1661 else
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1662 luaL_error(L, "invalid window property: `%s'", s);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1663 return 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1664 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1665
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1666 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1667 luaV_window_next(lua_State *L)
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 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
1670 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
1671 luaV_pushwindow(L, win->w_next);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1672 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1673 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1674
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1675 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1676 luaV_window_previous(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1677 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1678 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
1679 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
1680 luaV_pushwindow(L, win->w_prev);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1681 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1682 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1683
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1684 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1685 luaV_window_isvalid(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1686 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1687 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
1688 luaV_getudata(L, *w);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1689 lua_pushboolean(L, !lua_isnil(L, -1));
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1690 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1691 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1692
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1693 static const luaL_Reg luaV_Window_mt[] = {
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1694 {"__tostring", luaV_window_tostring},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1695 {"__call", luaV_window_call},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1696 {"__index", luaV_window_index},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1697 {"__newindex", luaV_window_newindex},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1698 {"next", luaV_window_next},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1699 {"previous", luaV_window_previous},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1700 {"isvalid", luaV_window_isvalid},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1701 {NULL, NULL}
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
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1704
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1705 // ======= Vim module =======
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1706
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1707 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1708 luaV_print(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1709 {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1710 int i, n = lua_gettop(L); // nargs
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1711 const char *s;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1712 size_t l;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1713 luaL_Buffer b;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1714 luaL_buffinit(L, &b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1715 lua_getglobal(L, "tostring");
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1716 for (i = 1; i <= n; i++)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1717 {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1718 lua_pushvalue(L, -1); // tostring
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1719 lua_pushvalue(L, i); // arg
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1720 lua_call(L, 1, 1);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1721 s = lua_tolstring(L, -1, &l);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1722 if (s == NULL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1723 return luaL_error(L, "cannot convert to string");
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1724 if (i > 1) luaL_addchar(&b, ' '); // use space instead of tab
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1725 luaV_addlstring(&b, s, l, 0);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1726 lua_pop(L, 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1727 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1728 luaL_pushresult(&b);
18370
026034963159 patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
1729 if (!got_int)
026034963159 patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
1730 luaV_msg(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1731 return 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1732 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1733
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1734 static int
3091
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1735 luaV_debug(lua_State *L)
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1736 {
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1737 lua_settop(L, 0);
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1738 lua_getglobal(L, "vim");
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1739 lua_getfield(L, -1, "eval");
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1740 lua_remove(L, -2); // vim.eval at position 1
3091
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1741 for (;;)
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1742 {
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1743 const char *input;
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1744 size_t l;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1745 lua_pushvalue(L, 1); // vim.eval
3091
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1746 lua_pushliteral(L, "input('lua_debug> ')");
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1747 lua_call(L, 1, 1); // return string
3091
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1748 input = lua_tolstring(L, -1, &l);
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1749 if (l == 0 || strcmp(input, "cont") == 0)
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1750 return 0;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1751 msg_putchar('\n'); // avoid outputting on input line
3091
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1752 if (luaL_loadbuffer(L, input, l, "=(debug command)")
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1753 || lua_pcall(L, 0, 0, 0))
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1754 luaV_emsg(L);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1755 lua_settop(L, 1); // remove eventual returns, but keep vim.eval
3091
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1756 }
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1757 }
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1758
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
1759 static int
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1760 luaV_command(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1761 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1762 do_cmdline_cmd((char_u *) luaL_checkstring(L, 1));
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1763 update_screen(VALID);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1764 return 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1765 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1766
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1767 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1768 luaV_eval(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1769 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1770 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
1771 if (tv == NULL) luaL_error(L, "invalid expression");
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1772 luaV_pushtypval(L, tv);
4293
af3a3680fc75 updated for version 7.3.896
Bram Moolenaar <bram@vim.org>
parents: 4270
diff changeset
1773 free_tv(tv);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1774 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1775 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1776
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1777 static int
2331
3840b7508835 Make it easier to build with Lua. Remove compiler warnings.
Bram Moolenaar <bram@vim.org>
parents: 2330
diff changeset
1778 luaV_beep(lua_State *L UNUSED)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1779 {
6949
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6887
diff changeset
1780 vim_beep(BO_LANG);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1781 return 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1782 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1783
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1784 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1785 luaV_line(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1786 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1787 luaV_pushline(L, curbuf, curwin->w_cursor.lnum);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1788 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1789 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1790
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1791 static int
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1792 luaV_list(lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1793 {
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1794 list_T *l;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1795 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
1796
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1797 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
1798 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
1799 l = list_alloc();
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1800 if (l == NULL)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1801 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1802 else
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1803 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1804 luaV_newlist(L, l);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1805 if (initarg) // traverse table to init list
14335
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
1806 {
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1807 int notnil, i = 0;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1808 typval_T v;
14335
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
1809 do
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
1810 {
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1811 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
1812 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
1813 if (notnil)
d59bf91128ea patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents: 14329
diff changeset
1814 {
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1815 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
1816 list_append_tv(l, &v);
16009
3b524e8110ab patch 8.1.1010: Lua interface leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 15868
diff changeset
1817 clear_tv(&v);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1818 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1819 lua_pop(L, 1); // value
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1820 } while (notnil);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1821 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1822 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1823 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1824 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1825
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1826 static int
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1827 luaV_dict(lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1828 {
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1829 dict_T *d;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1830 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
1831
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1832 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
1833 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
1834 d = dict_alloc();
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1835 if (d == NULL)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1836 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1837 else
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1838 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1839 luaV_newdict(L, d);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1840 if (initarg) // traverse table to init dict
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1841 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1842 lua_pushnil(L);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1843 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
1844 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1845 char_u *key;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1846 dictitem_T *di;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1847 typval_T v;
14329
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1848
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1849 lua_pushvalue(L, -2); // dup key in case it's a number
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1850 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
1851 if (key == NULL)
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1852 {
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1853 lua_pushnil(L);
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1854 return 1;
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1855 }
fe651f98e173 patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
1856 if (*key == NUL)
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1857 luaL_error(L, "table has empty key");
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1858 luaV_checktypval(L, -2, &v, "vim.dict"); // value
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1859 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
1860 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
1861 {
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1862 vim_free(di);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1863 lua_pushnil(L);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1864 return 1;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1865 }
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
1866 di->di_tv = v;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1867 lua_pop(L, 2); // key copy and value
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1868 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1869 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1870 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1871 return 1;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1872 }
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1873
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1874 static int
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1875 luaV_blob(lua_State *L)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1876 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1877 blob_T *b;
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1878 int initarg = !lua_isnoneornil(L, 1);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1879
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1880 if (initarg && !lua_isstring(L, 1))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1881 luaL_error(L, "string expected, got %s", luaL_typename(L, 1));
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1882 b = blob_alloc();
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1883 if (b == NULL)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1884 lua_pushnil(L);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1885 else
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1886 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1887 luaV_newblob(L, b);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1888 if (initarg)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1889 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1890 size_t i, l = 0;
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1891 const char *s = lua_tolstring(L, 1, &l);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1892
19372
967149bbd8d3 patch 8.2.0244: compiler warning in Lua interface
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
1893 if (ga_grow(&b->bv_ga, (int)l) == OK)
16099
643fe07aa0e2 patch 8.1.1054: not checking return value of ga_grow()
Bram Moolenaar <Bram@vim.org>
parents: 16076
diff changeset
1894 for (i = 0; i < l; ++i)
643fe07aa0e2 patch 8.1.1054: not checking return value of ga_grow()
Bram Moolenaar <Bram@vim.org>
parents: 16076
diff changeset
1895 ga_append(&b->bv_ga, s[i]);
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1896 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1897 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1898 return 1;
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1899 }
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1900
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1901 static int
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1902 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
1903 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1904 const char *name = luaL_checkstring(L, 1);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1905 // note: not checking if function exists (needs function_exists)
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1906 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
1907 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
1908 luaV_newfuncref(L, (char_u *) name);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1909 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1910 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1911
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1912 static int
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1913 luaV_buffer(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1914 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1915 buf_T *buf;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1916 if (lua_isstring(L, 1)) // get by number or name?
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1917 {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1918 if (lua_isnumber(L, 1)) // by number?
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1919 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1920 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
1921 FOR_ALL_BUFFERS(buf)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1922 if (buf->b_fnum == n) break;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1923 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1924 else // by name
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
1925 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1926 size_t l;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1927 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
1928 FOR_ALL_BUFFERS(buf)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1929 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1930 if (buf->b_ffname == NULL || buf->b_sfname == NULL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1931 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1932 if (l == 0) break;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1933 }
2331
3840b7508835 Make it easier to build with Lua. Remove compiler warnings.
Bram Moolenaar <bram@vim.org>
parents: 2330
diff changeset
1934 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
1935 || strncmp(s, (char *)buf->b_sfname, l) == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1936 break;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1937 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1938 }
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1939 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1940 else
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1941 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
1942 luaV_pushbuffer(L, buf);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1943 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1944 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1945
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1946 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1947 luaV_window(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1948 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1949 win_T *win;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1950 if (lua_isnumber(L, 1)) // get by number?
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1951 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1952 int n = lua_tointeger(L, 1);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1953 for (win = firstwin; win != NULL; win = win->w_next, n--)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1954 if (n == 1) break;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1955 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1956 else
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1957 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
1958 luaV_pushwindow(L, win);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1959 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1960 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1961
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1962 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1963 luaV_open(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1964 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1965 char_u *s = NULL;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1966 #ifdef HAVE_SANDBOX
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1967 luaV_checksandbox(L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1968 #endif
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1969 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
1970 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
1971 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1972 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1973
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1974 static int
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1975 luaV_type(lua_State *L)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
1976 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1977 luaL_checkany(L, 1);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1978 if (lua_type(L, 1) == LUA_TUSERDATA) // check vim udata?
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1979 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1980 lua_settop(L, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1981 if (lua_getmetatable(L, 1))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1982 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1983 luaV_getfield(L, LUAVIM_LIST);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1984 if (lua_rawequal(L, -1, 2))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1985 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1986 lua_pushstring(L, "list");
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1987 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1988 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1989 luaV_getfield(L, LUAVIM_DICT);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1990 if (lua_rawequal(L, -1, 2))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1991 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1992 lua_pushstring(L, "dict");
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1993 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
1994 }
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1995 luaV_getfield(L, LUAVIM_BLOB);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1996 if (lua_rawequal(L, -1, 2))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1997 {
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1998 lua_pushstring(L, "blob");
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
1999 return 1;
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
2000 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
2001 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
2002 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
2003 {
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
2004 lua_pushstring(L, "funcref");
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
2005 return 1;
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
2006 }
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2007 luaV_getfield(L, LUAVIM_BUFFER);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2008 if (lua_rawequal(L, -1, 2))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2009 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2010 lua_pushstring(L, "buffer");
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2011 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2012 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2013 luaV_getfield(L, LUAVIM_WINDOW);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2014 if (lua_rawequal(L, -1, 2))
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2015 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2016 lua_pushstring(L, "window");
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2017 return 1;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2018 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2019 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2020 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2021 lua_pushstring(L, luaL_typename(L, 1)); // fallback
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2022 return 1;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2023 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2024
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2025 static int
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2026 luaV_call(lua_State *L)
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2027 {
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2028 int argc = lua_gettop(L) - 1;
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2029 size_t funcname_len;
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2030 char_u *funcname;
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2031 char *error = NULL;
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2032 typval_T rettv;
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2033 typval_T argv[MAX_FUNC_ARGS + 1];
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2034 int i = 0;
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2035
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2036 if (argc > MAX_FUNC_ARGS)
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2037 return luaL_error(L, "Function called with too many arguments");
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2038
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2039 funcname = (char_u *)luaL_checklstring(L, 1, &funcname_len);
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2040
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2041 for (; i < argc; i++)
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2042 {
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2043 if (luaV_totypval(L, i + 2, &argv[i]) == FAIL)
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2044 {
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2045 error = "lua: cannot convert value";
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2046 goto free_vim_args;
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2047 }
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2048 }
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2049
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2050 argv[argc].v_type = VAR_UNKNOWN;
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2051
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2052 if (call_vim_function(funcname, argc, argv, &rettv) == FAIL)
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2053 {
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2054 error = "lua: call_vim_function failed";
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2055 goto free_vim_args;
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2056 }
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2057
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2058 luaV_pushtypval(L, &rettv);
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2059 clear_tv(&rettv);
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2060
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2061 free_vim_args:
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2062 while (i > 0)
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2063 clear_tv(&argv[--i]);
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2064
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2065 if (error == NULL)
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2066 return 1;
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2067 else
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2068 return luaL_error(L, error);
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2069 }
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2070
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2071 static const luaL_Reg luaV_module[] = {
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2072 {"command", luaV_command},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2073 {"eval", luaV_eval},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2074 {"beep", luaV_beep},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2075 {"line", luaV_line},
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2076 {"list", luaV_list},
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2077 {"dict", luaV_dict},
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
2078 {"blob", luaV_blob},
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
2079 {"funcref", luaV_funcref},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2080 {"buffer", luaV_buffer},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2081 {"window", luaV_window},
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2082 {"open", luaV_open},
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2083 {"type", luaV_type},
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2084 {"call", luaV_call},
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2085 {NULL, NULL}
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
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2088 /*
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2089 * for freeing list, dict, buffer and window objects; lightuserdata as arg
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2090 */
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2091 static int
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2092 luaV_free(lua_State *L)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2093 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2094 lua_pushnil(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2095 luaV_setudata(L, lua_touserdata(L, 1));
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2096 return 0;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2097 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2098
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2099 static int
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2100 luaV_luaeval(lua_State *L)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2101 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2102 luaL_Buffer b;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2103 size_t l;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2104 const char *str = lua_tolstring(L, 1, &l);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2105 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
2106 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
2107 luaL_buffinit(L, &b);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2108 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
2109 luaL_addlstring(&b, str, l);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2110 luaL_pushresult(&b);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2111 str = lua_tolstring(L, -1, &l);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2112 if (luaL_loadbuffer(L, str, l, LUAVIM_EVALNAME)) // compile error?
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2113 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2114 luaV_emsg(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2115 return 0;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2116 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2117 luaV_pushtypval(L, arg);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2118 if (lua_pcall(L, 1, 1, 0)) // running error?
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2119 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2120 luaV_emsg(L);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2121 return 0;
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2122 }
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
2123 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
2124 emsg("luaeval: cannot convert value");
6590
f884a1140a0a updated for version 7.4.621
Bram Moolenaar <bram@vim.org>
parents: 6586
diff changeset
2125 return 0;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2126 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2127
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2128 static int
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2129 luaV_setref(lua_State *L)
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2130 {
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2131 int copyID = lua_tointeger(L, 1);
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2132 int abort = FALSE;
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2133
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2134 luaV_getfield(L, LUAVIM_LIST);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2135 luaV_getfield(L, LUAVIM_DICT);
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2136 luaV_getfield(L, LUAVIM_FUNCREF);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2137 lua_pushnil(L);
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2138 // traverse cache table
6586
9ac723b9f54d updated for version 7.4.619
Bram Moolenaar <bram@vim.org>
parents: 6584
diff changeset
2139 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
2140 {
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2141 lua_getmetatable(L, -1);
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2142 if (lua_rawequal(L, -1, 2)) // list?
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2143 {
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2144 list_T *l = (list_T *)lua_touserdata(L, 5); // key
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2145
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 16099
diff changeset
2146 abort = set_ref_in_list(l, copyID);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2147 }
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2148 else if (lua_rawequal(L, -1, 3)) // dict?
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2149 {
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2150 dict_T *d = (dict_T *)lua_touserdata(L, 5); // key
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2151
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 16099
diff changeset
2152 abort = set_ref_in_dict(d, copyID);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2153 }
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2154 else if (lua_rawequal(L, -1, 4)) // funcref?
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2155 {
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2156 luaV_Funcref *f = (luaV_Funcref *)lua_touserdata(L, 5); // key
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2157
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 16099
diff changeset
2158 abort = set_ref_in_dict(f->self, copyID);
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2159 }
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2160 lua_pop(L, 2); // metatable and value
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2161 }
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2162 lua_pushinteger(L, abort);
6590
f884a1140a0a updated for version 7.4.621
Bram Moolenaar <bram@vim.org>
parents: 6586
diff changeset
2163 return 1;
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2164 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2165
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2166 #define LUA_VIM_FN_CODE \
20609
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2167 "vim.fn = setmetatable({}, {\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2168 " __index = function (t, key)\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2169 " local function _fn(...)\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2170 " return vim.call(key, ...)\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2171 " end\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2172 " t[key] = _fn\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2173 " return _fn\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2174 " end\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2175 " })"
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2176
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2177 #define LUA_VIM_UPDATE_PACKAGE_PATHS \
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2178 "local last_vim_paths = {}\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2179 "vim._update_package_paths = function ()\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2180 " local cur_vim_paths = {}\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2181 " local function split(s, delimiter)\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2182 " result = {}\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2183 " for match in (s..delimiter):gmatch(\"(.-)\"..delimiter) do\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2184 " table.insert(result, match)\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2185 " end\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2186 " return result\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2187 " end\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2188 " local rtps = split(vim.eval('&runtimepath'), ',')\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2189 " local sep = package.config:sub(1, 1)\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2190 " for _, key in ipairs({'path', 'cpath'}) do\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2191 " local orig_str = package[key] .. ';'\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2192 " local pathtrails_ordered = {}\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2193 " -- Note: ignores trailing item without trailing `;`. Not using something\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2194 " -- simpler in order to preserve empty items (stand for default path).\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2195 " local orig = {}\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2196 " for s in orig_str:gmatch('[^;]*;') do\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2197 " s = s:sub(1, -2) -- Strip trailing semicolon\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2198 " orig[#orig + 1] = s\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2199 " end\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2200 " if key == 'path' then\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2201 " -- /?.lua and /?/init.lua\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2202 " pathtrails_ordered = {sep .. '?.lua', sep .. '?' .. sep .. 'init.lua'}\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2203 " else\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2204 " local pathtrails = {}\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2205 " for _, s in ipairs(orig) do\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2206 " -- Find out path patterns. pathtrail should contain something like\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2207 " -- /?.so, \?.dll. This allows not to bother determining what correct\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2208 " -- suffixes are.\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2209 " local pathtrail = s:match('[/\\\\][^/\\\\]*%?.*$')\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2210 " if pathtrail and not pathtrails[pathtrail] then\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2211 " pathtrails[pathtrail] = true\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2212 " pathtrails_ordered[#pathtrails_ordered + 1] = pathtrail\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2213 " end\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2214 " end\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2215 " end\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2216 " local new = {}\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2217 " for _, rtp in ipairs(rtps) do\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2218 " if not rtp:match(';') then\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2219 " for _, pathtrail in pairs(pathtrails_ordered) do\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2220 " local new_path = rtp .. sep .. 'lua' .. pathtrail\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2221 " -- Always keep paths from &runtimepath at the start:\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2222 " -- append them here disregarding orig possibly containing one of them.\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2223 " new[#new + 1] = new_path\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2224 " cur_vim_paths[new_path] = true\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2225 " end\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2226 " end\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2227 " end\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2228 " for _, orig_path in ipairs(orig) do\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2229 " -- Handle removing obsolete paths originating from &runtimepath: such\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2230 " -- paths either belong to cur_nvim_paths and were already added above or\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2231 " -- to last_nvim_paths and should not be added at all if corresponding\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2232 " -- entry was removed from &runtimepath list.\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2233 " if not (cur_vim_paths[orig_path] or last_vim_paths[orig_path]) then\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2234 " new[#new + 1] = orig_path\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2235 " end\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2236 " end\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2237 " package[key] = table.concat(new, ';')\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2238 " end\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2239 " last_vim_paths = cur_vim_paths\n"\
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2240 "end"
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2241
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2242 static int
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2243 luaopen_vim(lua_State *L)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2244 {
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2245 // set cache table
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2246 lua_newtable(L);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2247 lua_newtable(L);
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2248 lua_pushstring(L, "v");
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2249 lua_setfield(L, -2, "__mode");
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2250 lua_setmetatable(L, -2); // cache is weak-valued
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2251 // print
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2252 lua_pushcfunction(L, luaV_print);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2253 lua_setglobal(L, "print");
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2254 // debug.debug
3091
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
2255 lua_getglobal(L, "debug");
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
2256 lua_pushcfunction(L, luaV_debug);
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
2257 lua_setfield(L, -2, "debug");
92a181a1cec3 updated for version 7.3.317
Bram Moolenaar <bram@vim.org>
parents: 2683
diff changeset
2258 lua_pop(L, 1);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2259 // free
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2260 lua_pushlightuserdata(L, (void *) LUAVIM_FREE);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2261 lua_pushvalue(L, 1); // cache table
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2262 lua_pushcclosure(L, luaV_free, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2263 lua_rawset(L, LUA_REGISTRYINDEX);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2264 // luaeval
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2265 lua_pushlightuserdata(L, (void *) LUAVIM_LUAEVAL);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2266 lua_pushvalue(L, 1); // cache table
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2267 lua_pushcclosure(L, luaV_luaeval, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2268 lua_rawset(L, LUA_REGISTRYINDEX);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2269 // setref
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2270 lua_pushlightuserdata(L, (void *) LUAVIM_SETREF);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2271 lua_pushvalue(L, 1); // cache table
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2272 lua_pushcclosure(L, luaV_setref, 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2273 lua_rawset(L, LUA_REGISTRYINDEX);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2274 // register
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2275 luaV_newmetatable(L, LUAVIM_LIST);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2276 lua_pushvalue(L, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2277 luaV_openlib(L, luaV_List_mt, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2278 luaV_newmetatable(L, LUAVIM_DICT);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2279 lua_pushvalue(L, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2280 luaV_openlib(L, luaV_Dict_mt, 1);
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
2281 luaV_newmetatable(L, LUAVIM_BLOB);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
2282 lua_pushvalue(L, 1);
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
2283 luaV_openlib(L, luaV_Blob_mt, 1);
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
2284 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
2285 lua_pushvalue(L, 1);
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
2286 luaV_openlib(L, luaV_Funcref_mt, 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2287 luaV_newmetatable(L, LUAVIM_BUFFER);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2288 lua_pushvalue(L, 1); // cache table
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2289 luaV_openlib(L, luaV_Buffer_mt, 1);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2290 luaV_newmetatable(L, LUAVIM_WINDOW);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2291 lua_pushvalue(L, 1); // cache table
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2292 luaV_openlib(L, luaV_Window_mt, 1);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2293 lua_newtable(L); // vim table
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2294 lua_pushvalue(L, 1); // cache table
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2295 luaV_openlib(L, luaV_module, 1);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2296 lua_setglobal(L, LUAVIM_NAME);
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 19846
diff changeset
2297 // custom code
20454
070c8a22261d patch 8.2.0781: compiler warning for not using value in Lua
Bram Moolenaar <Bram@vim.org>
parents: 20441
diff changeset
2298 (void)luaL_dostring(L, LUA_VIM_FN_CODE);
20609
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2299 (void)luaL_dostring(L, LUA_VIM_UPDATE_PACKAGE_PATHS);
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2300
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2301 lua_getglobal(L, "vim");
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2302 lua_getfield(L, -1, "_update_package_paths");
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2303
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2304 if (lua_pcall(L, 0, 0, 0))
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2305 luaV_emsg(L);
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2306
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2307 return 0;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2308 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2309
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2310 static lua_State *
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2311 luaV_newstate(void)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2312 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2313 lua_State *L = luaL_newstate();
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2314 luaL_openlibs(L); // core libs
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2315 lua_pushcfunction(L, luaopen_vim); // vim
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2316 lua_call(L, 0, 0);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2317 return L;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2318 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2319
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2320 static void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2321 luaV_setrange(lua_State *L, int line1, int line2)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2322 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2323 lua_getglobal(L, LUAVIM_NAME);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2324 lua_pushinteger(L, line1);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2325 lua_setfield(L, -2, "firstline");
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2326 lua_pushinteger(L, line2);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2327 lua_setfield(L, -2, "lastline");
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2328 lua_pop(L, 1); // vim table
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2329 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2330
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2331
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2332 // ======= Interface =======
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2333
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2334 static lua_State *L = NULL;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2335
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2336 static int
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2337 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
2338 {
8c512e2c7cb5 Fix: Lua interface tried to load the library when closing a buffer or window.
Bram Moolenaar <bram@vim.org>
parents: 2431
diff changeset
2339 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
2340 }
8c512e2c7cb5 Fix: Lua interface tried to load the library when closing a buffer or window.
Bram Moolenaar <bram@vim.org>
parents: 2431
diff changeset
2341
8c512e2c7cb5 Fix: Lua interface tried to load the library when closing a buffer or window.
Bram Moolenaar <bram@vim.org>
parents: 2431
diff changeset
2342 static int
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2343 lua_init(void)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2344 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2345 if (!lua_isopen())
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2346 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2347 #ifdef DYNAMIC_LUA
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2348 if (!lua_enabled(TRUE))
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2349 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15328
diff changeset
2350 emsg(_("Lua library cannot be loaded."));
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2351 return FAIL;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2352 }
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2353 #endif
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2354 L = luaV_newstate();
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2355 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2356 return OK;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2357 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2358
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2359 void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2360 lua_end(void)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2361 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2362 if (lua_isopen())
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2363 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2364 lua_close(L);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2365 L = NULL;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2366 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2367 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2368
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2369 /*
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2370 * ex commands
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2371 */
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2372 void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2373 ex_lua(exarg_T *eap)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2374 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2375 char *script;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2376 if (lua_init() == FAIL) return;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2377 script = (char *) script_get(eap, eap->arg);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2378 if (!eap->skip)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2379 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2380 char *s = (script) ? script : (char *) eap->arg;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2381 luaV_setrange(L, eap->line1, eap->line2);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2382 if (luaL_loadbuffer(L, s, strlen(s), LUAVIM_CHUNKNAME)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2383 || lua_pcall(L, 0, 0, 0))
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2384 luaV_emsg(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2385 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2386 if (script != NULL) vim_free(script);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2387 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2388
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2389 void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2390 ex_luado(exarg_T *eap)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2391 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2392 linenr_T l;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2393 const char *s = (const char *) eap->arg;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2394 luaL_Buffer b;
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2395 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
2396 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
2397
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2398 if (lua_init() == FAIL) return;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2399 if (u_save(eap->line1 - 1, eap->line2 + 1) == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2400 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15328
diff changeset
2401 emsg(_("cannot save undo information"));
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2402 return;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2403 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2404 luaV_setrange(L, eap->line1, eap->line2);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2405 luaL_buffinit(L, &b);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2406 luaL_addlstring(&b, "return function(line, linenr) ", 30); // header
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2407 luaL_addlstring(&b, s, strlen(s));
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2408 luaL_addlstring(&b, " end", 4); // footer
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2409 luaL_pushresult(&b);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2410 s = lua_tolstring(L, -1, &len);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2411 if (luaL_loadbuffer(L, s, len, LUAVIM_CHUNKNAME))
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2412 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2413 luaV_emsg(L);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2414 lua_pop(L, 1); // function body
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2415 return;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2416 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2417 lua_call(L, 0, 1);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2418 lua_replace(L, -2); // function -> body
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2419 for (l = eap->line1; l <= eap->line2; l++)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2420 {
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
2421 // Check the line number, the command may have deleted lines.
10757
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10025
diff changeset
2422 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
2423 break;
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10025
diff changeset
2424
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2425 lua_pushvalue(L, -1); // function
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2426 luaV_pushline(L, curbuf, l); // current line as arg
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2427 lua_pushinteger(L, l); // current line number as arg
3459
5240610f2778 updated for version 7.3.494
Bram Moolenaar <bram@vim.org>
parents: 3450
diff changeset
2428 if (lua_pcall(L, 2, 1, 0))
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2429 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2430 luaV_emsg(L);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2431 break;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2432 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2433 // Catch the command switching to another buffer.
10757
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents: 10025
diff changeset
2434 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
2435 break;
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2436 if (lua_isstring(L, -1)) // update line?
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2437 {
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2438 #ifdef HAVE_SANDBOX
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2439 luaV_checksandbox(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2440 #endif
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2441 ml_replace(l, luaV_toline(L, -1), TRUE);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2442 changed_bytes(l, 0);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2443 lua_pop(L, 1); // result from luaV_toline
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2444 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2445 lua_pop(L, 1); // line
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2446 }
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2447 lua_pop(L, 1); // function
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2448 check_cursor();
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2449 update_screen(NOT_VALID);
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2450 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2451
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2452 void
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2453 ex_luafile(exarg_T *eap)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2454 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2455 if (lua_init() == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2456 return;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2457 if (!eap->skip)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2458 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2459 luaV_setrange(L, eap->line1, eap->line2);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2460 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
2461 luaV_emsg(L);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2462 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2463 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2464
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2465 #define luaV_freetype(typ,tname) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2466 void \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2467 lua_##tname##_free(typ *o) \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2468 { \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2469 if (!lua_isopen()) return; \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2470 luaV_getfield(L, LUAVIM_FREE); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2471 lua_pushlightuserdata(L, (void *) o); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2472 lua_call(L, 1, 0); \
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2473 }
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2474
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2475 luaV_freetype(buf_T, buffer)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2476 luaV_freetype(win_T, window)
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2477
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2478 void
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2479 do_luaeval(char_u *str, typval_T *arg, typval_T *rettv)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2480 {
3450
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2481 lua_init();
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2482 luaV_getfield(L, LUAVIM_LUAEVAL);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2483 lua_pushstring(L, (char *) str);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2484 lua_pushlightuserdata(L, (void *) arg);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2485 lua_pushlightuserdata(L, (void *) rettv);
b067b8b81be9 updated for version 7.3.490
Bram Moolenaar <bram@vim.org>
parents: 3200
diff changeset
2486 lua_call(L, 3, 0);
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2487 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2488
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2489 int
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 16009
diff changeset
2490 set_ref_in_lua(int copyID)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2320
diff changeset
2491 {
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2492 int aborted = 0;
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2493
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2494 if (lua_isopen())
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2495 {
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2496 luaV_getfield(L, LUAVIM_SETREF);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2497 // call the function with 1 arg, getting 1 result back
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2498 lua_pushinteger(L, copyID);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2499 lua_call(L, 1, 1);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2500 // get the result
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2501 aborted = lua_tointeger(L, -1);
18798
f0f9692d4487 patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2502 // pop result off the stack
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2503 lua_pop(L, 1);
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2504 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
2505 return aborted;
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2506 }
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2507
20609
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2508 void
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2509 update_package_paths_in_lua()
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2510 {
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2511 if (lua_isopen())
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2512 {
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2513 lua_getglobal(L, "vim");
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2514 lua_getfield(L, -1, "_update_package_paths");
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2515
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2516 if (lua_pcall(L, 0, 0, 0))
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2517 luaV_emsg(L);
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2518 }
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2519 }
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
2520
21006
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2521 /*
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2522 * Native C function callback
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2523 */
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2524 static int
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2525 luaV_call_lua_func(
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2526 int argcount,
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2527 typval_T *argvars,
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2528 typval_T *rettv,
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2529 void *state)
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2530 {
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2531 int i;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2532 int luaargcount = argcount;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2533 luaV_CFuncState *funcstate = (luaV_CFuncState*)state;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2534 lua_rawgeti(funcstate->L, LUA_REGISTRYINDEX, funcstate->lua_funcref);
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2535
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2536 if (funcstate->lua_tableref != LUA_NOREF)
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2537 {
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2538 // First arg for metatable __call method is a table
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2539 luaargcount += 1;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2540 lua_rawgeti(funcstate->L, LUA_REGISTRYINDEX, funcstate->lua_tableref);
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2541 }
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2542
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2543 for (i = 0; i < argcount; ++i)
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2544 luaV_pushtypval(funcstate->L, &argvars[i]);
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2545
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2546 if (lua_pcall(funcstate->L, luaargcount, 1, 0))
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2547 {
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2548 luaV_emsg(funcstate->L);
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2549 return FCERR_OTHER;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2550 }
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2551
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2552 luaV_checktypval(funcstate->L, -1, rettv, "get return value");
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2553 return FCERR_NONE;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2554 }
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2555
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2556 /*
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2557 * Free up any lua references held by the func state.
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2558 */
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2559 static void
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2560 luaV_call_lua_func_free(void *state)
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2561 {
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2562 luaV_CFuncState *funcstate = (luaV_CFuncState*)state;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2563 luaL_unref(L, LUA_REGISTRYINDEX, funcstate->lua_funcref);
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2564 funcstate->L = NULL;
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2565 if (funcstate->lua_tableref != LUA_NOREF)
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2566 luaL_unref(L, LUA_REGISTRYINDEX, funcstate->lua_tableref);
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2567 VIM_CLEAR(funcstate);
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2568 }
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
2569
2320
966a5609669e Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2570 #endif