Skip to content
Snippets Groups Projects
Commit cf644abd authored by Georgiy Lebedev's avatar Georgiy Lebedev Committed by Serge Petrenko
Browse files

lua: fix completion retrieval for cdata objects

Cdata objects cannot have an `__autocomplete` metamethod (it's our custom
metamethod). To work this around, we should also lookup the
`__autocomplete` method using an object's `__index` metamethod.

Part of #9107

NO_CHANGELOG=<not a reported bug>
NO_DOC=<bugfix>
parent 2adfc662
No related branches found
No related tags found
No related merge requests found
......@@ -1108,6 +1108,17 @@ lua_rl_getcompletion(lua_State *L)
/* use __autocomplete metamethod if it's present */
lua_pushstring(L, "__autocomplete");
lua_rawget(L, -2);
if (lua_isnil(L, -1)) {
lua_pop(L, 1);
/*
* __autocomplete may not always be part of the metatable (e.g.,
* in case of cdata), so we also want to trigger the __index
* metamethod instead of simply doing a raw lookup in the
* metatable.
*/
lua_pushstring(L, "__autocomplete");
lua_gettable(L, -3);
}
if (lua_isfunction(L, -1)) {
lua_replace(L, -2);
lua_insert(L, -2);
......
......@@ -45,6 +45,14 @@ g.test__autocomplete = function()
})
-- the right way - should add 'auto' comletion
setmetatable(tab, {__autocomplete = function() return {auto = true} end})
t.assert_items_equals(tabcomplete('table11.'), {'table11.',
'table11.first',
'table11.second',
'table11.auto',
})
-- __autocomplete should also be looked up in __index
local autocompletion = function() return {auto = true} end
setmetatable(tab, {__index = {__autocomplete = autocompletion}})
t.assert_items_equals(tabcomplete('table11.'), {'table11.',
'table11.first',
'table11.second',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment