@@ -100,6 +100,7 @@ static const char LUAVIM_FREE[] = "luaV_free";
100100#define lua_setfield dll_lua_setfield
101101#define lua_rawset dll_lua_rawset
102102#define lua_rawseti dll_lua_rawseti
103+ #define lua_remove dll_lua_remove
103104#define lua_setmetatable dll_lua_setmetatable
104105#define lua_call dll_lua_call
105106#define lua_pcall dll_lua_pcall
@@ -161,6 +162,7 @@ int (*dll_lua_getmetatable) (lua_State *L, int objindex);
161162void (* dll_lua_setfield ) (lua_State * L , int idx , const char * k );
162163void (* dll_lua_rawset ) (lua_State * L , int idx );
163164void (* dll_lua_rawseti ) (lua_State * L , int idx , int n );
165+ void (* dll_lua_remove ) (lua_State * L , int idx );
164166int (* dll_lua_setmetatable ) (lua_State * L , int objindex );
165167void (* dll_lua_call ) (lua_State * L , int nargs , int nresults );
166168int (* dll_lua_pcall ) (lua_State * L , int nargs , int nresults , int errfunc );
@@ -229,6 +231,7 @@ static const luaV_Reg luaV_dll[] = {
229231 {"lua_setfield" , (luaV_function ) & dll_lua_setfield },
230232 {"lua_rawset" , (luaV_function ) & dll_lua_rawset },
231233 {"lua_rawseti" , (luaV_function ) & dll_lua_rawseti },
234+ {"lua_remove" , (luaV_function ) & dll_lua_remove },
232235 {"lua_setmetatable" , (luaV_function ) & dll_lua_setmetatable },
233236 {"lua_call" , (luaV_function ) & dll_lua_call },
234237 {"lua_pcall" , (luaV_function ) & dll_lua_pcall },
@@ -923,6 +926,31 @@ luaV_print(lua_State *L)
923926 return 0 ;
924927}
925928
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+
926954 static int
927955luaV_command (lua_State * L )
928956{
@@ -1082,6 +1110,11 @@ luaopen_vim(lua_State *L)
10821110 /* print */
10831111 lua_pushcfunction (L , luaV_print );
10841112 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 );
10851118 /* free */
10861119 lua_pushlightuserdata (L , (void * ) LUAVIM_FREE );
10871120 lua_pushcfunction (L , luaV_free );
0 commit comments