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