annotate src/if_lua.c @ 6895:63ac0cdf3b28 v7.4.767

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