diff options
author | Hadriel Kaplan <hadrielk@yahoo.com> | 2014-03-10 15:18:24 -0400 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2014-03-11 05:30:58 +0000 |
commit | 9961ee369c97768d5ed906d5ef5d17b718d33d3e (patch) | |
tree | 0c4c556d5949df2e4b99df061e3678729f928f5e /epan/wslua/wslua.h | |
parent | f4de2a2dd1142e7d7c9069bc923eeb8c7ac20333 (diff) |
Fix Bug 9870 'Lua: trying to call/get an invalid name results in a get-loop error'
Due to the change I made previously for how methods are accessed, if you try
to access one that doesn't exist (for example mistype it or whatever), you get
an internal Lua error about a loop in table get, as opposed to the right error
message about the field not existing.
That's because I had set the class' metatable __index metamethod to point to
the class table, which of course has the metatable with the __index
metamethod, causing a lookup loop. Blech.
Change-Id: I20d3717feadd45f652c2640e1671846184e7082d
Reviewed-on: https://code.wireshark.org/review/593
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/wslua/wslua.h')
-rw-r--r-- | epan/wslua/wslua.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h index 2ec7456766..9a41a714f0 100644 --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -343,6 +343,7 @@ typedef struct _wslua_attribute_table { lua_CFunction setfunc; } wslua_attribute_table; extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, gboolean is_getter); +extern int wslua_set__index(lua_State *L); #define WSLUA_TYPEOF_FIELD "__typeof" @@ -387,9 +388,8 @@ extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, gb /* setup the meta table */ \ WSLUA_REGISTER_META(C); \ luaL_getmetatable(L, #C); \ - /* push a copy of the class methods table, and set it to be the metatable's __index field */ \ - lua_pushvalue (L, -2); \ - lua_setfield (L, -2, "__index"); \ + /* the following sets the __index metamethod appropriately */ \ + wslua_set__index(L); \ /* set the metatable to be the class's metatable, so scripts can inspect it, and metamethods work for class tables */ \ lua_setmetatable(L, -2); \ /* set the class methods table as the global class table */ \ |