Patch to "fix" Lua binding's debug.debug

48 views
Skip to first unread message

Rob Hoelz

unread,
Sep 12, 2011, 1:03:34 PM9/12/11
to vim...@vim.org
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

vim-debug-debug.patch
signature.asc

Rob Hoelz

unread,
Sep 19, 2011, 11:07:10 AM9/19/11
to vim_dev
>  vim-debug-debug.patch
> 2KViewDownload
>
>  signature.asc
> < 1KViewDownload

Hello again,

It's been a week since I posted this patch, and I haven't seen any
response. If you guys don't want to incorporate my patch into Vim,
that's ok; I'd just like to know if I need to fix anything up, or if
it needs to get vetted or something.

Thanks,
Rob

Dominique Pellé

unread,
Sep 19, 2011, 11:20:51 AM9/19/11
to vim...@googlegroups.com


Hi Rob

Thanks for the patch. I just checked ":help todo.txt" in Vim-7.3.315
and it includes a comment about your patch:

==== [ :help todo.txt ] ====
Patch for Lua debug(). (Rob Hoelz, 2011 Sep 12).
====

It's also near the top of the TODO list so chances are it will
be included soon.

Regards
-- Dominique

Rob Hoelz

unread,
Sep 19, 2011, 11:31:23 AM9/19/11
to vim_dev
On Sep 19, 10:20 am, Dominique Pellé <dominique.pe...@gmail.com>
wrote:
Ah, thanks for the clarfication!

Luis Carvalho

unread,
Sep 19, 2011, 12:12:37 PM9/19/11
to vim...@googlegroups.com
Hi Rob,

> It's been a week since I posted this patch, and I haven't seen any
> response. If you guys don't want to incorporate my patch into Vim,
> that's ok; I'd just like to know if I need to fix anything up, or if
> it needs to get vetted or something.

Sorry for the delay in checking your patch. Can you please check if this
luaV_debug works instead of your luaV_debug_debug? It's simpler and more in
line with Lua's original debug.debug:

static int
luaV_debug (lua_State *L)
{
lua_settop(L, 0);
lua_getglobal(L, "vim");
lua_getfield(L, -1, "eval");
lua_remove(L, -2); /* vim.eval at position 1 */
for (;;)
{
const char *input;
size_t l;
lua_pushvalue(L, 1); /* vim.eval */
lua_pushliteral(L, "input('lua_debug> ')");
lua_call(L, 1, 1, 0); /* return string */
input = lua_tolstring(L, -1, &l);
if (l == 0 || strcmp(input, "cont") == 0)
return 0;
if (luaL_loadbuffer(L, input, l, "=(debug command)") ||
lua_pcall(L, 0, 0, 0))
luaV_emsg(L);
lua_settop(L, 1); /* remove eventual returns, but keep vim.eval */
}
}

If it works, can you please also product a patch?

Cheers,
Luis

--
Computers are useless. They can only give you answers.
-- Pablo Picasso

--
Luis Carvalho (Kozure)
lua -e 'print((("lexca...@NO.gmail.SPAM.com"):gsub("(%u+%.)","")))'

Rob Hoelz

unread,
Sep 20, 2011, 2:59:48 PM9/20/11
to vim_dev
> lua -e 'print((("lexcarva...@NO.gmail.SPAM.com"):gsub("(%u+%.)","")))'

Hi Luis,

Thanks for your improvement to my patch; it works fine, except the
output from each command appears on the same line as the input. The
following patch is based on yours,
but includes a fix for the same line behavior.

diff -r 15b934a16641 src/if_lua.c
--- a/src/if_lua.c Wed Sep 14 19:04:40 2011 +0200
+++ b/src/if_lua.c Tue Sep 20 13:58:15 2011 -0500
@@ -1069,6 +1069,31 @@
{NULL, NULL}
};

+ static int
+luaV_debug (lua_State *L)
+{
+ lua_settop(L, 0);
+ lua_getglobal(L, "vim");
+ lua_getfield(L, -1, "eval");
+ lua_remove(L, -2); /* vim.eval at position 1 */
+ for (;;)
+ {
+ const char *input;
+ size_t l;
+ lua_pushvalue(L, 1); /* vim.eval */
+ lua_pushliteral(L, "input('lua_debug> ')");
+ lua_call(L, 1, 1); /* return string */
+ msg_putchar('\n');
+ input = lua_tolstring(L, -1, &l);
+ if (l == 0 || strcmp(input, "cont") == 0)
+ return 0;
+ if (luaL_loadbuffer(L, input, l, "=(debug command)") ||
+ lua_pcall(L, 0, 0, 0))
+ luaV_emsg(L);
+ lua_settop(L, 1); /* remove eventual returns, but keep
vim.eval */
+ }
+}
+
static int
luaopen_vim(lua_State *L)
{
@@ -1082,6 +1107,11 @@
/* print */
lua_pushcfunction(L, luaV_print);
lua_setglobal(L, "print");
+ /* debug.debug */
+ lua_getglobal(L, "debug");
+ lua_pushcfunction(L, luaV_debug);
+ lua_setfield(L, -2, "debug");
+ lua_pop(L, 1);
/* free */
lua_pushlightuserdata(L, (void *) LUAVIM_FREE);
lua_pushcfunction(L, luaV_free);

Thanks,
Rob

Luis Carvalho

unread,
Sep 20, 2011, 6:16:05 PM9/20/11
to vim...@googlegroups.com
Hi Rob,

> Thanks for your improvement to my patch; it works fine, except the
> output from each command appears on the same line as the input. The
> following patch is based on yours,
> but includes a fix for the same line behavior.

Ok, great. We still need to define lua_remove for the dynamic version of the
interpreter, so I'm updating the patch. I've also added a comment to
msg_putchar and moved the function definition closer to luaV_print.

Thanks,
Luis

--
Computers are useless. They can only give you answers.
-- Pablo Picasso

--
Luis Carvalho (Kozure)
lua -e 'print((("lexca...@NO.gmail.SPAM.com"):gsub("(%u+%.)","")))'

if-lua-debug.diff
Reply all
Reply to author
Forward
0 new messages