Hello Vim developers,

I noticed that Vim currently uses the stock implementation of Lua's
debug.debug() function in if_lua.c, which will cause Vim to seemingly
hang if called. I've written and attached a new implementation for
debug.debug() that will make it more usable in Vim if Lua scripters
want to make use of it.

Thanks,
Rob Hoelz
diff --git a/src/if_lua.c b/src/if_lua.c
--- a/src/if_lua.c
+++ b/src/if_lua.c
@@ -1069,6 +1069,59 @@
     {NULL, NULL}
 };
 
+static int luaV_debug_debug(lua_State *L)
+{
+    const char *line = "";
+    int vim_eval_index;
+    int retval;
+
+    /* probably not the best implementation, because I don't 
+     * know how to invoke input() from the C API */
+    lua_getglobal(L, "vim");
+    lua_getfield(L, -1, "eval");
+    lua_remove(L, -2);
+    vim_eval_index = lua_gettop(L);
+
+    while(1) {
+        lua_pushvalue(L, vim_eval_index);
+        lua_pushliteral(L, "input('lua_debug> ')");
+        retval = lua_pcall(L, 1, 1, 0);
+        if(retval) {
+            lua_pushliteral(L, "error calling input(): ");
+            lua_insert(L, -2);
+            lua_concat(L, 2);
+            luaV_emsg(L);
+            return 0;
+        }
+        line = luaL_checkstring(L, -1);
+        if(! strcmp(line, "cont")) {
+            break;
+        }
+        msg_putchar('\n');
+        retval = luaL_loadstring(L, line);
+        if(retval) {
+            lua_pushliteral(L, "error compiling chunk: ");
+            lua_insert(L, -2);
+            lua_concat(L, 2);
+            luaV_emsg(L);
+            lua_pop(L, 1); /* pop line */
+            continue;
+        }
+        retval = lua_pcall(L, 0, 0, 0);
+        if(retval) {
+            lua_pushliteral(L, "error running chunk: ");
+            lua_insert(L, -2);
+            lua_concat(L, 2);
+            luaV_emsg(L);
+            lua_pop(L, 1); /* pop line */
+            continue;
+        }
+        lua_pop(L, 1); /* pop line */
+    }
+
+    return 0;
+}
+
     static int
 luaopen_vim(lua_State *L)
 {
@@ -1082,6 +1135,11 @@
     /* print */
     lua_pushcfunction(L, luaV_print);
     lua_setglobal(L, "print");
+    /* debug.debug */
+    lua_getglobal(L, "debug");
+    lua_pushcfunction(L, luaV_debug_debug);
+    lua_setfield(L, -2, "debug");
+    lua_pop(L, 1);
     /* free */
     lua_pushlightuserdata(L, (void *) LUAVIM_FREE);
     lua_pushcfunction(L, luaV_free);

Attachment: signature.asc
Description: PGP signature

Raspunde prin e-mail lui