comparison src/if_lua.c @ 3091:92a181a1cec3 v7.3.317

updated for version 7.3.317 Problem: Calling debug.debug() in Lua may cause Vim to hang. Solution: Add a better debug method. (Rob Hoelz, Luis Carvalho)
author Bram Moolenaar <bram@vim.org>
date Wed, 21 Sep 2011 17:15:39 +0200
parents 0c7d6d01e058
children 3801e4811b0e
comparison
equal deleted inserted replaced
3090:6838fcfbd037 3091:92a181a1cec3
98 #define lua_newuserdata dll_lua_newuserdata 98 #define lua_newuserdata dll_lua_newuserdata
99 #define lua_getmetatable dll_lua_getmetatable 99 #define lua_getmetatable dll_lua_getmetatable
100 #define lua_setfield dll_lua_setfield 100 #define lua_setfield dll_lua_setfield
101 #define lua_rawset dll_lua_rawset 101 #define lua_rawset dll_lua_rawset
102 #define lua_rawseti dll_lua_rawseti 102 #define lua_rawseti dll_lua_rawseti
103 #define lua_remove dll_lua_remove
103 #define lua_setmetatable dll_lua_setmetatable 104 #define lua_setmetatable dll_lua_setmetatable
104 #define lua_call dll_lua_call 105 #define lua_call dll_lua_call
105 #define lua_pcall dll_lua_pcall 106 #define lua_pcall dll_lua_pcall
106 /* libs */ 107 /* libs */
107 #define luaopen_base dll_luaopen_base 108 #define luaopen_base dll_luaopen_base
159 void *(*dll_lua_newuserdata) (lua_State *L, size_t sz); 160 void *(*dll_lua_newuserdata) (lua_State *L, size_t sz);
160 int (*dll_lua_getmetatable) (lua_State *L, int objindex); 161 int (*dll_lua_getmetatable) (lua_State *L, int objindex);
161 void (*dll_lua_setfield) (lua_State *L, int idx, const char *k); 162 void (*dll_lua_setfield) (lua_State *L, int idx, const char *k);
162 void (*dll_lua_rawset) (lua_State *L, int idx); 163 void (*dll_lua_rawset) (lua_State *L, int idx);
163 void (*dll_lua_rawseti) (lua_State *L, int idx, int n); 164 void (*dll_lua_rawseti) (lua_State *L, int idx, int n);
165 void (*dll_lua_remove) (lua_State *L, int idx);
164 int (*dll_lua_setmetatable) (lua_State *L, int objindex); 166 int (*dll_lua_setmetatable) (lua_State *L, int objindex);
165 void (*dll_lua_call) (lua_State *L, int nargs, int nresults); 167 void (*dll_lua_call) (lua_State *L, int nargs, int nresults);
166 int (*dll_lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); 168 int (*dll_lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
167 /* libs */ 169 /* libs */
168 int (*dll_luaopen_base) (lua_State *L); 170 int (*dll_luaopen_base) (lua_State *L);
227 {"lua_newuserdata", (luaV_function) &dll_lua_newuserdata}, 229 {"lua_newuserdata", (luaV_function) &dll_lua_newuserdata},
228 {"lua_getmetatable", (luaV_function) &dll_lua_getmetatable}, 230 {"lua_getmetatable", (luaV_function) &dll_lua_getmetatable},
229 {"lua_setfield", (luaV_function) &dll_lua_setfield}, 231 {"lua_setfield", (luaV_function) &dll_lua_setfield},
230 {"lua_rawset", (luaV_function) &dll_lua_rawset}, 232 {"lua_rawset", (luaV_function) &dll_lua_rawset},
231 {"lua_rawseti", (luaV_function) &dll_lua_rawseti}, 233 {"lua_rawseti", (luaV_function) &dll_lua_rawseti},
234 {"lua_remove", (luaV_function) &dll_lua_remove},
232 {"lua_setmetatable", (luaV_function) &dll_lua_setmetatable}, 235 {"lua_setmetatable", (luaV_function) &dll_lua_setmetatable},
233 {"lua_call", (luaV_function) &dll_lua_call}, 236 {"lua_call", (luaV_function) &dll_lua_call},
234 {"lua_pcall", (luaV_function) &dll_lua_pcall}, 237 {"lua_pcall", (luaV_function) &dll_lua_pcall},
235 /* libs */ 238 /* libs */
236 {"luaopen_base", (luaV_function) &dll_luaopen_base}, 239 {"luaopen_base", (luaV_function) &dll_luaopen_base},
922 luaV_msg(L); 925 luaV_msg(L);
923 return 0; 926 return 0;
924 } 927 }
925 928
926 static int 929 static int
930 luaV_debug(lua_State *L)
931 {
932 lua_settop(L, 0);
933 lua_getglobal(L, "vim");
934 lua_getfield(L, -1, "eval");
935 lua_remove(L, -2); /* vim.eval at position 1 */
936 for (;;)
937 {
938 const char *input;
939 size_t l;
940 lua_pushvalue(L, 1); /* vim.eval */
941 lua_pushliteral(L, "input('lua_debug> ')");
942 lua_call(L, 1, 1); /* return string */
943 input = lua_tolstring(L, -1, &l);
944 if (l == 0 || strcmp(input, "cont") == 0)
945 return 0;
946 msg_putchar('\n'); /* avoid outputting on input line */
947 if (luaL_loadbuffer(L, input, l, "=(debug command)")
948 || lua_pcall(L, 0, 0, 0))
949 luaV_emsg(L);
950 lua_settop(L, 1); /* remove eventual returns, but keep vim.eval */
951 }
952 }
953
954 static int
927 luaV_command(lua_State *L) 955 luaV_command(lua_State *L)
928 { 956 {
929 do_cmdline_cmd((char_u *) luaL_checkstring(L, 1)); 957 do_cmdline_cmd((char_u *) luaL_checkstring(L, 1));
930 update_screen(VALID); 958 update_screen(VALID);
931 return 0; 959 return 0;
1080 lua_setmetatable(L, -2); 1108 lua_setmetatable(L, -2);
1081 lua_replace(L, LUA_ENVIRONINDEX); 1109 lua_replace(L, LUA_ENVIRONINDEX);
1082 /* print */ 1110 /* print */
1083 lua_pushcfunction(L, luaV_print); 1111 lua_pushcfunction(L, luaV_print);
1084 lua_setglobal(L, "print"); 1112 lua_setglobal(L, "print");
1113 /* debug.debug */
1114 lua_getglobal(L, "debug");
1115 lua_pushcfunction(L, luaV_debug);
1116 lua_setfield(L, -2, "debug");
1117 lua_pop(L, 1);
1085 /* free */ 1118 /* free */
1086 lua_pushlightuserdata(L, (void *) LUAVIM_FREE); 1119 lua_pushlightuserdata(L, (void *) LUAVIM_FREE);
1087 lua_pushcfunction(L, luaV_free); 1120 lua_pushcfunction(L, luaV_free);
1088 lua_rawset(L, LUA_REGISTRYINDEX); 1121 lua_rawset(L, LUA_REGISTRYINDEX);
1089 /* register */ 1122 /* register */