Lines Matching refs:L
49 lua_State *L; member
67 #define luaV_getudata(L, v) \ argument
68 lua_pushlightuserdata((L), (void *) (v)); \
69 lua_rawget((L), lua_upvalueindex(1))
70 #define luaV_setudata(L, v) \ argument
71 lua_pushlightuserdata((L), (void *) (v)); \
72 lua_pushvalue((L), -2); \
73 lua_rawset((L), lua_upvalueindex(1))
74 #define luaV_getfield(L, s) \ argument
75 lua_pushlightuserdata((L), (void *)(s)); \
76 lua_rawget((L), LUA_REGISTRYINDEX)
77 #define luaV_checksandbox(L) \ argument
78 if (sandbox) luaL_error((L), "not allowed in sandbox")
79 #define luaV_msg(L) luaV_msgfunc((L), (msgfunc_T) msg) argument
80 #define luaV_emsg(L) luaV_msgfunc((L), (msgfunc_T) emsg) argument
81 #define luaV_checktypval(L, a, v, msg) \ argument
83 if (luaV_totypval(L, a, v) == FAIL) \
84 luaL_error(L, msg ": cannot convert value"); \
87 static luaV_List *luaV_pushlist(lua_State *L, list_T *lis);
88 static luaV_Dict *luaV_pushdict(lua_State *L, dict_T *dic);
89 static luaV_Blob *luaV_pushblob(lua_State *L, blob_T *blo);
90 static luaV_Funcref *luaV_pushfuncref(lua_State *L, char_u *name);
95 #define luaV_openlib(L, l, n) luaL_openlib(L, NULL, l, n) argument
220 void (*dll_luaL_register) (lua_State *L, const char *libname, const luaL_Reg *l);
222 void (*dll_luaL_openlib) (lua_State *L, const char *libname, const luaL_Reg *l, int nup);
223 int (*dll_luaL_typerror) (lua_State *L, int narg, const char *tname);
224 int (*dll_luaL_loadfile) (lua_State *L, const char *filename);
225 int (*dll_luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, const char *name);
228 void (*dll_luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
229 int (*dll_luaL_loadfilex) (lua_State *L, const char *filename, const char *mode);
230 int (*dll_luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, const char *name, const cha…
231 int (*dll_luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
234 int (*dll_luaL_typeerror) (lua_State *L, int narg, const char *tname);
236 void (*dll_luaL_checkany) (lua_State *L, int narg);
237 const char *(*dll_luaL_checklstring) (lua_State *L, int numArg, size_t *l);
238 lua_Integer (*dll_luaL_checkinteger) (lua_State *L, int numArg);
239 lua_Integer (*dll_luaL_optinteger) (lua_State *L, int nArg, lua_Integer def);
240 void (*dll_luaL_checktype) (lua_State *L, int narg, int t);
241 int (*dll_luaL_error) (lua_State *L, const char *fmt, ...);
243 void (*dll_luaL_buffinit) (lua_State *L, luaL_Buffer *B);
246 int (*dll_luaL_loadstring) (lua_State *L, const char *s);
247 int (*dll_luaL_ref) (lua_State *L, int idx);
249 void (*dll_luaL_unref) (lua_State *L, int idx, int n);
251 void (*dll_luaL_unref) (lua_State *L, int idx, lua_Integer n);
255 lua_Number (*dll_lua_tonumber) (lua_State *L, int idx);
256 lua_Integer (*dll_lua_tointeger) (lua_State *L, int idx);
257 void (*dll_lua_call) (lua_State *L, int nargs, int nresults);
258 int (*dll_lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
260 lua_Number (*dll_lua_tonumberx) (lua_State *L, int idx, int *isnum);
261 lua_Integer (*dll_lua_tointegerx) (lua_State *L, int idx, int *isnum);
262 void (*dll_lua_callk) (lua_State *L, int nargs, int nresults, int ctx,
264 int (*dll_lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
266 void (*dll_lua_getglobal) (lua_State *L, const char *var);
267 void (*dll_lua_setglobal) (lua_State *L, const char *var);
270 void (*dll_lua_replace) (lua_State *L, int idx);
271 void (*dll_lua_remove) (lua_State *L, int idx);
274 void (*dll_lua_rotate) (lua_State *L, int idx, int n);
275 void (*dll_lua_copy) (lua_State *L, int fromidx, int toidx);
277 const char *(*dll_lua_typename) (lua_State *L, int tp);
278 void (*dll_lua_close) (lua_State *L);
279 int (*dll_lua_gettop) (lua_State *L);
280 void (*dll_lua_settop) (lua_State *L, int idx);
281 void (*dll_lua_pushvalue) (lua_State *L, int idx);
282 int (*dll_lua_isnumber) (lua_State *L, int idx);
283 int (*dll_lua_isstring) (lua_State *L, int idx);
284 int (*dll_lua_type) (lua_State *L, int idx);
285 int (*dll_lua_rawequal) (lua_State *L, int idx1, int idx2);
286 int (*dll_lua_toboolean) (lua_State *L, int idx);
287 const char *(*dll_lua_tolstring) (lua_State *L, int idx, size_t *len);
288 void *(*dll_lua_touserdata) (lua_State *L, int idx);
289 void (*dll_lua_pushnil) (lua_State *L);
290 void (*dll_lua_pushnumber) (lua_State *L, lua_Number n);
291 void (*dll_lua_pushinteger) (lua_State *L, lua_Integer n);
292 void (*dll_lua_pushlstring) (lua_State *L, const char *s, size_t l);
293 void (*dll_lua_pushstring) (lua_State *L, const char *s);
294 const char *(*dll_lua_pushfstring) (lua_State *L, const char *fmt, ...);
295 void (*dll_lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
296 void (*dll_lua_pushboolean) (lua_State *L, int b);
297 void (*dll_lua_pushlightuserdata) (lua_State *L, void *p);
298 void (*dll_lua_getfield) (lua_State *L, int idx, const char *k);
300 void (*dll_lua_rawget) (lua_State *L, int idx);
301 void (*dll_lua_rawgeti) (lua_State *L, int idx, int n);
303 int (*dll_lua_rawget) (lua_State *L, int idx);
304 int (*dll_lua_rawgeti) (lua_State *L, int idx, lua_Integer n);
306 void (*dll_lua_createtable) (lua_State *L, int narr, int nrec);
307 void (*dll_lua_settable) (lua_State *L, int idx);
309 void *(*dll_lua_newuserdatauv) (lua_State *L, size_t sz, int nuvalue);
311 void *(*dll_lua_newuserdata) (lua_State *L, size_t sz);
313 int (*dll_lua_getmetatable) (lua_State *L, int objindex);
314 void (*dll_lua_setfield) (lua_State *L, int idx, const char *k);
315 void (*dll_lua_rawset) (lua_State *L, int idx);
317 void (*dll_lua_rawseti) (lua_State *L, int idx, int n);
319 void (*dll_lua_rawseti) (lua_State *L, int idx, lua_Integer n);
321 int (*dll_lua_setmetatable) (lua_State *L, int objindex);
322 int (*dll_lua_next) (lua_State *L, int idx);
324 int (*dll_luaopen_base) (lua_State *L);
325 int (*dll_luaopen_table) (lua_State *L);
326 int (*dll_luaopen_string) (lua_State *L);
327 int (*dll_luaopen_math) (lua_State *L);
328 int (*dll_luaopen_io) (lua_State *L);
329 int (*dll_luaopen_os) (lua_State *L);
330 int (*dll_luaopen_package) (lua_State *L);
331 int (*dll_luaopen_debug) (lua_State *L);
332 void (*dll_luaL_openlibs) (lua_State *L);
483 luaL_typeerror(lua_State *L, int narg, const char *tname) in luaL_typeerror() argument
485 const char *msg = lua_pushfstring(L, "%s expected, got %s", in luaL_typeerror()
486 tname, luaL_typename(L, narg)); in luaL_typeerror()
487 return luaL_argerror(L, narg, msg); in luaL_typeerror()
495 luaV_newmetatable(lua_State *L, const char *tname) in luaV_newmetatable() argument
497 lua_newtable(L); in luaV_newmetatable()
498 lua_pushlightuserdata(L, (void *) tname); in luaV_newmetatable()
499 lua_pushvalue(L, -2); in luaV_newmetatable()
500 lua_rawset(L, LUA_REGISTRYINDEX); in luaV_newmetatable()
504 luaV_toudata(lua_State *L, int ud, const char *tname) in luaV_toudata() argument
506 void *p = lua_touserdata(L, ud); in luaV_toudata()
510 if (lua_getmetatable(L, ud)) // does it have a metatable? in luaV_toudata()
512 luaV_getfield(L, tname); // get metatable in luaV_toudata()
513 if (lua_rawequal(L, -1, -2)) // MTs match? in luaV_toudata()
515 lua_pop(L, 2); // MTs in luaV_toudata()
524 luaV_checkcache(lua_State *L, void *p) in luaV_checkcache() argument
526 luaV_getudata(L, p); in luaV_checkcache()
527 if (lua_isnil(L, -1)) luaL_error(L, "invalid object"); in luaV_checkcache()
528 lua_pop(L, 1); in luaV_checkcache()
532 #define luaV_unbox(L,luatyp,ud) (*((luatyp *) lua_touserdata((L),(ud)))) argument
534 #define luaV_checkvalid(L,luatyp,ud) \ argument
535 luaV_checkcache((L), (void *) luaV_unbox((L),luatyp,(ud)))
538 luaV_checkudata(lua_State *L, int ud, const char *tname) in luaV_checkudata() argument
540 void *p = luaV_toudata(L, ud, tname); in luaV_checkudata()
541 if (p == NULL) luaL_typeerror(L, ud, tname); in luaV_checkudata()
546 luaV_pushtypval(lua_State *L, typval_T *tv) in luaV_pushtypval() argument
550 lua_pushnil(L); in luaV_pushtypval()
556 lua_pushstring(L, tv->vval.v_string == NULL in luaV_pushtypval()
560 lua_pushinteger(L, (int) tv->vval.v_number); in luaV_pushtypval()
564 lua_pushnumber(L, (lua_Number) tv->vval.v_float); in luaV_pushtypval()
568 luaV_pushlist(L, tv->vval.v_list); in luaV_pushtypval()
571 luaV_pushdict(L, tv->vval.v_dict); in luaV_pushtypval()
576 lua_pushinteger(L, (int) tv->vval.v_number); in luaV_pushtypval()
578 lua_pushnil(L); in luaV_pushtypval()
581 luaV_pushfuncref(L, tv->vval.v_string); in luaV_pushtypval()
585 luaV_pushfuncref(L, partial_name(tv->vval.v_partial)); in luaV_pushtypval()
589 luaV_pushblob(L, tv->vval.v_blob); in luaV_pushtypval()
592 lua_pushnil(L); in luaV_pushtypval()
601 luaV_totypval(lua_State *L, int pos, typval_T *tv) in luaV_totypval() argument
607 switch (lua_type(L, pos)) in luaV_totypval()
611 tv->vval.v_number = (varnumber_T) lua_toboolean(L, pos); in luaV_totypval()
619 tv->vval.v_string = vim_strsave((char_u *) lua_tostring(L, pos)); in luaV_totypval()
624 const lua_Number n = lua_tonumber(L, pos); in luaV_totypval()
640 tv->vval.v_number = (varnumber_T) lua_tointeger(L, pos); in luaV_totypval()
648 lua_pushvalue(L, pos); in luaV_totypval()
650 state->lua_funcref = luaL_ref(L, LUA_REGISTRYINDEX); in luaV_totypval()
651 state->L = L; in luaV_totypval()
663 lua_pushvalue(L, pos); in luaV_totypval()
664 lua_tableref = luaL_ref(L, LUA_REGISTRYINDEX); in luaV_totypval()
665 if (lua_getmetatable(L, pos)) { in luaV_totypval()
666 lua_getfield(L, -1, LUA___CALL); in luaV_totypval()
667 if (lua_isfunction(L, -1)) { in luaV_totypval()
669 int lua_funcref = luaL_ref(L, LUA_REGISTRYINDEX); in luaV_totypval()
673 state->L = L; in luaV_totypval()
689 void *p = lua_touserdata(L, pos); in luaV_totypval()
691 if (lua_getmetatable(L, pos)) // has metatable? in luaV_totypval()
694 luaV_getfield(L, LUAVIM_LIST); in luaV_totypval()
695 if (lua_rawequal(L, -1, -2)) in luaV_totypval()
700 lua_pop(L, 2); // MTs in luaV_totypval()
704 luaV_getfield(L, LUAVIM_DICT); in luaV_totypval()
705 if (lua_rawequal(L, -1, -3)) in luaV_totypval()
710 lua_pop(L, 3); // MTs in luaV_totypval()
714 luaV_getfield(L, LUAVIM_BLOB); in luaV_totypval()
715 if (lua_rawequal(L, -1, -4)) in luaV_totypval()
720 lua_pop(L, 4); // MTs in luaV_totypval()
724 luaV_getfield(L, LUAVIM_FUNCREF); in luaV_totypval()
725 if (lua_rawequal(L, -1, -5)) in luaV_totypval()
732 lua_pop(L, 5); // MTs in luaV_totypval()
735 lua_pop(L, 4); // MTs in luaV_totypval()
767 luaV_pushline(lua_State *L, buf_T *buf, linenr_T n) in luaV_pushline() argument
771 luaL_buffinit(L, &b); in luaV_pushline()
777 luaV_toline(lua_State *L, int pos) in luaV_toline() argument
780 const char *s = lua_tolstring(L, pos, &l); in luaV_toline()
783 luaL_buffinit(L, &b); in luaV_toline()
786 return (char_u *) lua_tostring(L, -1); in luaV_toline()
794 luaV_msgfunc(lua_State *L, msgfunc_T mf) in luaV_msgfunc() argument
798 const char *p, *s = lua_tolstring(L, -1, &l); in luaV_msgfunc()
799 luaL_buffinit(L, &b); in luaV_msgfunc()
803 p = s = lua_tolstring(L, -1, &l); in luaV_msgfunc()
813 lua_pop(L, 2); // original and modified strings in luaV_msgfunc()
818 luaV_new##tname(lua_State *L, typ *obj) \
820 luatyp *o = (luatyp *) lua_newuserdata(L, sizeof(luatyp)); \
822 luaV_setudata(L, obj); /* cache[obj] = udata */ \
823 luaV_getfield(L, luatname); \
824 lua_setmetatable(L, -2); \
830 luaV_push##tname(lua_State *L, typ *obj) \
834 lua_pushnil(L); \
836 luaV_getudata(L, obj); \
837 if (lua_isnil(L, -1)) /* not interned? */ \
839 lua_pop(L, 1); \
840 o = luaV_new##tname(L, obj); \
843 o = (luatyp *) lua_touserdata(L, -1); \
850 luaV_##tname##_tostring(lua_State *L) \
852 lua_pushfstring(L, "%s: %p", luatname, lua_touserdata(L, 1)); \
859 luaV_newlist(lua_State *L, list_T *lis) in luaV_newlist() argument
861 luaV_List *l = (luaV_List *) lua_newuserdata(L, sizeof(luaV_List)); in luaV_newlist()
864 luaV_setudata(L, lis); // cache[lis] = udata in luaV_newlist()
865 luaV_getfield(L, LUAVIM_LIST); in luaV_newlist()
866 lua_setmetatable(L, -2); in luaV_newlist()
874 luaV_list_len(lua_State *L) in luaV_pushtype()
876 list_T *l = luaV_unbox(L, luaV_List, 1); in luaV_pushtype()
877 lua_pushinteger(L, (int) list_len(l)); in luaV_pushtype()
882 luaV_list_iter(lua_State *L) in luaV_list_iter() argument
884 listitem_T *li = (listitem_T *) lua_touserdata(L, lua_upvalueindex(2)); in luaV_list_iter()
886 luaV_pushtypval(L, &li->li_tv); in luaV_list_iter()
887 lua_pushlightuserdata(L, (void *) li->li_next); in luaV_list_iter()
888 lua_replace(L, lua_upvalueindex(2)); in luaV_list_iter()
893 luaV_list_call(lua_State *L) in luaV_list_call() argument
895 list_T *l = luaV_unbox(L, luaV_List, 1); in luaV_list_call()
896 lua_pushvalue(L, lua_upvalueindex(1)); // pass cache table along in luaV_list_call()
897 lua_pushlightuserdata(L, (void *) l->lv_first); in luaV_list_call()
898 lua_pushcclosure(L, luaV_list_iter, 2); in luaV_list_call()
903 luaV_list_index(lua_State *L) in luaV_list_index() argument
905 list_T *l = luaV_unbox(L, luaV_List, 1); in luaV_list_index()
906 if (lua_isnumber(L, 2)) // list item? in luaV_list_index()
908 long n = (long) luaL_checkinteger(L, 2); in luaV_list_index()
916 lua_pushnil(L); in luaV_list_index()
918 luaV_pushtypval(L, &li->li_tv); in luaV_list_index()
920 else if (lua_isstring(L, 2)) // method? in luaV_list_index()
922 const char *s = lua_tostring(L, 2); in luaV_list_index()
926 lua_getmetatable(L, 1); in luaV_list_index()
927 lua_getfield(L, -1, s); in luaV_list_index()
930 lua_pushnil(L); in luaV_list_index()
933 lua_pushnil(L); in luaV_list_index()
938 luaV_list_newindex(lua_State *L) in luaV_list_newindex() argument
940 list_T *l = luaV_unbox(L, luaV_List, 1); in luaV_list_newindex()
941 long n = (long) luaL_checkinteger(L, 2); in luaV_list_newindex()
948 luaL_error(L, "list is locked"); in luaV_list_newindex()
952 if (!lua_isnil(L, 3)) in luaV_list_newindex()
955 luaV_checktypval(L, 3, &v, "inserting list item"); in luaV_list_newindex()
957 luaL_error(L, "failed to add item to list"); in luaV_list_newindex()
963 if (lua_isnil(L, 3)) // remove? in luaV_list_newindex()
971 luaV_checktypval(L, 3, &v, "setting list item"); in luaV_list_newindex()
980 luaV_list_add(lua_State *L) in luaV_list_add() argument
982 luaV_List *lis = luaV_checkudata(L, 1, LUAVIM_LIST); in luaV_list_add()
983 list_T *l = (list_T *) luaV_checkcache(L, (void *) *lis); in luaV_list_add()
986 luaL_error(L, "list is locked"); in luaV_list_add()
987 lua_settop(L, 2); in luaV_list_add()
988 luaV_checktypval(L, 2, &v, "adding list item"); in luaV_list_add()
990 luaL_error(L, "failed to add item to list"); in luaV_list_add()
992 lua_settop(L, 1); in luaV_list_add()
997 luaV_list_insert(lua_State *L) in luaV_list_insert() argument
999 luaV_List *lis = luaV_checkudata(L, 1, LUAVIM_LIST); in luaV_list_insert()
1000 list_T *l = (list_T *) luaV_checkcache(L, (void *) *lis); in luaV_list_insert()
1001 long pos = (long) luaL_optinteger(L, 3, 0); in luaV_list_insert()
1005 luaL_error(L, "list is locked"); in luaV_list_insert()
1010 luaL_error(L, "invalid position"); in luaV_list_insert()
1012 lua_settop(L, 2); in luaV_list_insert()
1013 luaV_checktypval(L, 2, &v, "inserting list item"); in luaV_list_insert()
1015 luaL_error(L, "failed to add item to list"); in luaV_list_insert()
1017 lua_settop(L, 1); in luaV_list_insert()
1036 luaV_newdict(lua_State *L, dict_T *dic) in luaV_newdict() argument
1038 luaV_Dict *d = (luaV_Dict *) lua_newuserdata(L, sizeof(luaV_Dict)); in luaV_newdict()
1041 luaV_setudata(L, dic); // cache[dic] = udata in luaV_newdict()
1042 luaV_getfield(L, LUAVIM_DICT); in luaV_newdict()
1043 lua_setmetatable(L, -2); in luaV_newdict()
1051 luaV_dict_len(lua_State *L) in luaV_pushtype()
1053 dict_T *d = luaV_unbox(L, luaV_Dict, 1); in luaV_pushtype()
1054 lua_pushinteger(L, (int) dict_len(d)); in luaV_pushtype()
1059 luaV_dict_iter(lua_State *L UNUSED) in luaV_dict_iter()
1062 hashitem_T *hi = (hashitem_T *) lua_touserdata(L, lua_upvalueindex(2)); in luaV_dict_iter()
1063 int n = lua_tointeger(L, lua_upvalueindex(3)); in luaV_dict_iter()
1068 lua_pushstring(L, (char *) hi->hi_key); in luaV_dict_iter()
1069 luaV_pushtypval(L, &di->di_tv); in luaV_dict_iter()
1070 lua_pushlightuserdata(L, (void *) (hi + 1)); in luaV_dict_iter()
1071 lua_replace(L, lua_upvalueindex(2)); in luaV_dict_iter()
1072 lua_pushinteger(L, n - 1); in luaV_dict_iter()
1073 lua_replace(L, lua_upvalueindex(3)); in luaV_dict_iter()
1081 luaV_dict_call(lua_State *L) in luaV_dict_call() argument
1083 dict_T *d = luaV_unbox(L, luaV_Dict, 1); in luaV_dict_call()
1085 lua_pushvalue(L, lua_upvalueindex(1)); // pass cache table along in luaV_dict_call()
1086 lua_pushlightuserdata(L, (void *) ht->ht_array); in luaV_dict_call()
1087 lua_pushinteger(L, ht->ht_used); // # remaining items in luaV_dict_call()
1088 lua_pushcclosure(L, luaV_dict_iter, 3); in luaV_dict_call()
1093 luaV_dict_index(lua_State *L) in luaV_dict_index() argument
1095 dict_T *d = luaV_unbox(L, luaV_Dict, 1); in luaV_dict_index()
1096 char_u *key = (char_u *) luaL_checkstring(L, 2); in luaV_dict_index()
1100 lua_pushnil(L); in luaV_dict_index()
1103 luaV_pushtypval(L, &di->di_tv); in luaV_dict_index()
1106 luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, -1); in luaV_dict_index()
1115 luaV_dict_newindex(lua_State *L) in luaV_dict_newindex() argument
1117 dict_T *d = luaV_unbox(L, luaV_Dict, 1); in luaV_dict_newindex()
1118 char_u *key = (char_u *) luaL_checkstring(L, 2); in luaV_dict_newindex()
1123 luaL_error(L, "dict is locked"); in luaV_dict_newindex()
1127 luaL_error(L, "empty key"); in luaV_dict_newindex()
1128 if (!lua_isnil(L, 3)) // read value? in luaV_dict_newindex()
1130 luaV_checktypval(L, 3, &tv, "setting dict item"); in luaV_dict_newindex()
1134 luaL_error(L, "cannot assign funcref to builtin scope"); in luaV_dict_newindex()
1140 if (lua_isnil(L, 3)) in luaV_dict_newindex()
1157 if (lua_isnil(L, 3)) // remove? in luaV_dict_newindex()
1181 luaV_newblob(lua_State *L, blob_T *blo) in luaV_newblob() argument
1183 luaV_Blob *b = (luaV_Blob *) lua_newuserdata(L, sizeof(luaV_Blob)); in luaV_newblob()
1186 luaV_setudata(L, blo); // cache[blo] = udata in luaV_newblob()
1187 luaV_getfield(L, LUAVIM_BLOB); in luaV_newblob()
1188 lua_setmetatable(L, -2); in luaV_newblob()
1196 luaV_blob_gc(lua_State *L) in luaV_pushtype()
1198 blob_T *b = luaV_unbox(L, luaV_Blob, 1); in luaV_pushtype()
1204 luaV_blob_len(lua_State *L) in luaV_blob_len() argument
1206 blob_T *b = luaV_unbox(L, luaV_Blob, 1); in luaV_blob_len()
1207 lua_pushinteger(L, (int) blob_len(b)); in luaV_blob_len()
1212 luaV_blob_index(lua_State *L) in luaV_blob_index() argument
1214 blob_T *b = luaV_unbox(L, luaV_Blob, 1); in luaV_blob_index()
1215 if (lua_isnumber(L, 2)) in luaV_blob_index()
1217 int idx = luaL_checkinteger(L, 2); in luaV_blob_index()
1219 lua_pushnumber(L, (lua_Number) blob_get(b, idx)); in luaV_blob_index()
1221 lua_pushnil(L); in luaV_blob_index()
1223 else if (lua_isstring(L, 2)) in luaV_blob_index()
1225 const char *s = lua_tostring(L, 2); in luaV_blob_index()
1228 lua_getmetatable(L, 1); in luaV_blob_index()
1229 lua_getfield(L, -1, s); in luaV_blob_index()
1232 lua_pushnil(L); in luaV_blob_index()
1235 lua_pushnil(L); in luaV_blob_index()
1240 luaV_blob_newindex(lua_State *L) in luaV_blob_newindex() argument
1242 blob_T *b = luaV_unbox(L, luaV_Blob, 1); in luaV_blob_newindex()
1244 luaL_error(L, "blob is locked"); in luaV_blob_newindex()
1245 if (lua_isnumber(L, 2)) in luaV_blob_newindex()
1248 int idx = luaL_checkinteger(L, 2); in luaV_blob_newindex()
1249 int val = luaL_checkinteger(L, 3); in luaV_blob_newindex()
1257 luaL_error(L, "index out of range"); in luaV_blob_newindex()
1263 luaV_blob_add(lua_State *L) in luaV_blob_add() argument
1265 luaV_Blob *blo = luaV_checkudata(L, 1, LUAVIM_BLOB); in luaV_blob_add()
1266 blob_T *b = (blob_T *) luaV_checkcache(L, (void *) *blo); in luaV_blob_add()
1268 luaL_error(L, "blob is locked"); in luaV_blob_add()
1269 lua_settop(L, 2); in luaV_blob_add()
1270 if (!lua_isstring(L, 2)) in luaV_blob_add()
1271 luaL_error(L, "string expected, got %s", luaL_typename(L, 2)); in luaV_blob_add()
1275 const char *s = lua_tolstring(L, 2, &l); in luaV_blob_add()
1281 lua_settop(L, 1); in luaV_blob_add()
1299 luaV_newfuncref(lua_State *L, char_u *name) in luaV_newfuncref() argument
1301 luaV_Funcref *f = (luaV_Funcref *)lua_newuserdata(L, sizeof(luaV_Funcref)); in luaV_newfuncref()
1309 luaV_getfield(L, LUAVIM_FUNCREF); in luaV_newfuncref()
1310 lua_setmetatable(L, -2); in luaV_newfuncref()
1315 luaV_pushfuncref(lua_State *L, char_u *name) in luaV_pushfuncref() argument
1317 return luaV_newfuncref(L, name); in luaV_pushfuncref()
1324 luaV_funcref_gc(lua_State *L) in luaV_type_tostring()
1326 luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, 1); in luaV_type_tostring()
1337 luaV_funcref_len(lua_State *L) in luaV_funcref_len() argument
1339 luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, 1); in luaV_funcref_len()
1341 lua_pushstring(L, (const char *) f->name); in luaV_funcref_len()
1346 luaV_funcref_call(lua_State *L) in luaV_funcref_call() argument
1348 luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, 1); in luaV_funcref_call()
1349 int i, n = lua_gettop(L) - 1; // #args in luaV_funcref_call()
1363 luaV_checktypval(L, i + 2, &v, "calling funcref"); in luaV_funcref_call()
1369 luaV_pushtypval(L, &rettv); in luaV_funcref_call()
1374 luaL_error(L, "cannot call funcref"); in luaV_funcref_call()
1394 luaV_buffer_len(lua_State *L) in luaV_newtype()
1396 buf_T *b = (buf_T *) luaV_checkvalid(L, luaV_Buffer, 1); in luaV_newtype()
1397 lua_pushinteger(L, b->b_ml.ml_line_count); in luaV_newtype()
1402 luaV_buffer_call(lua_State *L) in luaV_buffer_call() argument
1404 buf_T *b = (buf_T *) luaV_checkvalid(L, luaV_Buffer, 1); in luaV_buffer_call()
1405 lua_settop(L, 1); in luaV_buffer_call()
1411 luaV_buffer_index(lua_State *L) in luaV_buffer_index() argument
1413 buf_T *b = (buf_T *) luaV_checkvalid(L, luaV_Buffer, 1); in luaV_buffer_index()
1414 linenr_T n = (linenr_T) lua_tointeger(L, 2); in luaV_buffer_index()
1416 luaV_pushline(L, b, n); in luaV_buffer_index()
1417 else if (lua_isstring(L, 2)) in luaV_buffer_index()
1419 const char *s = lua_tostring(L, 2); in luaV_buffer_index()
1421 lua_pushstring(L, (b->b_sfname == NULL) in luaV_buffer_index()
1424 lua_pushstring(L, (b->b_ffname == NULL) in luaV_buffer_index()
1427 lua_pushinteger(L, b->b_fnum); in luaV_buffer_index()
1434 lua_getmetatable(L, 1); in luaV_buffer_index()
1435 lua_getfield(L, -1, s); in luaV_buffer_index()
1438 lua_pushnil(L); in luaV_buffer_index()
1441 lua_pushnil(L); in luaV_buffer_index()
1446 luaV_buffer_newindex(lua_State *L) in luaV_buffer_newindex() argument
1448 buf_T *b = (buf_T *) luaV_checkvalid(L, luaV_Buffer, 1); in luaV_buffer_newindex()
1449 linenr_T n = (linenr_T) luaL_checkinteger(L, 2); in luaV_buffer_newindex()
1451 luaV_checksandbox(L); in luaV_buffer_newindex()
1454 luaL_error(L, "invalid line number"); in luaV_buffer_newindex()
1455 if (lua_isnil(L, 3)) // delete line in luaV_buffer_newindex()
1462 luaL_error(L, "cannot save undo information"); in luaV_buffer_newindex()
1467 luaL_error(L, "cannot delete line"); in luaV_buffer_newindex()
1490 else if (lua_isstring(L, 3)) // update line in luaV_buffer_newindex()
1497 luaL_error(L, "cannot save undo information"); in luaV_buffer_newindex()
1499 else if (ml_replace(n, luaV_toline(L, 3), TRUE) == FAIL) in luaV_buffer_newindex()
1502 luaL_error(L, "cannot replace line"); in luaV_buffer_newindex()
1510 luaL_error(L, "wrong argument to change line"); in luaV_buffer_newindex()
1515 luaV_buffer_insert(lua_State *L) in luaV_buffer_insert() argument
1517 luaV_Buffer *lb = luaV_checkudata(L, 1, LUAVIM_BUFFER); in luaV_buffer_insert()
1518 buf_T *b = (buf_T *) luaV_checkcache(L, (void *) *lb); in luaV_buffer_insert()
1520 linenr_T n = (linenr_T) luaL_optinteger(L, 3, last); in luaV_buffer_insert()
1522 luaL_checktype(L, 2, LUA_TSTRING); in luaV_buffer_insert()
1524 luaV_checksandbox(L); in luaV_buffer_insert()
1535 luaL_error(L, "cannot save undo information"); in luaV_buffer_insert()
1537 else if (ml_append(n, luaV_toline(L, 2), 0, FALSE) == FAIL) in luaV_buffer_insert()
1540 luaL_error(L, "cannot insert line"); in luaV_buffer_insert()
1550 luaV_buffer_next(lua_State *L) in luaV_buffer_next() argument
1552 luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER); in luaV_buffer_next()
1553 buf_T *buf = (buf_T *) luaV_checkcache(L, (void *) *b); in luaV_buffer_next()
1554 luaV_pushbuffer(L, buf->b_next); in luaV_buffer_next()
1559 luaV_buffer_previous(lua_State *L) in luaV_buffer_previous() argument
1561 luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER); in luaV_buffer_previous()
1562 buf_T *buf = (buf_T *) luaV_checkcache(L, (void *) *b); in luaV_buffer_previous()
1563 luaV_pushbuffer(L, buf->b_prev); in luaV_buffer_previous()
1568 luaV_buffer_isvalid(lua_State *L) in luaV_buffer_isvalid() argument
1570 luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER); in luaV_buffer_isvalid()
1571 luaV_getudata(L, *b); in luaV_buffer_isvalid()
1572 lua_pushboolean(L, !lua_isnil(L, -1)); in luaV_buffer_isvalid()
1597 luaV_window_call(lua_State *L) in luaV_newtype()
1599 win_T *w = (win_T *) luaV_checkvalid(L, luaV_Window, 1); in luaV_newtype()
1600 lua_settop(L, 1); in luaV_newtype()
1606 luaV_window_index(lua_State *L) in luaV_window_index() argument
1608 win_T *w = (win_T *) luaV_checkvalid(L, luaV_Window, 1); in luaV_window_index()
1609 const char *s = luaL_checkstring(L, 2); in luaV_window_index()
1611 luaV_pushbuffer(L, w->w_buffer); in luaV_window_index()
1613 lua_pushinteger(L, w->w_cursor.lnum); in luaV_window_index()
1615 lua_pushinteger(L, w->w_cursor.col + 1); in luaV_window_index()
1617 lua_pushinteger(L, w->w_width); in luaV_window_index()
1619 lua_pushinteger(L, w->w_height); in luaV_window_index()
1625 lua_getmetatable(L, 1); in luaV_window_index()
1626 lua_getfield(L, -1, s); in luaV_window_index()
1629 lua_pushnil(L); in luaV_window_index()
1634 luaV_window_newindex(lua_State *L) in luaV_window_newindex() argument
1636 win_T *w = (win_T *) luaV_checkvalid(L, luaV_Window, 1); in luaV_window_newindex()
1637 const char *s = luaL_checkstring(L, 2); in luaV_window_newindex()
1638 int v = luaL_checkinteger(L, 3); in luaV_window_newindex()
1642 luaV_checksandbox(L); in luaV_window_newindex()
1645 luaL_error(L, "line out of range"); in luaV_window_newindex()
1652 luaV_checksandbox(L); in luaV_window_newindex()
1679 luaL_error(L, "invalid window property: `%s'", s); in luaV_window_newindex()
1684 luaV_window_next(lua_State *L) in luaV_window_next() argument
1686 luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW); in luaV_window_next()
1687 win_T *win = (win_T *) luaV_checkcache(L, (void *) *w); in luaV_window_next()
1688 luaV_pushwindow(L, win->w_next); in luaV_window_next()
1693 luaV_window_previous(lua_State *L) in luaV_window_previous() argument
1695 luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW); in luaV_window_previous()
1696 win_T *win = (win_T *) luaV_checkcache(L, (void *) *w); in luaV_window_previous()
1697 luaV_pushwindow(L, win->w_prev); in luaV_window_previous()
1702 luaV_window_isvalid(lua_State *L) in luaV_window_isvalid() argument
1704 luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW); in luaV_window_isvalid()
1705 luaV_getudata(L, *w); in luaV_window_isvalid()
1706 lua_pushboolean(L, !lua_isnil(L, -1)); in luaV_window_isvalid()
1725 luaV_print(lua_State *L) in luaV_print() argument
1727 int i, n = lua_gettop(L); // nargs in luaV_print()
1733 lua_getglobal(L, "tostring"); in luaV_print()
1736 lua_pushvalue(L, -1); // tostring in luaV_print()
1737 lua_pushvalue(L, i); // arg in luaV_print()
1738 lua_call(L, 1, 1); in luaV_print()
1739 s = lua_tolstring(L, -1, &l); in luaV_print()
1741 return luaL_error(L, "cannot convert to string"); in luaV_print()
1745 lua_pop(L, 1); in luaV_print()
1751 lua_pushlstring(L, msg_ga.ga_data, msg_ga.ga_len); in luaV_print()
1753 luaV_msg(L); in luaV_print()
1760 luaV_debug(lua_State *L) in luaV_debug() argument
1762 lua_settop(L, 0); in luaV_debug()
1763 lua_getglobal(L, "vim"); in luaV_debug()
1764 lua_getfield(L, -1, "eval"); in luaV_debug()
1765 lua_remove(L, -2); // vim.eval at position 1 in luaV_debug()
1770 lua_pushvalue(L, 1); // vim.eval in luaV_debug()
1771 lua_pushliteral(L, "input('lua_debug> ')"); in luaV_debug()
1772 lua_call(L, 1, 1); // return string in luaV_debug()
1773 input = lua_tolstring(L, -1, &l); in luaV_debug()
1777 if (luaL_loadbuffer(L, input, l, "=(debug command)") in luaV_debug()
1778 || lua_pcall(L, 0, 0, 0)) in luaV_debug()
1779 luaV_emsg(L); in luaV_debug()
1780 lua_settop(L, 1); // remove eventual returns, but keep vim.eval in luaV_debug()
1785 luaV_get_var_scope(lua_State *L) in luaV_get_var_scope() argument
1787 const char *scope = luaL_checkstring(L, 1); in luaV_get_var_scope()
1802 luaL_error(L, "invalid scope %s", scope); in luaV_get_var_scope()
1810 luaV_setvar(lua_State *L) in luaV_setvar() argument
1819 name = (char *)luaL_checklstring(L, 3, &len); in luaV_setvar()
1820 del = (lua_gettop(L) < 4) || lua_isnil(L, 4); in luaV_setvar()
1822 dict = luaV_get_var_scope(L); in luaV_setvar()
1836 return luaL_error(L, error); in luaV_setvar()
1839 return luaL_error(L, "Dictionary is locked"); in luaV_setvar()
1857 lua_pushvalue(L, 4); in luaV_setvar()
1858 if (luaV_totypval(L, -1, &tv) == FAIL) in luaV_setvar()
1859 return luaL_error(L, "Couldn't convert lua value"); in luaV_setvar()
1876 return luaL_error(L, "Couldn't add to dictionary"); in luaV_setvar()
1895 luaV_getvar(lua_State *L) in luaV_getvar() argument
1897 dict_T *dict = luaV_get_var_scope(L); in luaV_getvar()
1899 const char *name = luaL_checklstring(L, 3, &len); in luaV_getvar()
1905 luaV_pushtypval(L, &di->di_tv); in luaV_getvar()
1910 luaV_command(lua_State *L) in luaV_command() argument
1912 char_u *s = vim_strsave((char_u *)luaL_checkstring(L, 1)); in luaV_command()
1921 luaV_eval(lua_State *L) in luaV_eval() argument
1923 typval_T *tv = eval_expr((char_u *) luaL_checkstring(L, 1), NULL); in luaV_eval()
1925 if (tv == NULL) luaL_error(L, "invalid expression"); in luaV_eval()
1926 luaV_pushtypval(L, tv); in luaV_eval()
1932 luaV_beep(lua_State *L UNUSED) in luaV_beep()
1939 luaV_line(lua_State *L) in luaV_line() argument
1941 luaV_pushline(L, curbuf, curwin->w_cursor.lnum); in luaV_line()
1946 luaV_list(lua_State *L) in luaV_list() argument
1949 int initarg = !lua_isnoneornil(L, 1); in luaV_list()
1951 if (initarg && lua_type(L, 1) != LUA_TTABLE) in luaV_list()
1952 luaL_error(L, "table expected, got %s", luaL_typename(L, 1)); in luaV_list()
1955 lua_pushnil(L); in luaV_list()
1958 luaV_newlist(L, l); in luaV_list()
1965 lua_rawgeti(L, 1, ++i); in luaV_list()
1966 notnil = !lua_isnil(L, -1); in luaV_list()
1969 luaV_checktypval(L, -1, &v, "vim.list"); in luaV_list()
1973 lua_pop(L, 1); // value in luaV_list()
1981 luaV_dict(lua_State *L) in luaV_dict() argument
1984 int initarg = !lua_isnoneornil(L, 1); in luaV_dict()
1986 if (initarg && lua_type(L, 1) != LUA_TTABLE) in luaV_dict()
1987 luaL_error(L, "table expected, got %s", luaL_typename(L, 1)); in luaV_dict()
1990 lua_pushnil(L); in luaV_dict()
1993 luaV_newdict(L, d); in luaV_dict()
1996 lua_pushnil(L); in luaV_dict()
1997 while (lua_next(L, 1)) in luaV_dict()
2003 lua_pushvalue(L, -2); // dup key in case it's a number in luaV_dict()
2004 key = (char_u *) lua_tostring(L, -1); in luaV_dict()
2007 lua_pushnil(L); in luaV_dict()
2011 luaL_error(L, "table has empty key"); in luaV_dict()
2012 luaV_checktypval(L, -2, &v, "vim.dict"); // value in luaV_dict()
2017 lua_pushnil(L); in luaV_dict()
2021 lua_pop(L, 2); // key copy and value in luaV_dict()
2029 luaV_blob(lua_State *L) in luaV_blob() argument
2032 int initarg = !lua_isnoneornil(L, 1); in luaV_blob()
2034 if (initarg && !lua_isstring(L, 1)) in luaV_blob()
2035 luaL_error(L, "string expected, got %s", luaL_typename(L, 1)); in luaV_blob()
2038 lua_pushnil(L); in luaV_blob()
2041 luaV_newblob(L, b); in luaV_blob()
2045 const char *s = lua_tolstring(L, 1, &l); in luaV_blob()
2056 luaV_funcref(lua_State *L) in luaV_funcref() argument
2058 const char *name = luaL_checkstring(L, 1); in luaV_funcref()
2061 luaL_error(L, "invalid function name: %s", name); in luaV_funcref()
2062 luaV_newfuncref(L, (char_u *) name); in luaV_funcref()
2067 luaV_buffer(lua_State *L) in luaV_buffer() argument
2070 if (lua_isstring(L, 1)) // get by number or name? in luaV_buffer()
2072 if (lua_isnumber(L, 1)) // by number? in luaV_buffer()
2074 int n = lua_tointeger(L, 1); in luaV_buffer()
2081 const char *s = lua_tolstring(L, 1, &l); in luaV_buffer()
2095 buf = (lua_toboolean(L, 1)) ? firstbuf : curbuf; // first buffer? in luaV_buffer()
2096 luaV_pushbuffer(L, buf); in luaV_buffer()
2101 luaV_window(lua_State *L) in luaV_window() argument
2104 if (lua_isnumber(L, 1)) // get by number? in luaV_window()
2106 int n = lua_tointeger(L, 1); in luaV_window()
2111 win = (lua_toboolean(L, 1)) ? firstwin : curwin; // first window? in luaV_window()
2112 luaV_pushwindow(L, win); in luaV_window()
2117 luaV_open(lua_State *L) in luaV_open() argument
2121 luaV_checksandbox(L); in luaV_open()
2123 if (lua_isstring(L, 1)) s = (char_u *) lua_tostring(L, 1); in luaV_open()
2124 luaV_pushbuffer(L, buflist_new(s, NULL, 1L, BLN_LISTED)); in luaV_open()
2129 luaV_type(lua_State *L) in luaV_type() argument
2131 luaL_checkany(L, 1); in luaV_type()
2132 if (lua_type(L, 1) == LUA_TUSERDATA) // check vim udata? in luaV_type()
2134 lua_settop(L, 1); in luaV_type()
2135 if (lua_getmetatable(L, 1)) in luaV_type()
2137 luaV_getfield(L, LUAVIM_LIST); in luaV_type()
2138 if (lua_rawequal(L, -1, 2)) in luaV_type()
2140 lua_pushstring(L, "list"); in luaV_type()
2143 luaV_getfield(L, LUAVIM_DICT); in luaV_type()
2144 if (lua_rawequal(L, -1, 2)) in luaV_type()
2146 lua_pushstring(L, "dict"); in luaV_type()
2149 luaV_getfield(L, LUAVIM_BLOB); in luaV_type()
2150 if (lua_rawequal(L, -1, 2)) in luaV_type()
2152 lua_pushstring(L, "blob"); in luaV_type()
2155 luaV_getfield(L, LUAVIM_FUNCREF); in luaV_type()
2156 if (lua_rawequal(L, -1, 2)) in luaV_type()
2158 lua_pushstring(L, "funcref"); in luaV_type()
2161 luaV_getfield(L, LUAVIM_BUFFER); in luaV_type()
2162 if (lua_rawequal(L, -1, 2)) in luaV_type()
2164 lua_pushstring(L, "buffer"); in luaV_type()
2167 luaV_getfield(L, LUAVIM_WINDOW); in luaV_type()
2168 if (lua_rawequal(L, -1, 2)) in luaV_type()
2170 lua_pushstring(L, "window"); in luaV_type()
2175 lua_pushstring(L, luaL_typename(L, 1)); // fallback in luaV_type()
2180 luaV_call(lua_State *L) in luaV_call() argument
2182 int argc = lua_gettop(L) - 1; in luaV_call()
2191 return luaL_error(L, "Function called with too many arguments"); in luaV_call()
2193 funcname = (char_u *)luaL_checklstring(L, 1, &funcname_len); in luaV_call()
2197 if (luaV_totypval(L, i + 2, &argv[i]) == FAIL) in luaV_call()
2212 luaV_pushtypval(L, &rettv); in luaV_call()
2222 return luaL_error(L, error); in luaV_call()
2229 luaV_version(lua_State *L) in luaV_version() argument
2231 lua_newtable(L); in luaV_version()
2232 lua_pushstring(L, "major"); in luaV_version()
2233 lua_pushinteger(L, VIM_VERSION_MAJOR); in luaV_version()
2234 lua_settable(L, -3); in luaV_version()
2235 lua_pushstring(L, "minor"); in luaV_version()
2236 lua_pushinteger(L, VIM_VERSION_MINOR); in luaV_version()
2237 lua_settable(L, -3); in luaV_version()
2238 lua_pushstring(L, "patch"); in luaV_version()
2239 lua_pushinteger(L, highest_patch()); in luaV_version()
2240 lua_settable(L, -3); in luaV_version()
2269 luaV_free(lua_State *L) in luaV_free() argument
2271 lua_pushnil(L); in luaV_free()
2272 luaV_setudata(L, lua_touserdata(L, 1)); in luaV_free()
2277 luaV_luaeval(lua_State *L) in luaV_luaeval() argument
2281 const char *str = lua_tolstring(L, 1, &l); in luaV_luaeval()
2282 typval_T *arg = (typval_T *) lua_touserdata(L, 2); in luaV_luaeval()
2283 typval_T *rettv = (typval_T *) lua_touserdata(L, 3); in luaV_luaeval()
2284 luaL_buffinit(L, &b); in luaV_luaeval()
2288 str = lua_tolstring(L, -1, &l); in luaV_luaeval()
2289 if (luaL_loadbuffer(L, str, l, LUAVIM_EVALNAME)) // compile error? in luaV_luaeval()
2291 luaV_emsg(L); in luaV_luaeval()
2294 luaV_pushtypval(L, arg); in luaV_luaeval()
2295 if (lua_pcall(L, 1, 1, 0)) // running error? in luaV_luaeval()
2297 luaV_emsg(L); in luaV_luaeval()
2300 if (luaV_totypval(L, -1, rettv) == FAIL) in luaV_luaeval()
2306 luaV_setref(lua_State *L) in luaV_setref() argument
2308 int copyID = lua_tointeger(L, 1); in luaV_setref()
2311 luaV_getfield(L, LUAVIM_LIST); in luaV_setref()
2312 luaV_getfield(L, LUAVIM_DICT); in luaV_setref()
2313 luaV_getfield(L, LUAVIM_FUNCREF); in luaV_setref()
2314 lua_pushnil(L); in luaV_setref()
2316 while (!abort && lua_next(L, lua_upvalueindex(1)) != 0) in luaV_setref()
2318 lua_getmetatable(L, -1); in luaV_setref()
2319 if (lua_rawequal(L, -1, 2)) // list? in luaV_setref()
2321 list_T *l = (list_T *)lua_touserdata(L, 5); // key in luaV_setref()
2325 else if (lua_rawequal(L, -1, 3)) // dict? in luaV_setref()
2327 dict_T *d = (dict_T *)lua_touserdata(L, 5); // key in luaV_setref()
2331 else if (lua_rawequal(L, -1, 4)) // funcref? in luaV_setref()
2333 luaV_Funcref *f = (luaV_Funcref *)lua_touserdata(L, 5); // key in luaV_setref()
2337 lua_pop(L, 2); // metatable and value in luaV_setref()
2339 lua_pushinteger(L, abort); in luaV_setref()
2344 luaV_pushversion(lua_State *L) in luaV_pushversion() argument
2353 lua_pushstring(L, s); in luaV_pushversion()
2453 luaopen_vim(lua_State *L) in luaopen_vim() argument
2456 lua_newtable(L); in luaopen_vim()
2457 lua_newtable(L); in luaopen_vim()
2458 lua_pushstring(L, "v"); in luaopen_vim()
2459 lua_setfield(L, -2, "__mode"); in luaopen_vim()
2460 lua_setmetatable(L, -2); // cache is weak-valued in luaopen_vim()
2462 lua_pushcfunction(L, luaV_print); in luaopen_vim()
2463 lua_setglobal(L, "print"); in luaopen_vim()
2465 lua_getglobal(L, "debug"); in luaopen_vim()
2466 lua_pushcfunction(L, luaV_debug); in luaopen_vim()
2467 lua_setfield(L, -2, "debug"); in luaopen_vim()
2468 lua_pop(L, 1); in luaopen_vim()
2470 lua_pushlightuserdata(L, (void *) LUAVIM_FREE); in luaopen_vim()
2471 lua_pushvalue(L, 1); // cache table in luaopen_vim()
2472 lua_pushcclosure(L, luaV_free, 1); in luaopen_vim()
2473 lua_rawset(L, LUA_REGISTRYINDEX); in luaopen_vim()
2475 lua_pushlightuserdata(L, (void *) LUAVIM_LUAEVAL); in luaopen_vim()
2476 lua_pushvalue(L, 1); // cache table in luaopen_vim()
2477 lua_pushcclosure(L, luaV_luaeval, 1); in luaopen_vim()
2478 lua_rawset(L, LUA_REGISTRYINDEX); in luaopen_vim()
2480 lua_pushlightuserdata(L, (void *) LUAVIM_SETREF); in luaopen_vim()
2481 lua_pushvalue(L, 1); // cache table in luaopen_vim()
2482 lua_pushcclosure(L, luaV_setref, 1); in luaopen_vim()
2483 lua_rawset(L, LUA_REGISTRYINDEX); in luaopen_vim()
2485 luaV_newmetatable(L, LUAVIM_LIST); in luaopen_vim()
2486 lua_pushvalue(L, 1); in luaopen_vim()
2487 luaV_openlib(L, luaV_List_mt, 1); in luaopen_vim()
2488 luaV_newmetatable(L, LUAVIM_DICT); in luaopen_vim()
2489 lua_pushvalue(L, 1); in luaopen_vim()
2490 luaV_openlib(L, luaV_Dict_mt, 1); in luaopen_vim()
2491 luaV_newmetatable(L, LUAVIM_BLOB); in luaopen_vim()
2492 lua_pushvalue(L, 1); in luaopen_vim()
2493 luaV_openlib(L, luaV_Blob_mt, 1); in luaopen_vim()
2494 luaV_newmetatable(L, LUAVIM_FUNCREF); in luaopen_vim()
2495 lua_pushvalue(L, 1); in luaopen_vim()
2496 luaV_openlib(L, luaV_Funcref_mt, 1); in luaopen_vim()
2497 luaV_newmetatable(L, LUAVIM_BUFFER); in luaopen_vim()
2498 lua_pushvalue(L, 1); // cache table in luaopen_vim()
2499 luaV_openlib(L, luaV_Buffer_mt, 1); in luaopen_vim()
2500 luaV_newmetatable(L, LUAVIM_WINDOW); in luaopen_vim()
2501 lua_pushvalue(L, 1); // cache table in luaopen_vim()
2502 luaV_openlib(L, luaV_Window_mt, 1); in luaopen_vim()
2503 lua_newtable(L); // vim table in luaopen_vim()
2504 lua_pushvalue(L, 1); // cache table in luaopen_vim()
2505 luaV_openlib(L, luaV_module, 1); in luaopen_vim()
2506 luaV_pushversion(L); in luaopen_vim()
2507 lua_setfield(L, -2, "lua_version"); in luaopen_vim()
2508 lua_setglobal(L, LUAVIM_NAME); in luaopen_vim()
2510 (void)luaL_dostring(L, LUA_VIM_FN_CODE); in luaopen_vim()
2511 (void)luaL_dostring(L, LUA_VIM_UPDATE_PACKAGE_PATHS); in luaopen_vim()
2512 (void)luaL_dostring(L, LUA_VIM_SETUP_VARIABLE_DICTS); in luaopen_vim()
2514 lua_getglobal(L, "vim"); in luaopen_vim()
2515 lua_getfield(L, -1, "_update_package_paths"); in luaopen_vim()
2517 if (lua_pcall(L, 0, 0, 0)) in luaopen_vim()
2518 luaV_emsg(L); in luaopen_vim()
2526 lua_State *L = luaL_newstate(); in luaV_newstate() local
2527 luaL_openlibs(L); // core libs in luaV_newstate()
2528 lua_pushcfunction(L, luaopen_vim); // vim in luaV_newstate()
2529 lua_call(L, 0, 0); in luaV_newstate()
2530 return L; in luaV_newstate()
2534 luaV_setrange(lua_State *L, int line1, int line2) in luaV_setrange() argument
2536 lua_getglobal(L, LUAVIM_NAME); in luaV_setrange()
2537 lua_pushinteger(L, line1); in luaV_setrange()
2538 lua_setfield(L, -2, "firstline"); in luaV_setrange()
2539 lua_pushinteger(L, line2); in luaV_setrange()
2540 lua_setfield(L, -2, "lastline"); in luaV_setrange()
2541 lua_pop(L, 1); // vim table in luaV_setrange()
2547 static lua_State *L = NULL; variable
2552 return L != NULL; in lua_isopen()
2567 L = luaV_newstate(); in lua_init()
2577 lua_close(L); in lua_end()
2578 L = NULL; in lua_end()
2594 luaV_setrange(L, eap->line1, eap->line2); in ex_lua()
2595 if (luaL_loadbuffer(L, s, strlen(s), LUAVIM_CHUNKNAME) in ex_lua()
2596 || lua_pcall(L, 0, 0, 0)) in ex_lua()
2597 luaV_emsg(L); in ex_lua()
2618 luaV_setrange(L, eap->line1, eap->line2); in ex_luado()
2619 luaL_buffinit(L, &b); in ex_luado()
2624 s = lua_tolstring(L, -1, &len); in ex_luado()
2625 if (luaL_loadbuffer(L, s, len, LUAVIM_CHUNKNAME)) in ex_luado()
2627 luaV_emsg(L); in ex_luado()
2628 lua_pop(L, 1); // function body in ex_luado()
2631 lua_call(L, 0, 1); in ex_luado()
2632 lua_replace(L, -2); // function -> body in ex_luado()
2639 lua_pushvalue(L, -1); // function in ex_luado()
2640 luaV_pushline(L, curbuf, l); // current line as arg in ex_luado()
2641 lua_pushinteger(L, l); // current line number as arg in ex_luado()
2642 if (lua_pcall(L, 2, 1, 0)) in ex_luado()
2644 luaV_emsg(L); in ex_luado()
2650 if (lua_isstring(L, -1)) // update line? in ex_luado()
2653 luaV_checksandbox(L); in ex_luado()
2655 ml_replace(l, luaV_toline(L, -1), TRUE); in ex_luado()
2657 lua_pop(L, 1); // result from luaV_toline in ex_luado()
2659 lua_pop(L, 1); // line in ex_luado()
2661 lua_pop(L, 1); // function in ex_luado()
2673 luaV_setrange(L, eap->line1, eap->line2); in ex_luafile()
2674 if (luaL_loadfile(L, (char *) eap->arg) || lua_pcall(L, 0, 0, 0)) in ex_luafile()
2675 luaV_emsg(L); in ex_luafile()
2684 luaV_getfield(L, LUAVIM_FREE); \
2685 lua_pushlightuserdata(L, (void *) o); \
2686 lua_call(L, 1, 0); \
2696 luaV_getfield(L, LUAVIM_LUAEVAL); in luaV_freetype()
2697 lua_pushstring(L, (char *) str); in luaV_freetype()
2698 lua_pushlightuserdata(L, (void *) arg); in luaV_freetype()
2699 lua_pushlightuserdata(L, (void *) rettv); in luaV_freetype()
2700 lua_call(L, 3, 0); in luaV_freetype()
2710 luaV_getfield(L, LUAVIM_SETREF); in set_ref_in_lua()
2712 lua_pushinteger(L, copyID); in set_ref_in_lua()
2713 lua_call(L, 1, 1); in set_ref_in_lua()
2715 aborted = lua_tointeger(L, -1); in set_ref_in_lua()
2717 lua_pop(L, 1); in set_ref_in_lua()
2727 lua_getglobal(L, "vim"); in update_package_paths_in_lua()
2728 lua_getfield(L, -1, "_update_package_paths"); in update_package_paths_in_lua()
2730 if (lua_pcall(L, 0, 0, 0)) in update_package_paths_in_lua()
2731 luaV_emsg(L); in update_package_paths_in_lua()
2748 lua_rawgeti(funcstate->L, LUA_REGISTRYINDEX, funcstate->lua_funcref); in luaV_call_lua_func()
2754 lua_rawgeti(funcstate->L, LUA_REGISTRYINDEX, funcstate->lua_tableref); in luaV_call_lua_func()
2758 luaV_pushtypval(funcstate->L, &argvars[i]); in luaV_call_lua_func()
2760 if (lua_pcall(funcstate->L, luaargcount, 1, 0)) in luaV_call_lua_func()
2762 luaV_emsg(funcstate->L); in luaV_call_lua_func()
2766 luaV_checktypval(funcstate->L, -1, rettv, "get return value"); in luaV_call_lua_func()
2777 luaL_unref(L, LUA_REGISTRYINDEX, funcstate->lua_funcref); in luaV_call_lua_func_free()
2778 funcstate->L = NULL; in luaV_call_lua_func_free()
2780 luaL_unref(L, LUA_REGISTRYINDEX, funcstate->lua_tableref); in luaV_call_lua_func_free()