diff options
author | Ronan Collobert <ronan@collobert.com> | 2014-02-15 16:35:54 +0400 |
---|---|---|
committer | Ronan Collobert <ronan@collobert.com> | 2014-02-15 16:35:54 +0400 |
commit | ce4727cf6dbe7fb51c7c93823625702a16fc3153 (patch) | |
tree | a5748ca1e0a413bce5f6b1bc6e30fc7614d2e7ba | |
parent | acbf61a46cb15599517db505ebf6af9e3adcbeb6 (diff) |
luajit readline: support for __metatable
-rw-r--r-- | luajit/src/luajit.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/luajit/src/luajit.c b/luajit/src/luajit.c index 6a2752a..a42434a 100644 --- a/luajit/src/luajit.c +++ b/luajit/src/luajit.c @@ -164,6 +164,18 @@ static int lua_rl_dmadd(dmlist *ml, const char *p, size_t pn, const char *s, static int lua_rl_getmetaindex(lua_State *L) { if (!lua_getmetatable(L, -1)) { lua_pop(L, 1); return 0; } + + /* prefer __metatable if it exists */ + lua_pushstring(L, "__metatable"); + lua_rawget(L, -2); + if(lua_istable(L, -1)) + { + lua_remove(L, -2); + return 1; + } + else + lua_pop(L, 1); + lua_pushstring(L, "__index"); lua_rawget(L, -2); lua_replace(L, -2); |