Mercurial > vim
annotate src/if_lua.c @ 33774:f2dd85a2bfc0 v9.0.2107
patch 9.0.2107: [security]: FPE in adjust_plines_for_skipcol
Commit: https://github.com/vim/vim/commit/cb0b99f0672d8446585d26e998343dceca17d1ce
Author: Christian Brabandt <cb@256bit.org>
Date: Tue Nov 14 20:05:59 2023 +0100
patch 9.0.2107: [security]: FPE in adjust_plines_for_skipcol
Problem: [security]: FPE in adjust_plines_for_skipcol
Solution: don't divide by zero, return zero
Prevent a floating point exception when calculating w_skipcol (which can
happen with a small window when the number option is set and cpo+=n).
Add a test to verify
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 16 Nov 2023 22:15:08 +0100 |
parents | 1a769647d661 |
children | daaff6843090 |
rev | line source |
---|---|
3450 | 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 | 12 #include "vim.h" |
25527
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
13 #include "version.h" |
2683 | 14 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
15 #include <lua.h> |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
16 #include <lualib.h> |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
17 #include <lauxlib.h> |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
18 |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
19 #if __STDC_VERSION__ >= 199901L |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
20 # define LUAV_INLINE inline |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
21 #else |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
22 # define LUAV_INLINE |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
23 #endif |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
24 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
25 // 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
|
26 // depend". |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
27 #if defined(FEAT_LUA) || defined(PROTO) |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
28 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
29 #define LUAVIM_CHUNKNAME "vim chunk" |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
30 #define LUAVIM_NAME "vim" |
3450 | 31 #define LUAVIM_EVALNAME "luaeval" |
32 #define LUAVIM_EVALHEADER "local _A=select(1,...) return " | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
33 |
24385
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
34 #ifdef LUA_RELEASE |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
35 # define LUAVIM_VERSION LUA_RELEASE |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
36 #else |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
37 # define LUAVIM_VERSION LUA_VERSION |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
38 #endif |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
39 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
40 typedef buf_T *luaV_Buffer; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
41 typedef win_T *luaV_Window; |
3450 | 42 typedef dict_T *luaV_Dict; |
43 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
|
44 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
|
45 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
|
46 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
|
47 dict_T *self; // selfdict |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
48 } luaV_Funcref; |
22719
8da5e18effc5
patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents:
21367
diff
changeset
|
49 typedef int (*msgfunc_T)(char *); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
50 |
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
|
51 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
|
52 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
|
53 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
|
54 // 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
|
55 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
|
56 } 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
|
57 |
3450 | 58 static const char LUAVIM_DICT[] = "dict"; |
59 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
|
60 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
|
61 static const char LUAVIM_FUNCREF[] = "funcref"; |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
62 static const char LUAVIM_BUFFER[] = "buffer"; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
63 static const char LUAVIM_WINDOW[] = "window"; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
64 static const char LUAVIM_FREE[] = "luaV_free"; |
3450 | 65 static const char LUAVIM_LUAEVAL[] = "luaV_luaeval"; |
66 static const char LUAVIM_SETREF[] = "luaV_setref"; | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
67 |
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
|
68 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
|
69 |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
70 // get/setudata manage references to vim userdata in a cache table through |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
71 // object pointers (light userdata). The cache table itself is retrieved |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
72 // from the registry. |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
73 |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
74 static const char LUAVIM_UDATA_CACHE[] = "luaV_udata_cache"; |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
75 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
76 #define luaV_getfield(L, s) \ |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
77 lua_pushlightuserdata((L), (void *)(s)); \ |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
78 lua_rawget((L), LUA_REGISTRYINDEX) |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
79 #define luaV_checksandbox(L) \ |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
80 if (sandbox) luaL_error((L), "not allowed in sandbox") |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
81 #define luaV_msg(L) luaV_msgfunc((L), (msgfunc_T) msg) |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
82 #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
|
83 #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
|
84 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
|
85 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
|
86 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
|
87 } while (0) |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
88 |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 static void luaV_call_lua_func_free(void *state); |
3450 | 95 |
96 #if LUA_VERSION_NUM <= 501 | |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
97 #define luaV_register(L, l) luaL_register(L, NULL, l) |
3450 | 98 #define luaL_typeerror luaL_typerror |
99 #else | |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
100 #define luaV_register(L, l) luaL_setfuncs(L, l, 0) |
3450 | 101 #endif |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
102 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
103 #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
|
104 |
33531
1a769647d661
patch 9.0.2013: confusing ifdefs in if_<lang>.c
Christian Brabandt <cb@256bit.org>
parents:
33339
diff
changeset
|
105 #ifdef MSWIN |
1a769647d661
patch 9.0.2013: confusing ifdefs in if_<lang>.c
Christian Brabandt <cb@256bit.org>
parents:
33339
diff
changeset
|
106 # define load_dll vimLoadLib |
1a769647d661
patch 9.0.2013: confusing ifdefs in if_<lang>.c
Christian Brabandt <cb@256bit.org>
parents:
33339
diff
changeset
|
107 # define symbol_from_dll GetProcAddress |
1a769647d661
patch 9.0.2013: confusing ifdefs in if_<lang>.c
Christian Brabandt <cb@256bit.org>
parents:
33339
diff
changeset
|
108 # define close_dll FreeLibrary |
1a769647d661
patch 9.0.2013: confusing ifdefs in if_<lang>.c
Christian Brabandt <cb@256bit.org>
parents:
33339
diff
changeset
|
109 # define load_dll_error GetWin32Error |
1a769647d661
patch 9.0.2013: confusing ifdefs in if_<lang>.c
Christian Brabandt <cb@256bit.org>
parents:
33339
diff
changeset
|
110 #else |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2331
diff
changeset
|
111 # include <dlfcn.h> |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2331
diff
changeset
|
112 # define HANDLE void* |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2331
diff
changeset
|
113 # 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
|
114 # 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
|
115 # define close_dll dlclose |
25342
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
24385
diff
changeset
|
116 # define load_dll_error dlerror |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2331
diff
changeset
|
117 #endif |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2331
diff
changeset
|
118 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
119 // lauxlib |
3450 | 120 #if LUA_VERSION_NUM <= 501 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
121 #define luaL_register dll_luaL_register |
3450 | 122 #define luaL_prepbuffer dll_luaL_prepbuffer |
123 #define luaL_openlib dll_luaL_openlib | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
124 #define luaL_typerror dll_luaL_typerror |
3450 | 125 #define luaL_loadfile dll_luaL_loadfile |
126 #define luaL_loadbuffer dll_luaL_loadbuffer | |
127 #else | |
128 #define luaL_prepbuffsize dll_luaL_prepbuffsize | |
129 #define luaL_setfuncs dll_luaL_setfuncs | |
130 #define luaL_loadfilex dll_luaL_loadfilex | |
131 #define luaL_loadbufferx dll_luaL_loadbufferx | |
132 #define luaL_argerror dll_luaL_argerror | |
133 #endif | |
21323
5b0bbc5d4e74
patch 8.2.1212: cannot build with Lua 5.4
Bram Moolenaar <Bram@vim.org>
parents:
21132
diff
changeset
|
134 #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
|
135 #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
|
136 #endif |
3459 | 137 #define luaL_checkany dll_luaL_checkany |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
138 #define luaL_checklstring dll_luaL_checklstring |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
139 #define luaL_checkinteger dll_luaL_checkinteger |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
140 #define luaL_optinteger dll_luaL_optinteger |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
141 #define luaL_checktype dll_luaL_checktype |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
142 #define luaL_error dll_luaL_error |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
143 #define luaL_newstate dll_luaL_newstate |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
144 #define luaL_buffinit dll_luaL_buffinit |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
145 #define luaL_addlstring dll_luaL_addlstring |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
146 #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
|
147 #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
|
148 #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
|
149 #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
|
150 // lua |
3450 | 151 #if LUA_VERSION_NUM <= 501 |
152 #define lua_tonumber dll_lua_tonumber | |
153 #define lua_tointeger dll_lua_tointeger | |
154 #define lua_call dll_lua_call | |
155 #define lua_pcall dll_lua_pcall | |
156 #else | |
157 #define lua_tonumberx dll_lua_tonumberx | |
158 #define lua_tointegerx dll_lua_tointegerx | |
159 #define lua_callk dll_lua_callk | |
160 #define lua_pcallk dll_lua_pcallk | |
161 #define lua_getglobal dll_lua_getglobal | |
162 #define lua_setglobal dll_lua_setglobal | |
3459 | 163 #endif |
6887 | 164 #if LUA_VERSION_NUM <= 502 |
165 #define lua_replace dll_lua_replace | |
166 #define lua_remove dll_lua_remove | |
167 #endif | |
168 #if LUA_VERSION_NUM >= 503 | |
169 #define lua_rotate dll_lua_rotate | |
170 #define lua_copy dll_lua_copy | |
171 #endif | |
3450 | 172 #define lua_typename dll_lua_typename |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
173 #define lua_close dll_lua_close |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
174 #define lua_gettop dll_lua_gettop |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
175 #define lua_settop dll_lua_settop |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
176 #define lua_pushvalue dll_lua_pushvalue |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
177 #define lua_isnumber dll_lua_isnumber |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
178 #define lua_isstring dll_lua_isstring |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
179 #define lua_type dll_lua_type |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
180 #define lua_rawequal dll_lua_rawequal |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
181 #define lua_toboolean dll_lua_toboolean |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
182 #define lua_tolstring dll_lua_tolstring |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
183 #define lua_touserdata dll_lua_touserdata |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
184 #define lua_pushnil dll_lua_pushnil |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
185 #define lua_pushnumber dll_lua_pushnumber |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
186 #define lua_pushinteger dll_lua_pushinteger |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
187 #define lua_pushlstring dll_lua_pushlstring |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
188 #define lua_pushstring dll_lua_pushstring |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
189 #define lua_pushfstring dll_lua_pushfstring |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
190 #define lua_pushcclosure dll_lua_pushcclosure |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
191 #define lua_pushboolean dll_lua_pushboolean |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
192 #define lua_pushlightuserdata dll_lua_pushlightuserdata |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
193 #define lua_getfield dll_lua_getfield |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
194 #define lua_rawget dll_lua_rawget |
3450 | 195 #define lua_rawgeti dll_lua_rawgeti |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
196 #define lua_createtable dll_lua_createtable |
25527
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
197 #define lua_settable dll_lua_settable |
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
|
198 #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
|
199 #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
|
200 #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
|
201 #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
|
202 #endif |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
203 #define lua_getmetatable dll_lua_getmetatable |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
204 #define lua_setfield dll_lua_setfield |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
205 #define lua_rawset dll_lua_rawset |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
206 #define lua_rawseti dll_lua_rawseti |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
207 #define lua_setmetatable dll_lua_setmetatable |
3459 | 208 #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
|
209 // libs |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
210 #define luaopen_base dll_luaopen_base |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
211 #define luaopen_table dll_luaopen_table |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
212 #define luaopen_string dll_luaopen_string |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
213 #define luaopen_math dll_luaopen_math |
2431
7b764999f9b9
Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2373
diff
changeset
|
214 #define luaopen_io dll_luaopen_io |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
215 #define luaopen_os dll_luaopen_os |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
216 #define luaopen_package dll_luaopen_package |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
217 #define luaopen_debug dll_luaopen_debug |
2431
7b764999f9b9
Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2373
diff
changeset
|
218 #define luaL_openlibs dll_luaL_openlibs |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
219 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
220 // lauxlib |
3450 | 221 #if LUA_VERSION_NUM <= 501 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
222 void (*dll_luaL_register) (lua_State *L, const char *libname, const luaL_Reg *l); |
3450 | 223 char *(*dll_luaL_prepbuffer) (luaL_Buffer *B); |
224 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
|
225 int (*dll_luaL_typerror) (lua_State *L, int narg, const char *tname); |
3450 | 226 int (*dll_luaL_loadfile) (lua_State *L, const char *filename); |
227 int (*dll_luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, const char *name); | |
228 #else | |
229 char *(*dll_luaL_prepbuffsize) (luaL_Buffer *B, size_t sz); | |
230 void (*dll_luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); | |
231 int (*dll_luaL_loadfilex) (lua_State *L, const char *filename, const char *mode); | |
232 int (*dll_luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, const char *name, const char *mode); | |
233 int (*dll_luaL_argerror) (lua_State *L, int numarg, const char *extramsg); | |
234 #endif | |
21323
5b0bbc5d4e74
patch 8.2.1212: cannot build with Lua 5.4
Bram Moolenaar <Bram@vim.org>
parents:
21132
diff
changeset
|
235 #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
|
236 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
|
237 #endif |
3459 | 238 void (*dll_luaL_checkany) (lua_State *L, int narg); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
239 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
|
240 lua_Integer (*dll_luaL_checkinteger) (lua_State *L, int numArg); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
241 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
|
242 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
|
243 int (*dll_luaL_error) (lua_State *L, const char *fmt, ...); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
244 lua_State *(*dll_luaL_newstate) (void); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
245 void (*dll_luaL_buffinit) (lua_State *L, luaL_Buffer *B); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
246 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
|
247 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
|
248 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
|
249 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
|
250 #if LUA_VERSION_NUM <= 502 |
380923b96878
patch 8.2.1057: cannot build with dynamic Lua
Bram Moolenaar <Bram@vim.org>
parents:
21006
diff
changeset
|
251 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
|
252 #else |
380923b96878
patch 8.2.1057: cannot build with dynamic Lua
Bram Moolenaar <Bram@vim.org>
parents:
21006
diff
changeset
|
253 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
|
254 #endif |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
255 // lua |
3450 | 256 #if LUA_VERSION_NUM <= 501 |
257 lua_Number (*dll_lua_tonumber) (lua_State *L, int idx); | |
258 lua_Integer (*dll_lua_tointeger) (lua_State *L, int idx); | |
259 void (*dll_lua_call) (lua_State *L, int nargs, int nresults); | |
260 int (*dll_lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); | |
261 #else | |
262 lua_Number (*dll_lua_tonumberx) (lua_State *L, int idx, int *isnum); | |
263 lua_Integer (*dll_lua_tointegerx) (lua_State *L, int idx, int *isnum); | |
264 void (*dll_lua_callk) (lua_State *L, int nargs, int nresults, int ctx, | |
3618 | 265 lua_CFunction k); |
3450 | 266 int (*dll_lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc, |
3618 | 267 int ctx, lua_CFunction k); |
3450 | 268 void (*dll_lua_getglobal) (lua_State *L, const char *var); |
269 void (*dll_lua_setglobal) (lua_State *L, const char *var); | |
6887 | 270 #endif |
271 #if LUA_VERSION_NUM <= 502 | |
272 void (*dll_lua_replace) (lua_State *L, int idx); | |
273 void (*dll_lua_remove) (lua_State *L, int idx); | |
274 #endif | |
275 #if LUA_VERSION_NUM >= 503 | |
276 void (*dll_lua_rotate) (lua_State *L, int idx, int n); | |
6878 | 277 void (*dll_lua_copy) (lua_State *L, int fromidx, int toidx); |
3459 | 278 #endif |
3450 | 279 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
|
280 void (*dll_lua_close) (lua_State *L); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
281 int (*dll_lua_gettop) (lua_State *L); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
282 void (*dll_lua_settop) (lua_State *L, int idx); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
283 void (*dll_lua_pushvalue) (lua_State *L, int idx); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
284 int (*dll_lua_isnumber) (lua_State *L, int idx); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
285 int (*dll_lua_isstring) (lua_State *L, int idx); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
286 int (*dll_lua_type) (lua_State *L, int idx); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
287 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
|
288 int (*dll_lua_toboolean) (lua_State *L, int idx); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
289 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
|
290 void *(*dll_lua_touserdata) (lua_State *L, int idx); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
291 void (*dll_lua_pushnil) (lua_State *L); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
292 void (*dll_lua_pushnumber) (lua_State *L, lua_Number n); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
293 void (*dll_lua_pushinteger) (lua_State *L, lua_Integer n); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
294 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
|
295 void (*dll_lua_pushstring) (lua_State *L, const char *s); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
296 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
|
297 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
|
298 void (*dll_lua_pushboolean) (lua_State *L, int b); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
299 void (*dll_lua_pushlightuserdata) (lua_State *L, void *p); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
300 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
|
301 #if LUA_VERSION_NUM <= 502 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
302 void (*dll_lua_rawget) (lua_State *L, int idx); |
3450 | 303 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
|
304 #else |
d59bf91128ea
patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents:
14329
diff
changeset
|
305 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
|
306 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
|
307 #endif |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
308 void (*dll_lua_createtable) (lua_State *L, int narr, int nrec); |
25527
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
309 void (*dll_lua_settable) (lua_State *L, int idx); |
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
|
310 #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
|
311 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
|
312 #else |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
313 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
|
314 #endif |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
315 int (*dll_lua_getmetatable) (lua_State *L, int objindex); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
316 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
|
317 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
|
318 #if LUA_VERSION_NUM <= 502 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
319 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
|
320 #else |
d59bf91128ea
patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents:
14329
diff
changeset
|
321 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
|
322 #endif |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
323 int (*dll_lua_setmetatable) (lua_State *L, int objindex); |
3459 | 324 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
|
325 // libs |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
326 int (*dll_luaopen_base) (lua_State *L); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
327 int (*dll_luaopen_table) (lua_State *L); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
328 int (*dll_luaopen_string) (lua_State *L); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
329 int (*dll_luaopen_math) (lua_State *L); |
2431
7b764999f9b9
Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2373
diff
changeset
|
330 int (*dll_luaopen_io) (lua_State *L); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
331 int (*dll_luaopen_os) (lua_State *L); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
332 int (*dll_luaopen_package) (lua_State *L); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
333 int (*dll_luaopen_debug) (lua_State *L); |
2431
7b764999f9b9
Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2373
diff
changeset
|
334 void (*dll_luaL_openlibs) (lua_State *L); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
335 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
336 typedef void **luaV_function; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
337 typedef struct { |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
338 const char *name; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
339 luaV_function func; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
340 } luaV_Reg; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
341 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
342 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
|
343 // lauxlib |
3450 | 344 #if LUA_VERSION_NUM <= 501 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
345 {"luaL_register", (luaV_function) &dll_luaL_register}, |
3450 | 346 {"luaL_prepbuffer", (luaV_function) &dll_luaL_prepbuffer}, |
347 {"luaL_openlib", (luaV_function) &dll_luaL_openlib}, | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
348 {"luaL_typerror", (luaV_function) &dll_luaL_typerror}, |
3450 | 349 {"luaL_loadfile", (luaV_function) &dll_luaL_loadfile}, |
350 {"luaL_loadbuffer", (luaV_function) &dll_luaL_loadbuffer}, | |
351 #else | |
352 {"luaL_prepbuffsize", (luaV_function) &dll_luaL_prepbuffsize}, | |
353 {"luaL_setfuncs", (luaV_function) &dll_luaL_setfuncs}, | |
354 {"luaL_loadfilex", (luaV_function) &dll_luaL_loadfilex}, | |
355 {"luaL_loadbufferx", (luaV_function) &dll_luaL_loadbufferx}, | |
356 {"luaL_argerror", (luaV_function) &dll_luaL_argerror}, | |
357 #endif | |
21323
5b0bbc5d4e74
patch 8.2.1212: cannot build with Lua 5.4
Bram Moolenaar <Bram@vim.org>
parents:
21132
diff
changeset
|
358 #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
|
359 {"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
|
360 #endif |
3459 | 361 {"luaL_checkany", (luaV_function) &dll_luaL_checkany}, |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
362 {"luaL_checklstring", (luaV_function) &dll_luaL_checklstring}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
363 {"luaL_checkinteger", (luaV_function) &dll_luaL_checkinteger}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
364 {"luaL_optinteger", (luaV_function) &dll_luaL_optinteger}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
365 {"luaL_checktype", (luaV_function) &dll_luaL_checktype}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
366 {"luaL_error", (luaV_function) &dll_luaL_error}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
367 {"luaL_newstate", (luaV_function) &dll_luaL_newstate}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
368 {"luaL_buffinit", (luaV_function) &dll_luaL_buffinit}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
369 {"luaL_addlstring", (luaV_function) &dll_luaL_addlstring}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
370 {"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
|
371 {"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
|
372 {"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
|
373 {"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
|
374 // lua |
3450 | 375 #if LUA_VERSION_NUM <= 501 |
376 {"lua_tonumber", (luaV_function) &dll_lua_tonumber}, | |
377 {"lua_tointeger", (luaV_function) &dll_lua_tointeger}, | |
378 {"lua_call", (luaV_function) &dll_lua_call}, | |
379 {"lua_pcall", (luaV_function) &dll_lua_pcall}, | |
380 #else | |
381 {"lua_tonumberx", (luaV_function) &dll_lua_tonumberx}, | |
382 {"lua_tointegerx", (luaV_function) &dll_lua_tointegerx}, | |
383 {"lua_callk", (luaV_function) &dll_lua_callk}, | |
384 {"lua_pcallk", (luaV_function) &dll_lua_pcallk}, | |
385 {"lua_getglobal", (luaV_function) &dll_lua_getglobal}, | |
386 {"lua_setglobal", (luaV_function) &dll_lua_setglobal}, | |
3459 | 387 #endif |
6887 | 388 #if LUA_VERSION_NUM <= 502 |
389 {"lua_replace", (luaV_function) &dll_lua_replace}, | |
390 {"lua_remove", (luaV_function) &dll_lua_remove}, | |
391 #endif | |
392 #if LUA_VERSION_NUM >= 503 | |
393 {"lua_rotate", (luaV_function) &dll_lua_rotate}, | |
394 {"lua_copy", (luaV_function) &dll_lua_copy}, | |
395 #endif | |
3450 | 396 {"lua_typename", (luaV_function) &dll_lua_typename}, |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
397 {"lua_close", (luaV_function) &dll_lua_close}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
398 {"lua_gettop", (luaV_function) &dll_lua_gettop}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
399 {"lua_settop", (luaV_function) &dll_lua_settop}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
400 {"lua_pushvalue", (luaV_function) &dll_lua_pushvalue}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
401 {"lua_isnumber", (luaV_function) &dll_lua_isnumber}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
402 {"lua_isstring", (luaV_function) &dll_lua_isstring}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
403 {"lua_type", (luaV_function) &dll_lua_type}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
404 {"lua_rawequal", (luaV_function) &dll_lua_rawequal}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
405 {"lua_toboolean", (luaV_function) &dll_lua_toboolean}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
406 {"lua_tolstring", (luaV_function) &dll_lua_tolstring}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
407 {"lua_touserdata", (luaV_function) &dll_lua_touserdata}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
408 {"lua_pushnil", (luaV_function) &dll_lua_pushnil}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
409 {"lua_pushnumber", (luaV_function) &dll_lua_pushnumber}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
410 {"lua_pushinteger", (luaV_function) &dll_lua_pushinteger}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
411 {"lua_pushlstring", (luaV_function) &dll_lua_pushlstring}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
412 {"lua_pushstring", (luaV_function) &dll_lua_pushstring}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
413 {"lua_pushfstring", (luaV_function) &dll_lua_pushfstring}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
414 {"lua_pushcclosure", (luaV_function) &dll_lua_pushcclosure}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
415 {"lua_pushboolean", (luaV_function) &dll_lua_pushboolean}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
416 {"lua_pushlightuserdata", (luaV_function) &dll_lua_pushlightuserdata}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
417 {"lua_getfield", (luaV_function) &dll_lua_getfield}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
418 {"lua_rawget", (luaV_function) &dll_lua_rawget}, |
3450 | 419 {"lua_rawgeti", (luaV_function) &dll_lua_rawgeti}, |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
420 {"lua_createtable", (luaV_function) &dll_lua_createtable}, |
25527
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
421 {"lua_settable", (luaV_function) &dll_lua_settable}, |
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
|
422 #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
|
423 {"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
|
424 #else |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
425 {"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
|
426 #endif |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
427 {"lua_getmetatable", (luaV_function) &dll_lua_getmetatable}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
428 {"lua_setfield", (luaV_function) &dll_lua_setfield}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
429 {"lua_rawset", (luaV_function) &dll_lua_rawset}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
430 {"lua_rawseti", (luaV_function) &dll_lua_rawseti}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
431 {"lua_setmetatable", (luaV_function) &dll_lua_setmetatable}, |
3459 | 432 {"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
|
433 // libs |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
434 {"luaopen_base", (luaV_function) &dll_luaopen_base}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
435 {"luaopen_table", (luaV_function) &dll_luaopen_table}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
436 {"luaopen_string", (luaV_function) &dll_luaopen_string}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
437 {"luaopen_math", (luaV_function) &dll_luaopen_math}, |
2431
7b764999f9b9
Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2373
diff
changeset
|
438 {"luaopen_io", (luaV_function) &dll_luaopen_io}, |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
439 {"luaopen_os", (luaV_function) &dll_luaopen_os}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
440 {"luaopen_package", (luaV_function) &dll_luaopen_package}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
441 {"luaopen_debug", (luaV_function) &dll_luaopen_debug}, |
2431
7b764999f9b9
Update for Lua interface. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2373
diff
changeset
|
442 {"luaL_openlibs", (luaV_function) &dll_luaL_openlibs}, |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
443 {NULL, NULL} |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
444 }; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
445 |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2331
diff
changeset
|
446 static HANDLE hinstLua = NULL; |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
447 |
2330 | 448 static int |
449 lua_link_init(char *libname, int verbose) | |
450 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
451 const luaV_Reg *reg; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
452 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
|
453 hinstLua = load_dll(libname); |
2330 | 454 if (!hinstLua) |
455 { | |
456 if (verbose) | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25881
diff
changeset
|
457 semsg(_(e_could_not_load_library_str_str), libname, load_dll_error()); |
2330 | 458 return FAIL; |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
459 } |
2330 | 460 for (reg = luaV_dll; reg->func; reg++) |
461 { | |
2373
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2331
diff
changeset
|
462 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
|
463 { |
f149bb1cf5be
Make it possible to load Lua dynamically on Unix. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2331
diff
changeset
|
464 close_dll(hinstLua); |
2330 | 465 hinstLua = 0; |
466 if (verbose) | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25881
diff
changeset
|
467 semsg(_(e_could_not_load_library_function_str), reg->name); |
2330 | 468 return FAIL; |
469 } | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
470 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
471 return OK; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
472 } |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
473 #endif // DYNAMIC_LUA |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
474 |
10025
068f397d0da4
commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
475 #if defined(DYNAMIC_LUA) || defined(PROTO) |
2330 | 476 int |
477 lua_enabled(int verbose) | |
478 { | |
7528
53163e4d9e4f
commit https://github.com/vim/vim/commit/25e4fcde767084d1a79e0926bc301c92987c0cce
Christian Brabandt <cb@256bit.org>
parents:
7297
diff
changeset
|
479 return lua_link_init((char *)p_luadll, verbose) == OK; |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
480 } |
10025
068f397d0da4
commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
481 #endif |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
482 |
21323
5b0bbc5d4e74
patch 8.2.1212: cannot build with Lua 5.4
Bram Moolenaar <Bram@vim.org>
parents:
21132
diff
changeset
|
483 #if LUA_VERSION_NUM > 501 && LUA_VERSION_NUM < 504 |
3450 | 484 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
|
485 luaL_typeerror(lua_State *L, int narg, const char *tname) |
3450 | 486 { |
487 const char *msg = lua_pushfstring(L, "%s expected, got %s", | |
3618 | 488 tname, luaL_typename(L, narg)); |
3450 | 489 return luaL_argerror(L, narg, msg); |
490 } | |
491 #endif | |
492 | |
32814
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
493 static LUAV_INLINE void |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
494 luaV_getudata(lua_State *L, void *v) |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
495 { |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
496 lua_pushlightuserdata(L, (void *) LUAVIM_UDATA_CACHE); |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
497 lua_rawget(L, LUA_REGISTRYINDEX); // now the cache table is at the top of the stack |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
498 lua_pushlightuserdata(L, v); |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
499 lua_rawget(L, -2); |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
500 lua_remove(L, -2); // remove the cache table from the stack |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
501 } |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
502 |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
503 static LUAV_INLINE void |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
504 luaV_setudata(lua_State *L, void *v) |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
505 { |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
506 lua_pushlightuserdata(L, (void *) LUAVIM_UDATA_CACHE); |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
507 lua_rawget(L, LUA_REGISTRYINDEX); // cache table is at -1 |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
508 lua_pushlightuserdata(L, v); // ...now at -2 |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
509 lua_pushvalue(L, -3); // copy the userdata (cache at -3) |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
510 lua_rawset(L, -3); // consumes two stack items |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
511 lua_pop(L, 1); // and remove the cache table |
cf6d98955c64
patch 9.0.1721: Build failure on Windows with dynamic lua
Christian Brabandt <cb@256bit.org>
parents:
32807
diff
changeset
|
512 } |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
513 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
514 // ======= Internal ======= |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
515 |
2330 | 516 static void |
517 luaV_newmetatable(lua_State *L, const char *tname) | |
518 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
519 lua_newtable(L); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
520 lua_pushlightuserdata(L, (void *) tname); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
521 lua_pushvalue(L, -2); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
522 lua_rawset(L, LUA_REGISTRYINDEX); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
523 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
524 |
2330 | 525 static void * |
526 luaV_toudata(lua_State *L, int ud, const char *tname) | |
527 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
528 void *p = lua_touserdata(L, ud); |
2330 | 529 |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
530 if (p == NULL) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
531 return NULL; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
532 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
533 // value is userdata |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
534 if (lua_getmetatable(L, ud)) // does it have a metatable? |
2330 | 535 { |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
536 luaV_getfield(L, tname); // get metatable |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
537 if (lua_rawequal(L, -1, -2)) // MTs match? |
2330 | 538 { |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
539 lua_pop(L, 2); // MTs |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
540 return p; |
2330 | 541 } |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
542 } |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
543 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
544 return NULL; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
545 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
546 |
2330 | 547 static void * |
3450 | 548 luaV_checkcache(lua_State *L, void *p) |
549 { | |
550 luaV_getudata(L, p); | |
551 if (lua_isnil(L, -1)) luaL_error(L, "invalid object"); | |
552 lua_pop(L, 1); | |
553 return p; | |
554 } | |
555 | |
556 #define luaV_unbox(L,luatyp,ud) (*((luatyp *) lua_touserdata((L),(ud)))) | |
557 | |
558 #define luaV_checkvalid(L,luatyp,ud) \ | |
559 luaV_checkcache((L), (void *) luaV_unbox((L),luatyp,(ud))) | |
560 | |
561 static void * | |
2330 | 562 luaV_checkudata(lua_State *L, int ud, const char *tname) |
563 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
564 void *p = luaV_toudata(L, ud, tname); |
3450 | 565 if (p == NULL) luaL_typeerror(L, ud, tname); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
566 return p; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
567 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
568 |
2330 | 569 static void |
570 luaV_pushtypval(lua_State *L, typval_T *tv) | |
571 { | |
3450 | 572 if (tv == NULL) |
573 { | |
574 lua_pushnil(L); | |
575 return; | |
576 } | |
2330 | 577 switch (tv->v_type) |
578 { | |
579 case VAR_STRING: | |
3865 | 580 lua_pushstring(L, tv->vval.v_string == NULL |
581 ? "" : (char *)tv->vval.v_string); | |
2330 | 582 break; |
583 case VAR_NUMBER: | |
584 lua_pushinteger(L, (int) tv->vval.v_number); | |
585 break; | |
586 case VAR_FLOAT: | |
587 lua_pushnumber(L, (lua_Number) tv->vval.v_float); | |
588 break; | |
3450 | 589 case VAR_LIST: |
590 luaV_pushlist(L, tv->vval.v_list); | |
591 break; | |
592 case VAR_DICT: | |
593 luaV_pushdict(L, tv->vval.v_dict); | |
594 break; | |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18798
diff
changeset
|
595 case VAR_BOOL: |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7528
diff
changeset
|
596 case VAR_SPECIAL: |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7528
diff
changeset
|
597 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
|
598 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
|
599 else |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7528
diff
changeset
|
600 lua_pushnil(L); |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7528
diff
changeset
|
601 break; |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
602 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
|
603 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
|
604 break; |
24073
c424821dc031
patch 8.2.2578: Lua cannot handle a passed in lambda
Bram Moolenaar <Bram@vim.org>
parents:
22719
diff
changeset
|
605 case VAR_PARTIAL: |
c424821dc031
patch 8.2.2578: Lua cannot handle a passed in lambda
Bram Moolenaar <Bram@vim.org>
parents:
22719
diff
changeset
|
606 // TODO: handle partial arguments |
c424821dc031
patch 8.2.2578: Lua cannot handle a passed in lambda
Bram Moolenaar <Bram@vim.org>
parents:
22719
diff
changeset
|
607 luaV_pushfuncref(L, partial_name(tv->vval.v_partial)); |
c424821dc031
patch 8.2.2578: Lua cannot handle a passed in lambda
Bram Moolenaar <Bram@vim.org>
parents:
22719
diff
changeset
|
608 break; |
c424821dc031
patch 8.2.2578: Lua cannot handle a passed in lambda
Bram Moolenaar <Bram@vim.org>
parents:
22719
diff
changeset
|
609 |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
610 case VAR_BLOB: |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
611 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
|
612 break; |
3450 | 613 default: |
614 lua_pushnil(L); | |
615 } | |
616 } | |
2330 | 617 |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
618 /* |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
619 * 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
|
620 * Returns OK or FAIL. |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
621 */ |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
622 static int |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
623 luaV_totypval(lua_State *L, int pos, typval_T *tv) |
3450 | 624 { |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
625 int status = OK; |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
626 |
21132
985e61894bb4
patch 8.2.1117: Coverity warns for unsing unitialized field
Bram Moolenaar <Bram@vim.org>
parents:
21108
diff
changeset
|
627 tv->v_lock = 0; |
985e61894bb4
patch 8.2.1117: Coverity warns for unsing unitialized field
Bram Moolenaar <Bram@vim.org>
parents:
21108
diff
changeset
|
628 |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
629 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
|
630 { |
3450 | 631 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
|
632 tv->v_type = VAR_BOOL; |
3450 | 633 tv->vval.v_number = (varnumber_T) lua_toboolean(L, pos); |
634 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
|
635 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
|
636 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
|
637 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
|
638 break; |
3450 | 639 case LUA_TSTRING: |
640 tv->v_type = VAR_STRING; | |
641 tv->vval.v_string = vim_strsave((char_u *) lua_tostring(L, pos)); | |
2330 | 642 break; |
3450 | 643 case LUA_TNUMBER: |
20441
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
644 { |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
645 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
|
646 |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
647 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
|
648 || ((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
|
649 { |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
650 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
|
651 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
|
652 } |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
653 else |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
654 { |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
655 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
|
656 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
|
657 } |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
658 } |
3450 | 659 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
|
660 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
|
661 { |
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 char_u *name; |
21367
f9d87868d77f
patch 8.2.1234: Lua build problem with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
21323
diff
changeset
|
663 luaV_CFuncState *state; |
f9d87868d77f
patch 8.2.1234: Lua build problem with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
21323
diff
changeset
|
664 |
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
|
665 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
|
666 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
|
667 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
|
668 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
|
669 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
|
670 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
|
671 &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
|
672 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
|
673 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
|
674 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
|
675 } |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
676 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
|
677 { |
21367
f9d87868d77f
patch 8.2.1234: Lua build problem with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
21323
diff
changeset
|
678 int lua_tableref; |
f9d87868d77f
patch 8.2.1234: Lua build problem with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
21323
diff
changeset
|
679 |
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
|
680 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
|
681 lua_tableref = luaL_ref(L, LUA_REGISTRYINDEX); |
31804
50555279168b
patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
31702
diff
changeset
|
682 if (lua_getmetatable(L, pos)) |
50555279168b
patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
31702
diff
changeset
|
683 { |
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
|
684 lua_getfield(L, -1, LUA___CALL); |
31804
50555279168b
patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
31702
diff
changeset
|
685 if (lua_isfunction(L, -1)) |
50555279168b
patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
31702
diff
changeset
|
686 { |
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
|
687 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
|
688 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
|
689 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
|
690 |
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
|
691 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
|
692 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
|
693 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
|
694 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
|
695 &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
|
696 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
|
697 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
|
698 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
|
699 } |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
700 } |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
701 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
|
702 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
|
703 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
|
704 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
|
705 } |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
706 case LUA_TUSERDATA: |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
707 { |
3450 | 708 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
|
709 |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
710 if (lua_getmetatable(L, pos)) // has metatable? |
2330 | 711 { |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
712 // check list |
3450 | 713 luaV_getfield(L, LUAVIM_LIST); |
714 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
|
715 { |
3450 | 716 tv->v_type = VAR_LIST; |
717 tv->vval.v_list = *((luaV_List *) p); | |
718 ++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
|
719 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
|
720 break; |
2330 | 721 } |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
722 // check dict |
3450 | 723 luaV_getfield(L, LUAVIM_DICT); |
724 if (lua_rawequal(L, -1, -3)) | |
725 { | |
726 tv->v_type = VAR_DICT; | |
727 tv->vval.v_dict = *((luaV_Dict *) p); | |
728 ++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
|
729 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
|
730 break; |
3450 | 731 } |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
732 // check blob |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
733 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
|
734 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
|
735 { |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
736 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
|
737 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
|
738 ++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
|
739 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
|
740 break; |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
741 } |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
742 // check funcref |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
743 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
|
744 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
|
745 { |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
746 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
|
747 |
16028
8ad2cda3757d
patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents:
16009
diff
changeset
|
748 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
|
749 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
|
750 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
|
751 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
|
752 break; |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
753 } |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
754 lua_pop(L, 4); // MTs |
2330 | 755 } |
756 } | |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
757 // FALLTHROUGH |
2330 | 758 default: |
3450 | 759 tv->v_type = VAR_NUMBER; |
760 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
|
761 status = FAIL; |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
762 } |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
763 return status; |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
764 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
765 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
766 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
767 * 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
|
768 * \n with \0 otherwise |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
769 */ |
2330 | 770 static void |
771 luaV_addlstring(luaL_Buffer *b, const char *s, size_t l, int toline) | |
772 { | |
773 while (l--) | |
774 { | |
775 if (*s == '\0' && toline) | |
776 luaL_addchar(b, '\n'); | |
777 else if (*s == '\n' && !toline) | |
778 luaL_addchar(b, '\0'); | |
779 else | |
780 luaL_addchar(b, *s); | |
781 s++; | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
782 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
783 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
784 |
2330 | 785 static void |
786 luaV_pushline(lua_State *L, buf_T *buf, linenr_T n) | |
787 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
788 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
|
789 luaL_Buffer b; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
790 luaL_buffinit(L, &b); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
791 luaV_addlstring(&b, s, strlen(s), 0); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
792 luaL_pushresult(&b); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
793 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
794 |
2330 | 795 static char_u * |
796 luaV_toline(lua_State *L, int pos) | |
797 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
798 size_t l; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
799 const char *s = lua_tolstring(L, pos, &l); |
2330 | 800 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
801 luaL_Buffer b; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
802 luaL_buffinit(L, &b); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
803 luaV_addlstring(&b, s, l, 1); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
804 luaL_pushresult(&b); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
805 return (char_u *) lua_tostring(L, -1); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
806 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
807 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
808 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
809 * 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
|
810 * s separated by newlines |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
811 */ |
2330 | 812 static void |
813 luaV_msgfunc(lua_State *L, msgfunc_T mf) | |
814 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
815 luaL_Buffer b; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
816 size_t l; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
817 const char *p, *s = lua_tolstring(L, -1, &l); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
818 luaL_buffinit(L, &b); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
819 luaV_addlstring(&b, s, l, 0); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
820 luaL_pushresult(&b); |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
821 // break string |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
822 p = s = lua_tolstring(L, -1, &l); |
2330 | 823 while (l--) |
824 { | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
825 if (*p++ == '\0') // break? |
2330 | 826 { |
22719
8da5e18effc5
patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents:
21367
diff
changeset
|
827 mf((char *)s); |
2330 | 828 s = p; |
829 } | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
830 } |
22719
8da5e18effc5
patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents:
21367
diff
changeset
|
831 mf((char *)s); |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
832 lua_pop(L, 2); // original and modified strings |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
833 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
834 |
3450 | 835 #define luaV_newtype(typ,tname,luatyp,luatname) \ |
836 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
|
837 luaV_new##tname(lua_State *L, typ *obj) \ |
3450 | 838 { \ |
839 luatyp *o = (luatyp *) lua_newuserdata(L, sizeof(luatyp)); \ | |
840 *o = obj; \ | |
841 luaV_setudata(L, obj); /* cache[obj] = udata */ \ | |
842 luaV_getfield(L, luatname); \ | |
843 lua_setmetatable(L, -2); \ | |
844 return o; \ | |
845 } | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
846 |
3450 | 847 #define luaV_pushtype(typ,tname,luatyp) \ |
848 static luatyp * \ | |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
849 luaV_push##tname(lua_State *L, typ *obj) \ |
3450 | 850 { \ |
851 luatyp *o = NULL; \ | |
852 if (obj == NULL) \ | |
853 lua_pushnil(L); \ | |
31804
50555279168b
patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
31702
diff
changeset
|
854 else \ |
50555279168b
patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents:
31702
diff
changeset
|
855 { \ |
3450 | 856 luaV_getudata(L, obj); \ |
857 if (lua_isnil(L, -1)) /* not interned? */ \ | |
858 { \ | |
859 lua_pop(L, 1); \ | |
860 o = luaV_new##tname(L, obj); \ | |
861 } \ | |
862 else \ | |
863 o = (luatyp *) lua_touserdata(L, -1); \ | |
864 } \ | |
865 return o; \ | |
866 } | |
867 | |
868 #define luaV_type_tostring(tname,luatname) \ | |
869 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
|
870 luaV_##tname##_tostring(lua_State *L) \ |
3450 | 871 { \ |
872 lua_pushfstring(L, "%s: %p", luatname, lua_touserdata(L, 1)); \ | |
873 return 1; \ | |
874 } | |
875 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
876 // ======= List type ======= |
3450 | 877 |
878 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
|
879 luaV_newlist(lua_State *L, list_T *lis) |
3450 | 880 { |
881 luaV_List *l = (luaV_List *) lua_newuserdata(L, sizeof(luaV_List)); | |
882 *l = lis; | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
883 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
|
884 luaV_setudata(L, lis); // cache[lis] = udata |
3450 | 885 luaV_getfield(L, LUAVIM_LIST); |
886 lua_setmetatable(L, -2); | |
887 return l; | |
888 } | |
889 | |
890 luaV_pushtype(list_T, list, luaV_List) | |
891 luaV_type_tostring(list, LUAVIM_LIST) | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
892 |
2330 | 893 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
|
894 luaV_list_len(lua_State *L) |
2330 | 895 { |
3450 | 896 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
|
897 lua_pushinteger(L, (int) list_len(l)); |
3450 | 898 return 1; |
899 } | |
900 | |
901 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
|
902 luaV_list_iter(lua_State *L) |
3450 | 903 { |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
904 listitem_T *li = (listitem_T *) lua_touserdata(L, lua_upvalueindex(1)); |
3450 | 905 if (li == NULL) return 0; |
906 luaV_pushtypval(L, &li->li_tv); | |
907 lua_pushlightuserdata(L, (void *) li->li_next); | |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
908 lua_replace(L, lua_upvalueindex(1)); |
3450 | 909 return 1; |
910 } | |
911 | |
912 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
|
913 luaV_list_call(lua_State *L) |
3450 | 914 { |
915 list_T *l = luaV_unbox(L, luaV_List, 1); | |
916 lua_pushlightuserdata(L, (void *) l->lv_first); | |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
917 lua_pushcclosure(L, luaV_list_iter, 1); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
918 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
919 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
920 |
2330 | 921 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
|
922 luaV_list_index(lua_State *L) |
3450 | 923 { |
924 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
|
925 if (lua_isnumber(L, 2)) // list item? |
3450 | 926 { |
21030
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21012
diff
changeset
|
927 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
|
928 listitem_T *li; |
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21012
diff
changeset
|
929 |
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21012
diff
changeset
|
930 // 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
|
931 // normalize. |
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21012
diff
changeset
|
932 n -= 1; |
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21012
diff
changeset
|
933 li = list_find(l, n); |
3450 | 934 if (li == NULL) |
935 lua_pushnil(L); | |
936 else | |
937 luaV_pushtypval(L, &li->li_tv); | |
938 } | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
939 else if (lua_isstring(L, 2)) // method? |
3450 | 940 { |
941 const char *s = lua_tostring(L, 2); | |
942 if (strncmp(s, "add", 3) == 0 | |
4293 | 943 || strncmp(s, "insert", 6) == 0) |
3450 | 944 { |
945 lua_getmetatable(L, 1); | |
946 lua_getfield(L, -1, s); | |
947 } | |
948 else | |
949 lua_pushnil(L); | |
950 } | |
951 else | |
952 lua_pushnil(L); | |
953 return 1; | |
954 } | |
955 | |
956 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
|
957 luaV_list_newindex(lua_State *L) |
3450 | 958 { |
959 list_T *l = luaV_unbox(L, luaV_List, 1); | |
960 long n = (long) luaL_checkinteger(L, 2); | |
961 listitem_T *li; | |
21030
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21012
diff
changeset
|
962 |
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21012
diff
changeset
|
963 // 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
|
964 n -= 1; |
08e284594211
patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents:
21012
diff
changeset
|
965 |
3450 | 966 if (l->lv_lock) |
967 luaL_error(L, "list is locked"); | |
968 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
|
969 if (li == NULL) |
3450 | 970 { |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
971 if (!lua_isnil(L, 3)) |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
972 { |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
973 typval_T v; |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
974 luaV_checktypval(L, 3, &v, "inserting list item"); |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
975 if (list_insert_tv(l, &v, li) == FAIL) |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
976 luaL_error(L, "failed to add item to list"); |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
977 clear_tv(&v); |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
978 } |
3450 | 979 } |
980 else | |
981 { | |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
982 if (lua_isnil(L, 3)) // remove? |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
983 { |
21060
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
984 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
|
985 listitem_free(l, li); |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
986 } |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
987 else |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
988 { |
21060
89aba7895bb2
patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents:
21030
diff
changeset
|
989 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
|
990 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
|
991 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
|
992 li->li_tv = v; |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
993 } |
3450 | 994 } |
995 return 0; | |
996 } | |
997 | |
998 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
|
999 luaV_list_add(lua_State *L) |
3450 | 1000 { |
1001 luaV_List *lis = luaV_checkudata(L, 1, LUAVIM_LIST); | |
1002 list_T *l = (list_T *) luaV_checkcache(L, (void *) *lis); | |
4293 | 1003 typval_T v; |
3450 | 1004 if (l->lv_lock) |
1005 luaL_error(L, "list is locked"); | |
4293 | 1006 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
|
1007 luaV_checktypval(L, 2, &v, "adding list item"); |
4293 | 1008 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
|
1009 luaL_error(L, "failed to add item to list"); |
4293 | 1010 clear_tv(&v); |
3450 | 1011 lua_settop(L, 1); |
1012 return 1; | |
1013 } | |
1014 | |
1015 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
|
1016 luaV_list_insert(lua_State *L) |
3450 | 1017 { |
1018 luaV_List *lis = luaV_checkudata(L, 1, LUAVIM_LIST); | |
1019 list_T *l = (list_T *) luaV_checkcache(L, (void *) *lis); | |
6625 | 1020 long pos = (long) luaL_optinteger(L, 3, 0); |
3450 | 1021 listitem_T *li = NULL; |
1022 typval_T v; | |
1023 if (l->lv_lock) | |
1024 luaL_error(L, "list is locked"); | |
1025 if (pos < l->lv_len) | |
1026 { | |
1027 li = list_find(l, pos); | |
1028 if (li == NULL) | |
1029 luaL_error(L, "invalid position"); | |
1030 } | |
1031 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
|
1032 luaV_checktypval(L, 2, &v, "inserting list item"); |
4293 | 1033 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
|
1034 luaL_error(L, "failed to add item to list"); |
4293 | 1035 clear_tv(&v); |
3450 | 1036 lua_settop(L, 1); |
1037 return 1; | |
1038 } | |
1039 | |
1040 static const luaL_Reg luaV_List_mt[] = { | |
1041 {"__tostring", luaV_list_tostring}, | |
1042 {"__len", luaV_list_len}, | |
1043 {"__call", luaV_list_call}, | |
1044 {"__index", luaV_list_index}, | |
1045 {"__newindex", luaV_list_newindex}, | |
1046 {"add", luaV_list_add}, | |
1047 {"insert", luaV_list_insert}, | |
1048 {NULL, NULL} | |
1049 }; | |
1050 | |
1051 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1052 // ======= Dict type ======= |
3450 | 1053 |
1054 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
|
1055 luaV_newdict(lua_State *L, dict_T *dic) |
3450 | 1056 { |
1057 luaV_Dict *d = (luaV_Dict *) lua_newuserdata(L, sizeof(luaV_Dict)); | |
1058 *d = dic; | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1059 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
|
1060 luaV_setudata(L, dic); // cache[dic] = udata |
3450 | 1061 luaV_getfield(L, LUAVIM_DICT); |
1062 lua_setmetatable(L, -2); | |
1063 return d; | |
1064 } | |
1065 | |
1066 luaV_pushtype(dict_T, dict, luaV_Dict) | |
1067 luaV_type_tostring(dict, LUAVIM_DICT) | |
1068 | |
1069 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
|
1070 luaV_dict_len(lua_State *L) |
3450 | 1071 { |
1072 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
|
1073 lua_pushinteger(L, (int) dict_len(d)); |
3450 | 1074 return 1; |
1075 } | |
1076 | |
1077 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
|
1078 luaV_dict_iter(lua_State *L UNUSED) |
3450 | 1079 { |
4135 | 1080 #ifdef FEAT_EVAL |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
1081 hashitem_T *hi = (hashitem_T *) lua_touserdata(L, lua_upvalueindex(1)); |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
1082 int n = lua_tointeger(L, lua_upvalueindex(2)); |
3450 | 1083 dictitem_T *di; |
1084 if (n <= 0) return 0; | |
1085 while (HASHITEM_EMPTY(hi)) hi++; | |
1086 di = dict_lookup(hi); | |
1087 lua_pushstring(L, (char *) hi->hi_key); | |
1088 luaV_pushtypval(L, &di->di_tv); | |
1089 lua_pushlightuserdata(L, (void *) (hi + 1)); | |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
1090 lua_replace(L, lua_upvalueindex(1)); |
3450 | 1091 lua_pushinteger(L, n - 1); |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
1092 lua_replace(L, lua_upvalueindex(2)); |
3450 | 1093 return 2; |
4135 | 1094 #else |
1095 return 0; | |
1096 #endif | |
3450 | 1097 } |
1098 | |
1099 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
|
1100 luaV_dict_call(lua_State *L) |
3450 | 1101 { |
1102 dict_T *d = luaV_unbox(L, luaV_Dict, 1); | |
1103 hashtab_T *ht = &d->dv_hashtab; | |
1104 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
|
1105 lua_pushinteger(L, ht->ht_used); // # remaining items |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
1106 lua_pushcclosure(L, luaV_dict_iter, 2); |
3450 | 1107 return 1; |
1108 } | |
1109 | |
1110 static int | |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1111 luaV_dict_index(lua_State *L) |
3450 | 1112 { |
1113 dict_T *d = luaV_unbox(L, luaV_Dict, 1); | |
1114 char_u *key = (char_u *) luaL_checkstring(L, 2); | |
1115 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
|
1116 |
3450 | 1117 if (di == NULL) |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1118 { |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1119 lua_pushnil(L); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1120 return 1; |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1121 } |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1122 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1123 luaV_pushtypval(L, &di->di_tv); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1124 if (di->di_tv.v_type == VAR_FUNC) // funcref? |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1125 { |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1126 luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, -1); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1127 f->self = d; // keep "self" reference |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1128 d->dv_refcount++; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1129 } |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1130 |
3450 | 1131 return 1; |
1132 } | |
1133 | |
1134 static int | |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1135 luaV_dict_newindex(lua_State *L) |
3450 | 1136 { |
1137 dict_T *d = luaV_unbox(L, luaV_Dict, 1); | |
1138 char_u *key = (char_u *) luaL_checkstring(L, 2); | |
1139 dictitem_T *di; | |
21108
43e82e8133b9
patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents:
21060
diff
changeset
|
1140 typval_T tv; |
16009
3b524e8110ab
patch 8.1.1010: Lua interface leaks memory
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1141 |
3450 | 1142 if (d->dv_lock) |
1143 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
|
1144 if (key == NULL) |
fe651f98e173
patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
1145 return 0; |
fe651f98e173
patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
1146 if (*key == NUL) |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1147 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
|
1148 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
|
1149 { |
21108
43e82e8133b9
patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents:
21060
diff
changeset
|
1150 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
|
1151 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
|
1152 { |
43e82e8133b9
patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents:
21060
diff
changeset
|
1153 clear_tv(&tv); |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1154 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
|
1155 } |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1156 } |
3450 | 1157 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
|
1158 if (di == NULL) // non-existing key? |
3450 | 1159 { |
14329
fe651f98e173
patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
1160 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
|
1161 return 0; |
3450 | 1162 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
|
1163 if (di == NULL) |
21108
43e82e8133b9
patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents:
21060
diff
changeset
|
1164 { |
43e82e8133b9
patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents:
21060
diff
changeset
|
1165 clear_tv(&tv); |
14329
fe651f98e173
patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
1166 return 0; |
21108
43e82e8133b9
patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents:
21060
diff
changeset
|
1167 } |
3450 | 1168 if (dict_add(d, di) == FAIL) |
1169 { | |
14329
fe651f98e173
patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
1170 vim_free(di); |
21108
43e82e8133b9
patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents:
21060
diff
changeset
|
1171 clear_tv(&tv); |
14329
fe651f98e173
patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
1172 return 0; |
3450 | 1173 } |
1174 } | |
1175 else | |
1176 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
|
1177 if (lua_isnil(L, 3)) // remove? |
3450 | 1178 { |
1179 hashitem_T *hi = hash_find(&d->dv_hashtab, di->di_key); | |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1180 hash_remove(&d->dv_hashtab, hi, "Lua new index"); |
3450 | 1181 dictitem_free(di); |
1182 } | |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1183 else |
21108
43e82e8133b9
patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents:
21060
diff
changeset
|
1184 di->di_tv = tv; |
3450 | 1185 return 0; |
1186 } | |
1187 | |
1188 static const luaL_Reg luaV_Dict_mt[] = { | |
1189 {"__tostring", luaV_dict_tostring}, | |
1190 {"__len", luaV_dict_len}, | |
1191 {"__call", luaV_dict_call}, | |
1192 {"__index", luaV_dict_index}, | |
1193 {"__newindex", luaV_dict_newindex}, | |
1194 {NULL, NULL} | |
1195 }; | |
1196 | |
1197 | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1198 // ======= Blob type ======= |
16076
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 static luaV_Blob * |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1201 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
|
1202 { |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1203 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
|
1204 *b = blo; |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1205 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
|
1206 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
|
1207 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
|
1208 lua_setmetatable(L, -2); |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1209 return b; |
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 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1212 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
|
1213 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
|
1214 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1215 static int |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1216 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
|
1217 { |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1218 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
|
1219 blob_unref(b); |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1220 return 0; |
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 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1223 static int |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1224 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
|
1225 { |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1226 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
|
1227 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
|
1228 return 1; |
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 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1231 static int |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1232 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
|
1233 { |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1234 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
|
1235 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
|
1236 { |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1237 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
|
1238 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
|
1239 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
|
1240 else |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1241 lua_pushnil(L); |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1242 } |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1243 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
|
1244 { |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1245 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
|
1246 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
|
1247 { |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1248 lua_getmetatable(L, 1); |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1249 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
|
1250 } |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1251 else |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1252 lua_pushnil(L); |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1253 } |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1254 else |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1255 lua_pushnil(L); |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1256 return 1; |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1257 } |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1258 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1259 static int |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1260 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
|
1261 { |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1262 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
|
1263 if (b->bv_lock) |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1264 luaL_error(L, "blob is locked"); |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1265 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1266 if (!lua_isnumber(L, 2)) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1267 return 0; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1268 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1269 long len = blob_len(b); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1270 int idx = luaL_checkinteger(L, 2); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1271 int val = luaL_checkinteger(L, 3); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1272 if (idx < len || (idx == len && ga_grow(&b->bv_ga, 1) == OK)) |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1273 { |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1274 blob_set(b, idx, (char_u) val); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1275 if (idx == len) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1276 ++b->bv_ga.ga_len; |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1277 } |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1278 else |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1279 luaL_error(L, "index out of range"); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1280 |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1281 return 0; |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1282 } |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1283 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1284 static int |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1285 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
|
1286 { |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1287 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
|
1288 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
|
1289 if (b->bv_lock) |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1290 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
|
1291 lua_settop(L, 2); |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1292 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
|
1293 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
|
1294 else |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1295 { |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1296 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
|
1297 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
|
1298 |
19372
967149bbd8d3
patch 8.2.0244: compiler warning in Lua interface
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1299 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
|
1300 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
|
1301 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
|
1302 } |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1303 lua_settop(L, 1); |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1304 return 1; |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1305 } |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1306 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1307 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
|
1308 {"__tostring", luaV_blob_tostring}, |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1309 {"__gc", luaV_blob_gc}, |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1310 {"__len", luaV_blob_len}, |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1311 {"__index", luaV_blob_index}, |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1312 {"__newindex", luaV_blob_newindex}, |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1313 {"add", luaV_blob_add}, |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1314 {NULL, NULL} |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1315 }; |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1316 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
1317 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1318 // ======= Funcref type ======= |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1319 |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1320 static luaV_Funcref * |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1321 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
|
1322 { |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1323 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
|
1324 |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1325 if (name != NULL) |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1326 { |
16028
8ad2cda3757d
patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents:
16009
diff
changeset
|
1327 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
|
1328 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
|
1329 } |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1330 f->self = NULL; |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1331 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
|
1332 lua_setmetatable(L, -2); |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1333 return f; |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1334 } |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1335 |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1336 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
|
1337 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
|
1338 { |
16028
8ad2cda3757d
patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents:
16009
diff
changeset
|
1339 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
|
1340 } |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1341 |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1342 |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1343 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
|
1344 |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1345 static int |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1346 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
|
1347 { |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1348 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
|
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 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
|
1351 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
|
1352 // 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
|
1353 // 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
|
1354 return 0; |
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 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1357 // 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
|
1358 static int |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1359 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
|
1360 { |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1361 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
|
1362 |
16028
8ad2cda3757d
patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents:
16009
diff
changeset
|
1363 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
|
1364 return 1; |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1365 } |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1366 |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1367 static int |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1368 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
|
1369 { |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1370 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
|
1371 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
|
1372 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
|
1373 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
|
1374 typval_T rettv; |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1375 |
16028
8ad2cda3757d
patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents:
16009
diff
changeset
|
1376 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
|
1377 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
|
1378 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
|
1379 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
|
1380 { |
16028
8ad2cda3757d
patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents:
16009
diff
changeset
|
1381 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
|
1382 |
14335
d59bf91128ea
patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents:
14329
diff
changeset
|
1383 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
|
1384 { |
14329
fe651f98e173
patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
1385 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
|
1386 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
|
1387 clear_tv(&v); |
14329
fe651f98e173
patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
1388 } |
16028
8ad2cda3757d
patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents:
16009
diff
changeset
|
1389 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
|
1390 if (status == OK) |
fe651f98e173
patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
1391 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
|
1392 clear_tv(&args); |
14329
fe651f98e173
patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
1393 clear_tv(&rettv); |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1394 } |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1395 if (status != OK) |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1396 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
|
1397 return 1; |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1398 } |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1399 |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1400 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
|
1401 {"__tostring", luaV_funcref_tostring}, |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1402 {"__gc", luaV_funcref_gc}, |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1403 {"__len", luaV_funcref_len}, |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1404 {"__call", luaV_funcref_call}, |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1405 {NULL, NULL} |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1406 }; |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1407 |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1408 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1409 // ======= Buffer type ======= |
3450 | 1410 |
1411 luaV_newtype(buf_T, buffer, luaV_Buffer, LUAVIM_BUFFER) | |
1412 luaV_pushtype(buf_T, buffer, luaV_Buffer) | |
1413 luaV_type_tostring(buffer, LUAVIM_BUFFER) | |
1414 | |
1415 static int | |
2330 | 1416 luaV_buffer_len(lua_State *L) |
1417 { | |
3450 | 1418 buf_T *b = (buf_T *) luaV_checkvalid(L, luaV_Buffer, 1); |
1419 lua_pushinteger(L, b->b_ml.ml_line_count); | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1420 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1421 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1422 |
2330 | 1423 static int |
1424 luaV_buffer_call(lua_State *L) | |
1425 { | |
3450 | 1426 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
|
1427 lua_settop(L, 1); |
3450 | 1428 set_curbuf(b, DOBUF_SPLIT); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1429 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1430 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1431 |
2330 | 1432 static int |
1433 luaV_buffer_index(lua_State *L) | |
1434 { | |
3450 | 1435 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
|
1436 linenr_T n = (linenr_T) lua_tointeger(L, 2); |
3450 | 1437 if (n > 0 && n <= b->b_ml.ml_line_count) |
1438 luaV_pushline(L, b, n); | |
2330 | 1439 else if (lua_isstring(L, 2)) |
1440 { | |
1441 const char *s = lua_tostring(L, 2); | |
1442 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
|
1443 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
|
1444 ? "" : (char *) b->b_sfname); |
2330 | 1445 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
|
1446 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
|
1447 ? "" : (char *) b->b_ffname); |
2330 | 1448 else if (strncmp(s, "number", 6) == 0) |
3450 | 1449 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
|
1450 // methods |
2330 | 1451 else if (strncmp(s, "insert", 6) == 0 |
1452 || strncmp(s, "next", 4) == 0 | |
1453 || strncmp(s, "previous", 8) == 0 | |
1454 || strncmp(s, "isvalid", 7) == 0) | |
1455 { | |
1456 lua_getmetatable(L, 1); | |
1457 lua_getfield(L, -1, s); | |
1458 } | |
1459 else | |
1460 lua_pushnil(L); | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1461 } |
2330 | 1462 else |
1463 lua_pushnil(L); | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1464 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1465 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1466 |
2330 | 1467 static int |
1468 luaV_buffer_newindex(lua_State *L) | |
1469 { | |
3450 | 1470 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
|
1471 linenr_T n = (linenr_T) luaL_checkinteger(L, 2); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1472 #ifdef HAVE_SANDBOX |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1473 luaV_checksandbox(L); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1474 #endif |
3450 | 1475 if (n < 1 || n > b->b_ml.ml_line_count) |
2330 | 1476 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
|
1477 if (lua_isnil(L, 3)) // delete line |
2330 | 1478 { |
1479 buf_T *buf = curbuf; | |
3450 | 1480 curbuf = b; |
2330 | 1481 if (u_savedel(n, 1L) == FAIL) |
1482 { | |
1483 curbuf = buf; | |
1484 luaL_error(L, "cannot save undo information"); | |
1485 } | |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20456
diff
changeset
|
1486 else if (ml_delete(n) == FAIL) |
2330 | 1487 { |
1488 curbuf = buf; | |
1489 luaL_error(L, "cannot delete line"); | |
1490 } | |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1491 else |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1492 { |
2330 | 1493 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
|
1494 if (b == curwin->w_buffer) // fix cursor in current window? |
2330 | 1495 { |
1496 if (curwin->w_cursor.lnum >= n) | |
1497 { | |
1498 if (curwin->w_cursor.lnum > n) | |
1499 { | |
1500 curwin->w_cursor.lnum -= 1; | |
1501 check_cursor_col(); | |
1502 } | |
21108
43e82e8133b9
patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents:
21060
diff
changeset
|
1503 else |
43e82e8133b9
patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents:
21060
diff
changeset
|
1504 check_cursor(); |
2330 | 1505 changed_cline_bef_curs(); |
1506 } | |
1507 invalidate_botline(); | |
1508 } | |
1509 } | |
1510 curbuf = buf; | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1511 } |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1512 else if (lua_isstring(L, 3)) // update line |
2330 | 1513 { |
1514 buf_T *buf = curbuf; | |
3450 | 1515 curbuf = b; |
2330 | 1516 if (u_savesub(n) == FAIL) |
1517 { | |
1518 curbuf = buf; | |
1519 luaL_error(L, "cannot save undo information"); | |
1520 } | |
1521 else if (ml_replace(n, luaV_toline(L, 3), TRUE) == FAIL) | |
1522 { | |
1523 curbuf = buf; | |
1524 luaL_error(L, "cannot replace line"); | |
1525 } | |
29660
e134ff00be57
patch 9.0.0170: various minor code formatting issues
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1526 else |
e134ff00be57
patch 9.0.0170: various minor code formatting issues
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1527 changed_bytes(n, 0); |
2330 | 1528 curbuf = buf; |
3450 | 1529 if (b == curwin->w_buffer) |
2330 | 1530 check_cursor_col(); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1531 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1532 else |
2330 | 1533 luaL_error(L, "wrong argument to change line"); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1534 return 0; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1535 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1536 |
2330 | 1537 static int |
1538 luaV_buffer_insert(lua_State *L) | |
1539 { | |
3450 | 1540 luaV_Buffer *lb = luaV_checkudata(L, 1, LUAVIM_BUFFER); |
1541 buf_T *b = (buf_T *) luaV_checkcache(L, (void *) *lb); | |
1542 linenr_T last = b->b_ml.ml_line_count; | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1543 linenr_T n = (linenr_T) luaL_optinteger(L, 3, last); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1544 buf_T *buf; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1545 luaL_checktype(L, 2, LUA_TSTRING); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1546 #ifdef HAVE_SANDBOX |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1547 luaV_checksandbox(L); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1548 #endif |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1549 // fix insertion line |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1550 if (n < 0) n = 0; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1551 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
|
1552 // insert |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1553 buf = curbuf; |
3450 | 1554 curbuf = b; |
2330 | 1555 if (u_save(n, n + 1) == FAIL) |
1556 { | |
1557 curbuf = buf; | |
1558 luaL_error(L, "cannot save undo information"); | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1559 } |
2330 | 1560 else if (ml_append(n, luaV_toline(L, 2), 0, FALSE) == FAIL) |
1561 { | |
1562 curbuf = buf; | |
1563 luaL_error(L, "cannot insert line"); | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1564 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1565 else |
2330 | 1566 appended_lines_mark(n, 1L); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1567 curbuf = buf; |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29660
diff
changeset
|
1568 update_screen(UPD_VALID); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1569 return 0; |
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 |
2330 | 1572 static int |
1573 luaV_buffer_next(lua_State *L) | |
1574 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1575 luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER); |
3450 | 1576 buf_T *buf = (buf_T *) luaV_checkcache(L, (void *) *b); |
1577 luaV_pushbuffer(L, buf->b_next); | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1578 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1579 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1580 |
2330 | 1581 static int |
1582 luaV_buffer_previous(lua_State *L) | |
1583 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1584 luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER); |
3450 | 1585 buf_T *buf = (buf_T *) luaV_checkcache(L, (void *) *b); |
1586 luaV_pushbuffer(L, buf->b_prev); | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1587 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1588 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1589 |
2330 | 1590 static int |
1591 luaV_buffer_isvalid(lua_State *L) | |
1592 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1593 luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER); |
3450 | 1594 luaV_getudata(L, *b); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1595 lua_pushboolean(L, !lua_isnil(L, -1)); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1596 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1597 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1598 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1599 static const luaL_Reg luaV_Buffer_mt[] = { |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1600 {"__tostring", luaV_buffer_tostring}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1601 {"__len", luaV_buffer_len}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1602 {"__call", luaV_buffer_call}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1603 {"__index", luaV_buffer_index}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1604 {"__newindex", luaV_buffer_newindex}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1605 {"insert", luaV_buffer_insert}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1606 {"next", luaV_buffer_next}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1607 {"previous", luaV_buffer_previous}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1608 {"isvalid", luaV_buffer_isvalid}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1609 {NULL, NULL} |
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 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1612 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1613 // ======= Window type ======= |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1614 |
3450 | 1615 luaV_newtype(win_T, window, luaV_Window, LUAVIM_WINDOW) |
1616 luaV_pushtype(win_T, window, luaV_Window) | |
1617 luaV_type_tostring(window, LUAVIM_WINDOW) | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1618 |
2330 | 1619 static int |
1620 luaV_window_call(lua_State *L) | |
1621 { | |
3450 | 1622 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
|
1623 lua_settop(L, 1); |
3450 | 1624 win_goto(w); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1625 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1626 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1627 |
2330 | 1628 static int |
1629 luaV_window_index(lua_State *L) | |
1630 { | |
3450 | 1631 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
|
1632 const char *s = luaL_checkstring(L, 2); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1633 if (strncmp(s, "buffer", 6) == 0) |
3450 | 1634 luaV_pushbuffer(L, w->w_buffer); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1635 else if (strncmp(s, "line", 4) == 0) |
3450 | 1636 lua_pushinteger(L, w->w_cursor.lnum); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1637 else if (strncmp(s, "col", 3) == 0) |
3450 | 1638 lua_pushinteger(L, w->w_cursor.col + 1); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1639 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
|
1640 lua_pushinteger(L, w->w_width); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1641 else if (strncmp(s, "height", 6) == 0) |
3450 | 1642 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
|
1643 // methods |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1644 else if (strncmp(s, "next", 4) == 0 |
2330 | 1645 || strncmp(s, "previous", 8) == 0 |
1646 || strncmp(s, "isvalid", 7) == 0) | |
1647 { | |
1648 lua_getmetatable(L, 1); | |
1649 lua_getfield(L, -1, s); | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1650 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1651 else |
2330 | 1652 lua_pushnil(L); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1653 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1654 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1655 |
2330 | 1656 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
|
1657 luaV_window_newindex(lua_State *L) |
2330 | 1658 { |
3450 | 1659 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
|
1660 const char *s = luaL_checkstring(L, 2); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1661 int v = luaL_checkinteger(L, 3); |
2330 | 1662 if (strncmp(s, "line", 4) == 0) |
1663 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1664 #ifdef HAVE_SANDBOX |
2330 | 1665 luaV_checksandbox(L); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1666 #endif |
3450 | 1667 if (v < 1 || v > w->w_buffer->b_ml.ml_line_count) |
2330 | 1668 luaL_error(L, "line out of range"); |
3450 | 1669 w->w_cursor.lnum = v; |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29660
diff
changeset
|
1670 update_screen(UPD_VALID); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1671 } |
2330 | 1672 else if (strncmp(s, "col", 3) == 0) |
1673 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1674 #ifdef HAVE_SANDBOX |
2330 | 1675 luaV_checksandbox(L); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1676 #endif |
3450 | 1677 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
|
1678 w->w_set_curswant = TRUE; |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29660
diff
changeset
|
1679 update_screen(UPD_VALID); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1680 } |
2330 | 1681 else if (strncmp(s, "width", 5) == 0) |
1682 { | |
1683 win_T *win = curwin; | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1684 #ifdef FEAT_GUI |
2330 | 1685 need_mouse_correct = TRUE; |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1686 #endif |
3450 | 1687 curwin = w; |
2330 | 1688 win_setwidth(v); |
1689 curwin = win; | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1690 } |
2330 | 1691 else if (strncmp(s, "height", 6) == 0) |
1692 { | |
1693 win_T *win = curwin; | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1694 #ifdef FEAT_GUI |
2330 | 1695 need_mouse_correct = TRUE; |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1696 #endif |
3450 | 1697 curwin = w; |
2330 | 1698 win_setheight(v); |
1699 curwin = win; | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1700 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1701 else |
2330 | 1702 luaL_error(L, "invalid window property: `%s'", s); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1703 return 0; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1704 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1705 |
2330 | 1706 static int |
1707 luaV_window_next(lua_State *L) | |
1708 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1709 luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW); |
3450 | 1710 win_T *win = (win_T *) luaV_checkcache(L, (void *) *w); |
1711 luaV_pushwindow(L, win->w_next); | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1712 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1713 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1714 |
2330 | 1715 static int |
1716 luaV_window_previous(lua_State *L) | |
1717 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1718 luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW); |
3450 | 1719 win_T *win = (win_T *) luaV_checkcache(L, (void *) *w); |
1720 luaV_pushwindow(L, win->w_prev); | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1721 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1722 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1723 |
2330 | 1724 static int |
1725 luaV_window_isvalid(lua_State *L) | |
1726 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1727 luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW); |
3450 | 1728 luaV_getudata(L, *w); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1729 lua_pushboolean(L, !lua_isnil(L, -1)); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1730 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1731 } |
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 static const luaL_Reg luaV_Window_mt[] = { |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1734 {"__tostring", luaV_window_tostring}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1735 {"__call", luaV_window_call}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1736 {"__index", luaV_window_index}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1737 {"__newindex", luaV_window_newindex}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1738 {"next", luaV_window_next}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1739 {"previous", luaV_window_previous}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1740 {"isvalid", luaV_window_isvalid}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1741 {NULL, NULL} |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1742 }; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1743 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1744 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1745 // ======= Vim module ======= |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1746 |
2330 | 1747 static int |
1748 luaV_print(lua_State *L) | |
1749 { | |
25415
02d1b2817585
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Bram Moolenaar <Bram@vim.org>
parents:
25407
diff
changeset
|
1750 int i, n = lua_gettop(L); // nargs |
02d1b2817585
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Bram Moolenaar <Bram@vim.org>
parents:
25407
diff
changeset
|
1751 const char *s; |
02d1b2817585
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Bram Moolenaar <Bram@vim.org>
parents:
25407
diff
changeset
|
1752 size_t l; |
02d1b2817585
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Bram Moolenaar <Bram@vim.org>
parents:
25407
diff
changeset
|
1753 garray_T msg_ga; |
02d1b2817585
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Bram Moolenaar <Bram@vim.org>
parents:
25407
diff
changeset
|
1754 |
02d1b2817585
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Bram Moolenaar <Bram@vim.org>
parents:
25407
diff
changeset
|
1755 ga_init2(&msg_ga, 1, 128); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1756 lua_getglobal(L, "tostring"); |
2330 | 1757 for (i = 1; i <= n; i++) |
1758 { | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1759 lua_pushvalue(L, -1); // tostring |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1760 lua_pushvalue(L, i); // arg |
2330 | 1761 lua_call(L, 1, 1); |
1762 s = lua_tolstring(L, -1, &l); | |
1763 if (s == NULL) | |
1764 return luaL_error(L, "cannot convert to string"); | |
25394
3a8b61b31724
patch 8.2.3234: crash when printing long string with Lua
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
1765 if (i > 1) |
25415
02d1b2817585
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Bram Moolenaar <Bram@vim.org>
parents:
25407
diff
changeset
|
1766 ga_append(&msg_ga, ' '); // use space instead of tab |
02d1b2817585
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Bram Moolenaar <Bram@vim.org>
parents:
25407
diff
changeset
|
1767 ga_concat_len(&msg_ga, (char_u *)s, l); |
25407
241d26b17192
patch 8.2.3240: Lua print() does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
25394
diff
changeset
|
1768 lua_pop(L, 1); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1769 } |
25415
02d1b2817585
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Bram Moolenaar <Bram@vim.org>
parents:
25407
diff
changeset
|
1770 // Replace any "\n" with "\0" |
02d1b2817585
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Bram Moolenaar <Bram@vim.org>
parents:
25407
diff
changeset
|
1771 for (i = 0; i < msg_ga.ga_len; i++) |
02d1b2817585
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Bram Moolenaar <Bram@vim.org>
parents:
25407
diff
changeset
|
1772 if (((char *)msg_ga.ga_data)[i] == '\n') |
02d1b2817585
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Bram Moolenaar <Bram@vim.org>
parents:
25407
diff
changeset
|
1773 ((char *)msg_ga.ga_data)[i] = '\0'; |
02d1b2817585
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Bram Moolenaar <Bram@vim.org>
parents:
25407
diff
changeset
|
1774 lua_pushlstring(L, msg_ga.ga_data, msg_ga.ga_len); |
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
|
1775 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
|
1776 luaV_msg(L); |
25415
02d1b2817585
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Bram Moolenaar <Bram@vim.org>
parents:
25407
diff
changeset
|
1777 |
02d1b2817585
patch 8.2.3244: Lua 5.3 print() with a long string crashes
Bram Moolenaar <Bram@vim.org>
parents:
25407
diff
changeset
|
1778 ga_clear(&msg_ga); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1779 return 0; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1780 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1781 |
2330 | 1782 static int |
3091 | 1783 luaV_debug(lua_State *L) |
1784 { | |
1785 lua_settop(L, 0); | |
1786 lua_getglobal(L, "vim"); | |
1787 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
|
1788 lua_remove(L, -2); // vim.eval at position 1 |
3091 | 1789 for (;;) |
1790 { | |
1791 const char *input; | |
1792 size_t l; | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1793 lua_pushvalue(L, 1); // vim.eval |
3091 | 1794 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
|
1795 lua_call(L, 1, 1); // return string |
3091 | 1796 input = lua_tolstring(L, -1, &l); |
1797 if (l == 0 || strcmp(input, "cont") == 0) | |
1798 return 0; | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1799 msg_putchar('\n'); // avoid outputting on input line |
3091 | 1800 if (luaL_loadbuffer(L, input, l, "=(debug command)") |
1801 || lua_pcall(L, 0, 0, 0)) | |
1802 luaV_emsg(L); | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1803 lua_settop(L, 1); // remove eventual returns, but keep vim.eval |
3091 | 1804 } |
1805 } | |
1806 | |
25503
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1807 static dict_T * |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1808 luaV_get_var_scope(lua_State *L) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1809 { |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1810 const char *scope = luaL_checkstring(L, 1); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1811 dict_T *dict = NULL; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1812 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1813 if (STRICMP((char *)scope, "g") == 0) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1814 dict = get_globvar_dict(); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1815 else if (STRICMP((char *)scope, "v") == 0) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1816 dict = get_vimvar_dict(); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1817 else if (STRICMP((char *)scope, "b") == 0) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1818 dict = curbuf->b_vars; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1819 else if (STRICMP((char *)scope, "w") == 0) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1820 dict = curwin->w_vars; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1821 else if (STRICMP((char *)scope, "t") == 0) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1822 dict = curtab->tp_vars; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1823 else |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1824 { |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1825 luaL_error(L, "invalid scope %s", scope); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1826 return NULL; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1827 } |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1828 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1829 return dict; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1830 } |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1831 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1832 static int |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1833 luaV_setvar(lua_State *L) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1834 { |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1835 dict_T *dict; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1836 dictitem_T *di; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1837 size_t len; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1838 char *name; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1839 int del; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1840 char *error = NULL; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1841 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1842 name = (char *)luaL_checklstring(L, 3, &len); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1843 del = (lua_gettop(L) < 4) || lua_isnil(L, 4); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1844 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1845 dict = luaV_get_var_scope(L); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1846 if (dict == NULL) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1847 return 0; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1848 |
25527
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
1849 di = dict_find(dict, (char_u *)name, (int)len); |
25503
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1850 if (di != NULL) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1851 { |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1852 if (di->di_flags & DI_FLAGS_RO) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1853 error = "variable is read-only"; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1854 else if (di->di_flags & DI_FLAGS_LOCK) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1855 error = "variable is locked"; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1856 else if (del && di->di_flags & DI_FLAGS_FIX) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1857 error = "variable is fixed"; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1858 if (error != NULL) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1859 return luaL_error(L, error); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1860 } |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1861 else if (dict->dv_lock) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1862 return luaL_error(L, "Dictionary is locked"); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1863 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1864 if (del) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1865 { |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1866 // Delete the key |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1867 if (di == NULL) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1868 // Doesn't exist, nothing to do |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1869 return 0; |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1870 // Delete the entry |
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1871 dictitem_remove(dict, di, "Lua delete variable"); |
25503
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1872 } |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1873 else |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1874 { |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1875 // Update the key |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1876 typval_T tv; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1877 |
25881
2ee0425960fe
patch 8.2.3474: some places use "Vimscript" instead of "Vim script"
Bram Moolenaar <Bram@vim.org>
parents:
25527
diff
changeset
|
1878 // Convert the lua value to a Vim script type in the temporary variable |
25503
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1879 lua_pushvalue(L, 4); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1880 if (luaV_totypval(L, -1, &tv) == FAIL) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1881 return luaL_error(L, "Couldn't convert lua value"); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1882 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1883 if (di == NULL) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1884 { |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1885 // Need to create an entry |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1886 di = dictitem_alloc((char_u *)name); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1887 if (di == NULL) |
25515
d84f6784c27c
patch 8.2.3294: Lua: memory leak when adding dict item fails
Bram Moolenaar <Bram@vim.org>
parents:
25509
diff
changeset
|
1888 { |
d84f6784c27c
patch 8.2.3294: Lua: memory leak when adding dict item fails
Bram Moolenaar <Bram@vim.org>
parents:
25509
diff
changeset
|
1889 clear_tv(&tv); |
25503
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1890 return 0; |
25515
d84f6784c27c
patch 8.2.3294: Lua: memory leak when adding dict item fails
Bram Moolenaar <Bram@vim.org>
parents:
25509
diff
changeset
|
1891 } |
25503
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1892 // Update the value |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1893 copy_tv(&tv, &di->di_tv); |
25509
7ed54019fbb8
patch 8.2.3291: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
1894 if (dict_add(dict, di) == FAIL) |
25515
d84f6784c27c
patch 8.2.3294: Lua: memory leak when adding dict item fails
Bram Moolenaar <Bram@vim.org>
parents:
25509
diff
changeset
|
1895 { |
d84f6784c27c
patch 8.2.3294: Lua: memory leak when adding dict item fails
Bram Moolenaar <Bram@vim.org>
parents:
25509
diff
changeset
|
1896 dictitem_free(di); |
d84f6784c27c
patch 8.2.3294: Lua: memory leak when adding dict item fails
Bram Moolenaar <Bram@vim.org>
parents:
25509
diff
changeset
|
1897 clear_tv(&tv); |
25509
7ed54019fbb8
patch 8.2.3291: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents:
25503
diff
changeset
|
1898 return luaL_error(L, "Couldn't add to dictionary"); |
25515
d84f6784c27c
patch 8.2.3294: Lua: memory leak when adding dict item fails
Bram Moolenaar <Bram@vim.org>
parents:
25509
diff
changeset
|
1899 } |
d84f6784c27c
patch 8.2.3294: Lua: memory leak when adding dict item fails
Bram Moolenaar <Bram@vim.org>
parents:
25509
diff
changeset
|
1900 } |
d84f6784c27c
patch 8.2.3294: Lua: memory leak when adding dict item fails
Bram Moolenaar <Bram@vim.org>
parents:
25509
diff
changeset
|
1901 else |
25503
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1902 { |
33339
441ceb1c45c1
patch 9.0.1933: Can change the type of a v: variable using if_lua
Christian Brabandt <cb@256bit.org>
parents:
32814
diff
changeset
|
1903 int type_error = FALSE; |
441ceb1c45c1
patch 9.0.1933: Can change the type of a v: variable using if_lua
Christian Brabandt <cb@256bit.org>
parents:
32814
diff
changeset
|
1904 if (dict == get_vimvar_dict() |
441ceb1c45c1
patch 9.0.1933: Can change the type of a v: variable using if_lua
Christian Brabandt <cb@256bit.org>
parents:
32814
diff
changeset
|
1905 && !before_set_vvar((char_u *)name, di, &tv, TRUE, &type_error)) |
441ceb1c45c1
patch 9.0.1933: Can change the type of a v: variable using if_lua
Christian Brabandt <cb@256bit.org>
parents:
32814
diff
changeset
|
1906 { |
441ceb1c45c1
patch 9.0.1933: Can change the type of a v: variable using if_lua
Christian Brabandt <cb@256bit.org>
parents:
32814
diff
changeset
|
1907 clear_tv(&tv); |
441ceb1c45c1
patch 9.0.1933: Can change the type of a v: variable using if_lua
Christian Brabandt <cb@256bit.org>
parents:
32814
diff
changeset
|
1908 if (type_error) |
441ceb1c45c1
patch 9.0.1933: Can change the type of a v: variable using if_lua
Christian Brabandt <cb@256bit.org>
parents:
32814
diff
changeset
|
1909 return luaL_error(L, |
441ceb1c45c1
patch 9.0.1933: Can change the type of a v: variable using if_lua
Christian Brabandt <cb@256bit.org>
parents:
32814
diff
changeset
|
1910 "Setting v:%s to value with wrong type", name); |
441ceb1c45c1
patch 9.0.1933: Can change the type of a v: variable using if_lua
Christian Brabandt <cb@256bit.org>
parents:
32814
diff
changeset
|
1911 return 0; |
441ceb1c45c1
patch 9.0.1933: Can change the type of a v: variable using if_lua
Christian Brabandt <cb@256bit.org>
parents:
32814
diff
changeset
|
1912 } |
25503
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1913 // Clear the old value |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1914 clear_tv(&di->di_tv); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1915 // Update the value |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1916 copy_tv(&tv, &di->di_tv); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1917 } |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1918 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1919 // Clear the temporary variable |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1920 clear_tv(&tv); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1921 } |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1922 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1923 return 0; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1924 } |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1925 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1926 static int |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1927 luaV_getvar(lua_State *L) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1928 { |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1929 dict_T *dict = luaV_get_var_scope(L); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1930 size_t len; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1931 const char *name = luaL_checklstring(L, 3, &len); |
25527
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
1932 dictitem_T *di = dict_find(dict, (char_u *)name, (int)len); |
25503
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1933 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1934 if (di == NULL) |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1935 return 0; // nil |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1936 |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1937 luaV_pushtypval(L, &di->di_tv); |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1938 return 1; |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1939 } |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
1940 |
3091 | 1941 static int |
2330 | 1942 luaV_command(lua_State *L) |
1943 { | |
25527
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
1944 char_u *s = vim_strsave((char_u *)luaL_checkstring(L, 1)); |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
1945 |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
1946 execute_cmds_from_string(s); |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
1947 vim_free(s); |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29660
diff
changeset
|
1948 update_screen(UPD_VALID); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1949 return 0; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1950 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1951 |
2330 | 1952 static int |
1953 luaV_eval(lua_State *L) | |
1954 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1955 typval_T *tv = eval_expr((char_u *) luaL_checkstring(L, 1), NULL); |
25527
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
1956 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1957 if (tv == NULL) luaL_error(L, "invalid expression"); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1958 luaV_pushtypval(L, tv); |
4293 | 1959 free_tv(tv); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1960 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1961 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1962 |
2330 | 1963 static int |
2331
3840b7508835
Make it easier to build with Lua. Remove compiler warnings.
Bram Moolenaar <bram@vim.org>
parents:
2330
diff
changeset
|
1964 luaV_beep(lua_State *L UNUSED) |
2330 | 1965 { |
6949 | 1966 vim_beep(BO_LANG); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1967 return 0; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1968 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1969 |
2330 | 1970 static int |
1971 luaV_line(lua_State *L) | |
1972 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1973 luaV_pushline(L, curbuf, curwin->w_cursor.lnum); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1974 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1975 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1976 |
2330 | 1977 static int |
3450 | 1978 luaV_list(lua_State *L) |
1979 { | |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1980 list_T *l; |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1981 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
|
1982 |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1983 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
|
1984 luaL_error(L, "table expected, got %s", luaL_typename(L, 1)); |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1985 |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1986 l = list_alloc(); |
3450 | 1987 if (l == NULL) |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
1988 { |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1989 lua_pushnil(L); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1990 return 1; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1991 } |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1992 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1993 luaV_newlist(L, l); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1994 if (!initarg) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1995 return 1; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1996 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1997 // traverse table to init list |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1998 int notnil, i = 0; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
1999 typval_T v; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2000 do |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2001 { |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2002 lua_rawgeti(L, 1, ++i); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2003 notnil = !lua_isnil(L, -1); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2004 if (notnil) |
14335
d59bf91128ea
patch 8.1.0183: Lua API changed, breaking the build
Christian Brabandt <cb@256bit.org>
parents:
14329
diff
changeset
|
2005 { |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2006 luaV_checktypval(L, -1, &v, "vim.list"); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2007 list_append_tv(l, &v); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2008 clear_tv(&v); |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2009 } |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2010 lua_pop(L, 1); // value |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2011 } while (notnil); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2012 |
3450 | 2013 return 1; |
2014 } | |
2015 | |
2016 static int | |
2017 luaV_dict(lua_State *L) | |
2018 { | |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2019 dict_T *d; |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2020 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
|
2021 |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2022 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
|
2023 luaL_error(L, "table expected, got %s", luaL_typename(L, 1)); |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2024 |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2025 d = dict_alloc(); |
3450 | 2026 if (d == NULL) |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2027 { |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2028 lua_pushnil(L); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2029 return 1; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2030 } |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2031 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2032 luaV_newdict(L, d); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2033 if (!initarg) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2034 return 1; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2035 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2036 // traverse table to init dict |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2037 lua_pushnil(L); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2038 while (lua_next(L, 1)) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2039 { |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2040 char_u *key; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2041 dictitem_T *di; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2042 typval_T v; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2043 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2044 lua_pushvalue(L, -2); // dup key in case it's a number |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2045 key = (char_u *) lua_tostring(L, -1); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2046 if (key == NULL) |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2047 { |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2048 lua_pushnil(L); |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2049 return 1; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2050 } |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2051 if (*key == NUL) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2052 luaL_error(L, "table has empty key"); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2053 luaV_checktypval(L, -2, &v, "vim.dict"); // value |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2054 di = dictitem_alloc(key); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2055 if (di == NULL || dict_add(d, di) == FAIL) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2056 { |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2057 vim_free(di); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2058 lua_pushnil(L); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2059 return 1; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2060 } |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2061 di->di_tv = v; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2062 lua_pop(L, 2); // key copy and value |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2063 } |
14329
fe651f98e173
patch 8.1.0180: static analysis errors in Lua interface
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
2064 |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2065 return 1; |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2066 } |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2067 |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2068 static int |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2069 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
|
2070 { |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2071 blob_T *b; |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2072 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
|
2073 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2074 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
|
2075 luaL_error(L, "string expected, got %s", luaL_typename(L, 1)); |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2076 |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2077 b = blob_alloc(); |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2078 if (b == NULL) |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2079 { |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2080 lua_pushnil(L); |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2081 return 1; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2082 } |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2083 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2084 luaV_newblob(L, b); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2085 if (!initarg) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2086 return 1; |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2087 |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2088 // traverse table to init blob |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2089 size_t i, l = 0; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2090 const char *s = lua_tolstring(L, 1, &l); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2091 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2092 if (ga_grow(&b->bv_ga, (int)l) == OK) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2093 for (i = 0; i < l; ++i) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2094 ga_append(&b->bv_ga, s[i]); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2095 |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2096 return 1; |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2097 } |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2098 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2099 static int |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2100 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
|
2101 { |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2102 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
|
2103 // 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
|
2104 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
|
2105 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
|
2106 luaV_newfuncref(L, (char_u *) name); |
3450 | 2107 return 1; |
2108 } | |
2109 | |
2110 static int | |
2330 | 2111 luaV_buffer(lua_State *L) |
2112 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2113 buf_T *buf; |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2114 if (lua_isstring(L, 1)) // get by number or name? |
2330 | 2115 { |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2116 if (lua_isnumber(L, 1)) // by number? |
2330 | 2117 { |
2118 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
|
2119 FOR_ALL_BUFFERS(buf) |
2330 | 2120 if (buf->b_fnum == n) break; |
2121 } | |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2122 else // by name |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2123 { |
2330 | 2124 size_t l; |
2125 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
|
2126 FOR_ALL_BUFFERS(buf) |
2330 | 2127 { |
2128 if (buf->b_ffname == NULL || buf->b_sfname == NULL) | |
2129 { | |
2130 if (l == 0) break; | |
2131 } | |
2331
3840b7508835
Make it easier to build with Lua. Remove compiler warnings.
Bram Moolenaar <bram@vim.org>
parents:
2330
diff
changeset
|
2132 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
|
2133 || strncmp(s, (char *)buf->b_sfname, l) == 0) |
2330 | 2134 break; |
2135 } | |
2136 } | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2137 } |
3450 | 2138 else |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2139 buf = (lua_toboolean(L, 1)) ? firstbuf : curbuf; // first buffer? |
3450 | 2140 luaV_pushbuffer(L, buf); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2141 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2142 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2143 |
2330 | 2144 static int |
2145 luaV_window(lua_State *L) | |
2146 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2147 win_T *win; |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2148 if (lua_isnumber(L, 1)) // get by number? |
2330 | 2149 { |
2150 int n = lua_tointeger(L, 1); | |
2151 for (win = firstwin; win != NULL; win = win->w_next, n--) | |
2152 if (n == 1) break; | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2153 } |
3450 | 2154 else |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2155 win = (lua_toboolean(L, 1)) ? firstwin : curwin; // first window? |
3450 | 2156 luaV_pushwindow(L, win); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2157 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2158 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2159 |
2330 | 2160 static int |
2161 luaV_open(lua_State *L) | |
2162 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2163 char_u *s = NULL; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2164 #ifdef HAVE_SANDBOX |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2165 luaV_checksandbox(L); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2166 #endif |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2167 if (lua_isstring(L, 1)) s = (char_u *) lua_tostring(L, 1); |
3200 | 2168 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
|
2169 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2170 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2171 |
2330 | 2172 static int |
3450 | 2173 luaV_type(lua_State *L) |
2330 | 2174 { |
3450 | 2175 luaL_checkany(L, 1); |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2176 if (lua_type(L, 1) == LUA_TUSERDATA) // check vim udata? |
3450 | 2177 { |
2178 lua_settop(L, 1); | |
2179 if (lua_getmetatable(L, 1)) | |
2180 { | |
2181 luaV_getfield(L, LUAVIM_LIST); | |
2182 if (lua_rawequal(L, -1, 2)) | |
2183 { | |
2184 lua_pushstring(L, "list"); | |
2185 return 1; | |
2186 } | |
2187 luaV_getfield(L, LUAVIM_DICT); | |
2188 if (lua_rawequal(L, -1, 2)) | |
2189 { | |
2190 lua_pushstring(L, "dict"); | |
2191 return 1; | |
2192 } | |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2193 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
|
2194 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
|
2195 { |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2196 lua_pushstring(L, "blob"); |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2197 return 1; |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2198 } |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2199 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
|
2200 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
|
2201 { |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2202 lua_pushstring(L, "funcref"); |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2203 return 1; |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2204 } |
3450 | 2205 luaV_getfield(L, LUAVIM_BUFFER); |
2206 if (lua_rawequal(L, -1, 2)) | |
2207 { | |
2208 lua_pushstring(L, "buffer"); | |
2209 return 1; | |
2210 } | |
2211 luaV_getfield(L, LUAVIM_WINDOW); | |
2212 if (lua_rawequal(L, -1, 2)) | |
2213 { | |
2214 lua_pushstring(L, "window"); | |
2215 return 1; | |
2216 } | |
2217 } | |
2218 } | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2219 lua_pushstring(L, luaL_typename(L, 1)); // fallback |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2220 return 1; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2221 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2222 |
20441
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2223 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
|
2224 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
|
2225 { |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2226 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
|
2227 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
|
2228 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
|
2229 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
|
2230 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
|
2231 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
|
2232 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
|
2233 |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2234 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
|
2235 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
|
2236 |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2237 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
|
2238 |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2239 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
|
2240 { |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2241 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
|
2242 { |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2243 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
|
2244 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
|
2245 } |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2246 } |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2247 |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2248 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
|
2249 |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2250 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
|
2251 { |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2252 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
|
2253 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
|
2254 } |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2255 |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2256 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
|
2257 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
|
2258 |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2259 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
|
2260 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
|
2261 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
|
2262 |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2263 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
|
2264 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
|
2265 else |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2266 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
|
2267 } |
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2268 |
25527
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2269 /* |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2270 * Return the Vim version as a Lua table |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2271 */ |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2272 static int |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2273 luaV_version(lua_State *L) |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2274 { |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2275 lua_newtable(L); |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2276 lua_pushstring(L, "major"); |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2277 lua_pushinteger(L, VIM_VERSION_MAJOR); |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2278 lua_settable(L, -3); |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2279 lua_pushstring(L, "minor"); |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2280 lua_pushinteger(L, VIM_VERSION_MINOR); |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2281 lua_settable(L, -3); |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2282 lua_pushstring(L, "patch"); |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2283 lua_pushinteger(L, highest_patch()); |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2284 lua_settable(L, -3); |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2285 return 1; |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2286 } |
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2287 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2288 static const luaL_Reg luaV_module[] = { |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2289 {"command", luaV_command}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2290 {"eval", luaV_eval}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2291 {"beep", luaV_beep}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2292 {"line", luaV_line}, |
3450 | 2293 {"list", luaV_list}, |
2294 {"dict", luaV_dict}, | |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2295 {"blob", luaV_blob}, |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2296 {"funcref", luaV_funcref}, |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2297 {"buffer", luaV_buffer}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2298 {"window", luaV_window}, |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2299 {"open", luaV_open}, |
3450 | 2300 {"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
|
2301 {"call", luaV_call}, |
25503
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2302 {"_getvar", luaV_getvar}, |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2303 {"_setvar", luaV_setvar}, |
25527
d5e9c05b4811
patch 8.2.3300: Lua: can only execute on Vim command at a time
Bram Moolenaar <Bram@vim.org>
parents:
25515
diff
changeset
|
2304 {"version", luaV_version}, |
24385
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2305 {"lua_version", NULL}, |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2306 {NULL, NULL} |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2307 }; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2308 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2309 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2310 * 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
|
2311 */ |
3450 | 2312 static int |
2313 luaV_free(lua_State *L) | |
2314 { | |
2315 lua_pushnil(L); | |
2316 luaV_setudata(L, lua_touserdata(L, 1)); | |
2317 return 0; | |
2318 } | |
2319 | |
2320 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
|
2321 luaV_luaeval(lua_State *L) |
3450 | 2322 { |
2323 luaL_Buffer b; | |
2324 size_t l; | |
2325 const char *str = lua_tolstring(L, 1, &l); | |
2326 typval_T *arg = (typval_T *) lua_touserdata(L, 2); | |
2327 typval_T *rettv = (typval_T *) lua_touserdata(L, 3); | |
2328 luaL_buffinit(L, &b); | |
2329 luaL_addlstring(&b, LUAVIM_EVALHEADER, sizeof(LUAVIM_EVALHEADER) - 1); | |
2330 luaL_addlstring(&b, str, l); | |
2331 luaL_pushresult(&b); | |
2332 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
|
2333 if (luaL_loadbuffer(L, str, l, LUAVIM_EVALNAME)) // compile error? |
3450 | 2334 { |
2335 luaV_emsg(L); | |
2336 return 0; | |
2337 } | |
2338 luaV_pushtypval(L, arg); | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2339 if (lua_pcall(L, 1, 1, 0)) // running error? |
3450 | 2340 { |
2341 luaV_emsg(L); | |
2342 return 0; | |
2343 } | |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2344 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
|
2345 emsg("luaeval: cannot convert value"); |
6590 | 2346 return 0; |
3450 | 2347 } |
2348 | |
2349 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
|
2350 luaV_setref(lua_State *L) |
3450 | 2351 { |
16028
8ad2cda3757d
patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents:
16009
diff
changeset
|
2352 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
|
2353 int abort = FALSE; |
6565 | 2354 |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2355 lua_pushlightuserdata(L, (void *) LUAVIM_UDATA_CACHE); |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2356 lua_rawget(L, LUA_REGISTRYINDEX); // the cache table |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2357 |
3450 | 2358 luaV_getfield(L, LUAVIM_LIST); |
2359 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
|
2360 luaV_getfield(L, LUAVIM_FUNCREF); |
3450 | 2361 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
|
2362 // traverse cache table |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2363 while (!abort && lua_next(L, 2) != 0) |
3450 | 2364 { |
2365 lua_getmetatable(L, -1); | |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2366 if (lua_rawequal(L, -1, 3)) // list? |
3450 | 2367 { |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2368 list_T *l = (list_T *)lua_touserdata(L, 6); // key |
16028
8ad2cda3757d
patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents:
16009
diff
changeset
|
2369 |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
16099
diff
changeset
|
2370 abort = set_ref_in_list(l, copyID); |
3450 | 2371 } |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2372 else if (lua_rawequal(L, -1, 4)) // dict? |
3450 | 2373 { |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2374 dict_T *d = (dict_T *)lua_touserdata(L, 6); // key |
16028
8ad2cda3757d
patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents:
16009
diff
changeset
|
2375 |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
16099
diff
changeset
|
2376 abort = set_ref_in_dict(d, copyID); |
3450 | 2377 } |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2378 else if (lua_rawequal(L, -1, 5)) // funcref? |
16028
8ad2cda3757d
patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents:
16009
diff
changeset
|
2379 { |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2380 luaV_Funcref *f = (luaV_Funcref *)lua_touserdata(L, 6); // key |
16028
8ad2cda3757d
patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents:
16009
diff
changeset
|
2381 |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
16099
diff
changeset
|
2382 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
|
2383 } |
8ad2cda3757d
patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents:
16009
diff
changeset
|
2384 lua_pop(L, 2); // metatable and value |
3450 | 2385 } |
6565 | 2386 lua_pushinteger(L, abort); |
6590 | 2387 return 1; |
3450 | 2388 } |
2389 | |
24385
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2390 static int |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2391 luaV_pushversion(lua_State *L) |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2392 { |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2393 int major = 0; |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2394 int minor = 0; |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2395 int patch = 0; |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2396 char s[16]; |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2397 |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2398 sscanf(LUAVIM_VERSION, "Lua %d.%d.%d", &major, &minor, &patch); |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2399 vim_snprintf(s, sizeof(s), "%d.%d.%d", major, minor, patch); |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2400 lua_pushstring(L, s); |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2401 return 0; |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2402 } |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2403 |
20441
86dde5c4b375
patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents:
19846
diff
changeset
|
2404 #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
|
2405 "vim.fn = setmetatable({}, {\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2406 " __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
|
2407 " local function _fn(...)\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2408 " 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
|
2409 " end\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2410 " t[key] = _fn\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2411 " return _fn\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2412 " end\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2413 " })" |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2414 |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2415 #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
|
2416 "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
|
2417 "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
|
2418 " 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
|
2419 " 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
|
2420 " result = {}\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2421 " 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
|
2422 " 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
|
2423 " end\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2424 " return result\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2425 " end\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2426 " 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
|
2427 " 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
|
2428 " 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
|
2429 " 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
|
2430 " local pathtrails_ordered = {}\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2431 " -- 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
|
2432 " -- 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
|
2433 " local orig = {}\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2434 " 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
|
2435 " 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
|
2436 " 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
|
2437 " end\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2438 " 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
|
2439 " -- /?.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
|
2440 " 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
|
2441 " else\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2442 " local pathtrails = {}\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2443 " 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
|
2444 " -- 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
|
2445 " -- /?.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
|
2446 " -- suffixes are.\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2447 " 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
|
2448 " 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
|
2449 " pathtrails[pathtrail] = true\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2450 " 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
|
2451 " end\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2452 " end\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2453 " end\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2454 " local new = {}\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2455 " 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
|
2456 " 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
|
2457 " 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
|
2458 " 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
|
2459 " -- 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
|
2460 " -- 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
|
2461 " 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
|
2462 " 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
|
2463 " end\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2464 " end\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2465 " end\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2466 " 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
|
2467 " -- 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
|
2468 " -- 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
|
2469 " -- 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
|
2470 " -- 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
|
2471 " 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
|
2472 " 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
|
2473 " end\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2474 " end\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2475 " 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
|
2476 " end\n"\ |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2477 " 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
|
2478 "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
|
2479 |
25503
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2480 #define LUA_VIM_SETUP_VARIABLE_DICTS \ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2481 "do\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2482 " local function make_dict_accessor(scope)\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2483 " local mt = {}\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2484 " function mt:__newindex(k, v)\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2485 " return vim._setvar(scope, 0, k, v)\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2486 " end\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2487 " function mt:__index(k)\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2488 " return vim._getvar(scope, 0, k)\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2489 " end\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2490 " return setmetatable({}, mt)\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2491 " end\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2492 " vim.g = make_dict_accessor('g')\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2493 " vim.v = make_dict_accessor('v')\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2494 " vim.b = make_dict_accessor('b')\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2495 " vim.w = make_dict_accessor('w')\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2496 " vim.t = make_dict_accessor('t')\n"\ |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2497 "end" |
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2498 |
2330 | 2499 static int |
2500 luaopen_vim(lua_State *L) | |
2501 { | |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2502 lua_newtable(L); // cache table |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2503 lua_newtable(L); // cache table's metatable |
3450 | 2504 lua_pushstring(L, "v"); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2505 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
|
2506 lua_setmetatable(L, -2); // cache is weak-valued |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2507 // put the cache table in the registry for luaV_get/setudata() |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2508 lua_pushlightuserdata(L, (void *) LUAVIM_UDATA_CACHE); |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2509 lua_pushvalue(L, -2); |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2510 lua_rawset(L, LUA_REGISTRYINDEX); |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2511 lua_pop(L, 1); // we don't need the cache table here anymore |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2512 // print |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2513 lua_pushcfunction(L, luaV_print); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2514 lua_setglobal(L, "print"); |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2515 // debug.debug |
3091 | 2516 lua_getglobal(L, "debug"); |
2517 lua_pushcfunction(L, luaV_debug); | |
2518 lua_setfield(L, -2, "debug"); | |
2519 lua_pop(L, 1); | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2520 // free |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2521 lua_pushlightuserdata(L, (void *) LUAVIM_FREE); |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2522 lua_pushcfunction(L, luaV_free); |
3450 | 2523 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
|
2524 // luaeval |
3450 | 2525 lua_pushlightuserdata(L, (void *) LUAVIM_LUAEVAL); |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2526 lua_pushcfunction(L, luaV_luaeval); |
3450 | 2527 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
|
2528 // setref |
3450 | 2529 lua_pushlightuserdata(L, (void *) LUAVIM_SETREF); |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2530 lua_pushcfunction(L, luaV_setref); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2531 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
|
2532 // register |
3450 | 2533 luaV_newmetatable(L, LUAVIM_LIST); |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2534 luaV_register(L, luaV_List_mt); |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2535 lua_pop(L, 1); |
3450 | 2536 luaV_newmetatable(L, LUAVIM_DICT); |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2537 luaV_register(L, luaV_Dict_mt); |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2538 lua_pop(L, 1); |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
2539 luaV_newmetatable(L, LUAVIM_BLOB); |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2540 luaV_register(L, luaV_Blob_mt); |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2541 lua_pop(L, 1); |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2542 luaV_newmetatable(L, LUAVIM_FUNCREF); |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2543 luaV_register(L, luaV_Funcref_mt); |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2544 lua_pop(L, 1); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2545 luaV_newmetatable(L, LUAVIM_BUFFER); |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2546 luaV_register(L, luaV_Buffer_mt); |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2547 lua_pop(L, 1); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2548 luaV_newmetatable(L, LUAVIM_WINDOW); |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2549 luaV_register(L, luaV_Window_mt); |
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2550 lua_pop(L, 1); |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2551 lua_newtable(L); // vim table |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2552 luaV_register(L, luaV_module); |
24385
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2553 luaV_pushversion(L); |
0878f0fd349b
patch 8.2.2733: detecting Lua version is not reliable
Bram Moolenaar <Bram@vim.org>
parents:
24073
diff
changeset
|
2554 lua_setfield(L, -2, "lua_version"); |
3450 | 2555 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
|
2556 // 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
|
2557 (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
|
2558 (void)luaL_dostring(L, LUA_VIM_UPDATE_PACKAGE_PATHS); |
25503
9947b7e4b319
patch 8.2.3288: cannot easily access namespace dictionaries from Lua
Bram Moolenaar <Bram@vim.org>
parents:
25415
diff
changeset
|
2559 (void)luaL_dostring(L, LUA_VIM_SETUP_VARIABLE_DICTS); |
20609
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2560 |
32807
0582b3b40319
patch 9.0.1719: if_lua: crash for for Lua functions invoked via Vim callbacks
Christian Brabandt <cb@256bit.org>
parents:
32009
diff
changeset
|
2561 lua_getglobal(L, LUAVIM_NAME); |
20609
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2562 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
|
2563 |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2564 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
|
2565 luaV_emsg(L); |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2566 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2567 return 0; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2568 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2569 |
2330 | 2570 static lua_State * |
2571 luaV_newstate(void) | |
2572 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2573 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
|
2574 luaL_openlibs(L); // core libs |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2575 lua_pushcfunction(L, luaopen_vim); // vim |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2576 lua_call(L, 0, 0); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2577 return L; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2578 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2579 |
2330 | 2580 static void |
2581 luaV_setrange(lua_State *L, int line1, int line2) | |
2582 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2583 lua_getglobal(L, LUAVIM_NAME); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2584 lua_pushinteger(L, line1); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2585 lua_setfield(L, -2, "firstline"); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2586 lua_pushinteger(L, line2); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2587 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
|
2588 lua_pop(L, 1); // vim table |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2589 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2590 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2591 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2592 // ======= Interface ======= |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2593 |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2594 static lua_State *L = NULL; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2595 |
2330 | 2596 static int |
3450 | 2597 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
|
2598 { |
8c512e2c7cb5
Fix: Lua interface tried to load the library when closing a buffer or window.
Bram Moolenaar <bram@vim.org>
parents:
2431
diff
changeset
|
2599 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
|
2600 } |
8c512e2c7cb5
Fix: Lua interface tried to load the library when closing a buffer or window.
Bram Moolenaar <bram@vim.org>
parents:
2431
diff
changeset
|
2601 |
8c512e2c7cb5
Fix: Lua interface tried to load the library when closing a buffer or window.
Bram Moolenaar <bram@vim.org>
parents:
2431
diff
changeset
|
2602 static int |
2330 | 2603 lua_init(void) |
2604 { | |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2605 if (lua_isopen()) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2606 return OK; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2607 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2608 #ifdef DYNAMIC_LUA |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2609 if (!lua_enabled(TRUE)) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2610 { |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2611 emsg(_("Lua library cannot be loaded.")); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2612 return FAIL; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2613 } |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2614 #endif |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2615 L = luaV_newstate(); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2616 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2617 return OK; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2618 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2619 |
2330 | 2620 void |
2621 lua_end(void) | |
2622 { | |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2623 if (!lua_isopen()) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2624 return; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2625 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2626 lua_close(L); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2627 L = NULL; |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2628 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2629 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2630 /* |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2631 * ex commands |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2632 */ |
2330 | 2633 void |
2634 ex_lua(exarg_T *eap) | |
2635 { | |
22719
8da5e18effc5
patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents:
21367
diff
changeset
|
2636 char *script = (char *)script_get(eap, eap->arg); |
8da5e18effc5
patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents:
21367
diff
changeset
|
2637 |
8da5e18effc5
patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents:
21367
diff
changeset
|
2638 if (!eap->skip && lua_init() == OK) |
2330 | 2639 { |
22719
8da5e18effc5
patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents:
21367
diff
changeset
|
2640 char *s = script != NULL ? script : (char *)eap->arg; |
8da5e18effc5
patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents:
21367
diff
changeset
|
2641 |
2330 | 2642 luaV_setrange(L, eap->line1, eap->line2); |
2643 if (luaL_loadbuffer(L, s, strlen(s), LUAVIM_CHUNKNAME) | |
2644 || lua_pcall(L, 0, 0, 0)) | |
2645 luaV_emsg(L); | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2646 } |
22719
8da5e18effc5
patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents:
21367
diff
changeset
|
2647 if (script != NULL) |
8da5e18effc5
patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents:
21367
diff
changeset
|
2648 vim_free(script); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2649 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2650 |
2330 | 2651 void |
2652 ex_luado(exarg_T *eap) | |
2653 { | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2654 linenr_T l; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2655 const char *s = (const char *) eap->arg; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2656 luaL_Buffer b; |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2657 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
|
2658 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
|
2659 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2660 if (lua_init() == FAIL) return; |
2330 | 2661 if (u_save(eap->line1 - 1, eap->line2 + 1) == FAIL) |
2662 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15328
diff
changeset
|
2663 emsg(_("cannot save undo information")); |
2330 | 2664 return; |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2665 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2666 luaV_setrange(L, eap->line1, eap->line2); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2667 luaL_buffinit(L, &b); |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2668 luaL_addlstring(&b, "return function(line, linenr) ", 30); // header |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2669 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
|
2670 luaL_addlstring(&b, " end", 4); // footer |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2671 luaL_pushresult(&b); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2672 s = lua_tolstring(L, -1, &len); |
2330 | 2673 if (luaL_loadbuffer(L, s, len, LUAVIM_CHUNKNAME)) |
2674 { | |
2675 luaV_emsg(L); | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2676 lua_pop(L, 1); // function body |
2330 | 2677 return; |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2678 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2679 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
|
2680 lua_replace(L, -2); // function -> body |
2330 | 2681 for (l = eap->line1; l <= eap->line2; l++) |
2682 { | |
21108
43e82e8133b9
patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents:
21060
diff
changeset
|
2683 // 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
|
2684 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
|
2685 break; |
6c3d42d18366
patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents:
10025
diff
changeset
|
2686 |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2687 lua_pushvalue(L, -1); // function |
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2688 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
|
2689 lua_pushinteger(L, l); // current line number as arg |
3459 | 2690 if (lua_pcall(L, 2, 1, 0)) |
2330 | 2691 { |
2692 luaV_emsg(L); | |
2693 break; | |
2694 } | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2695 // 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
|
2696 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
|
2697 break; |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2698 if (lua_isstring(L, -1)) // update line? |
2330 | 2699 { |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2700 #ifdef HAVE_SANDBOX |
2330 | 2701 luaV_checksandbox(L); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2702 #endif |
2330 | 2703 ml_replace(l, luaV_toline(L, -1), TRUE); |
2704 changed_bytes(l, 0); | |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2705 lua_pop(L, 1); // result from luaV_toline |
2330 | 2706 } |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2707 lua_pop(L, 1); // line |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2708 } |
18798
f0f9692d4487
patch 8.1.2387: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2709 lua_pop(L, 1); // function |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2710 check_cursor(); |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29660
diff
changeset
|
2711 update_screen(UPD_NOT_VALID); |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2712 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2713 |
2330 | 2714 void |
2715 ex_luafile(exarg_T *eap) | |
2716 { | |
2717 if (lua_init() == FAIL) | |
2718 return; | |
2719 if (!eap->skip) | |
2720 { | |
2721 luaV_setrange(L, eap->line1, eap->line2); | |
2722 if (luaL_loadfile(L, (char *) eap->arg) || lua_pcall(L, 0, 0, 0)) | |
2723 luaV_emsg(L); | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2724 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2725 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2726 |
3450 | 2727 #define luaV_freetype(typ,tname) \ |
2728 void \ | |
2729 lua_##tname##_free(typ *o) \ | |
2730 { \ | |
2731 if (!lua_isopen()) return; \ | |
2732 luaV_getfield(L, LUAVIM_FREE); \ | |
2733 lua_pushlightuserdata(L, (void *) o); \ | |
2734 lua_call(L, 1, 0); \ | |
2735 } | |
2736 | |
2737 luaV_freetype(buf_T, buffer) | |
2738 luaV_freetype(win_T, window) | |
2739 | |
2330 | 2740 void |
16028
8ad2cda3757d
patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents:
16009
diff
changeset
|
2741 do_luaeval(char_u *str, typval_T *arg, typval_T *rettv) |
2330 | 2742 { |
3450 | 2743 lua_init(); |
2744 luaV_getfield(L, LUAVIM_LUAEVAL); | |
2745 lua_pushstring(L, (char *) str); | |
2746 lua_pushlightuserdata(L, (void *) arg); | |
2747 lua_pushlightuserdata(L, (void *) rettv); | |
2748 lua_call(L, 3, 0); | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2749 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2750 |
6565 | 2751 int |
16028
8ad2cda3757d
patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents:
16009
diff
changeset
|
2752 set_ref_in_lua(int copyID) |
2330 | 2753 { |
6565 | 2754 int aborted = 0; |
2755 | |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2756 if (!lua_isopen()) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2757 return 0; |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2758 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2759 luaV_getfield(L, LUAVIM_SETREF); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2760 // call the function with 1 arg, getting 1 result back |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2761 lua_pushinteger(L, copyID); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2762 lua_call(L, 1, 1); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2763 // get the result |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2764 aborted = lua_tointeger(L, -1); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2765 // pop result off the stack |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2766 lua_pop(L, 1); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2767 |
6565 | 2768 return aborted; |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2769 } |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2770 |
20609
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2771 void |
32009
4545f58c8490
patch 9.0.1336: functions without arguments are not always declared properly
Bram Moolenaar <Bram@vim.org>
parents:
31976
diff
changeset
|
2772 update_package_paths_in_lua(void) |
20609
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2773 { |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2774 if (!lua_isopen()) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2775 return; |
20609
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2776 |
31702
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2777 lua_getglobal(L, "vim"); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2778 lua_getfield(L, -1, "_update_package_paths"); |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2779 |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2780 if (lua_pcall(L, 0, 0, 0)) |
27c9212d10aa
patch 9.0.1183: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
2781 luaV_emsg(L); |
20609
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2782 } |
054ba681412d
patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2783 |
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
|
2784 /* |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2785 * 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
|
2786 */ |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2787 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
|
2788 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
|
2789 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
|
2790 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
|
2791 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
|
2792 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
|
2793 { |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2794 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
|
2795 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
|
2796 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
|
2797 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
|
2798 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2799 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
|
2800 { |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2801 // 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
|
2802 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
|
2803 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
|
2804 } |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2805 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2806 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
|
2807 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
|
2808 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2809 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
|
2810 { |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2811 luaV_emsg(funcstate->L); |
31976
16025ef158bf
patch 9.0.1320: checking the type of a null object causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
31804
diff
changeset
|
2812 return (int)FCERR_OTHER; |
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
|
2813 } |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2814 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2815 luaV_checktypval(funcstate->L, -1, rettv, "get return value"); |
31976
16025ef158bf
patch 9.0.1320: checking the type of a null object causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
31804
diff
changeset
|
2816 return (int)FCERR_NONE; |
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
|
2817 } |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2818 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2819 /* |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2820 * 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
|
2821 */ |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2822 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
|
2823 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
|
2824 { |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2825 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
|
2826 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
|
2827 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
|
2828 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
|
2829 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
|
2830 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
|
2831 } |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20609
diff
changeset
|
2832 |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2833 #endif |