Fix code completion bug in Lua REPL

This commit is contained in:
Justine Tunney 2022-06-26 03:11:56 -07:00
parent 61257d48d4
commit 2f515ac5e3

View file

@ -116,22 +116,24 @@ void lua_readline_completions (const char *p, linenoiseCompletions *c) {
a = p; a = p;
b = strpbrk(a, ".:"); b = strpbrk(a, ".:");
while (b) { while (b) {
component = strndup(a, b - a);
found = false; found = false;
lua_pushnil(L); // search key if (lua_istable(L, -1)) {
while (lua_next(L, -2)) { component = strndup(a, b - a);
if (lua_type(L, -2) == LUA_TSTRING) { lua_pushnil(L); // search key
name = lua_tostring(L, -2); while (lua_next(L, -2)) {
if (!strcmp(name, component)) { if (lua_type(L, -2) == LUA_TSTRING) {
lua_remove(L, -3); // remove table name = lua_tostring(L, -2);
lua_remove(L, -2); // remove key if (!strcmp(name, component)) {
found = true; lua_remove(L, -3); // remove table
break; lua_remove(L, -2); // remove key
found = true;
break;
}
} }
lua_pop(L, 1); // pop value
} }
lua_pop(L, 1); // pop value free(component);
} }
free(component);
if (!found) { if (!found) {
lua_pop(L, 1); // pop table lua_pop(L, 1); // pop table
return; return;