diff options
author | Michael Mann <mmann78@netscape.net> | 2013-10-22 17:41:06 +0000 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2013-10-22 17:41:06 +0000 |
commit | 17679ee25d22b969a98a060c12edc99337f839ae (patch) | |
tree | 668bad597a8237f677577d21a39eb72fe5da89e8 /epan/wslua/wslua_proto.c | |
parent | 1363444506ed5a88a2c427dd31ec791ec572fe43 (diff) |
Cannot define Field refering ProtoField defined in LUA. Bug 3513 (https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=3513)
When a new Field is created, does as following:
* Check whether that field is registered, by using `proto_registrar_get_byname`. This is current behavior.
* (patched) If not registered, check whether that field is defined in LUA and will be registered. This is performed in `wslua_is_field_available` accessing LUA context.
* If not, an error "a field with this name must exist" occurs.
svn path=/trunk/; revision=52771
Diffstat (limited to 'epan/wslua/wslua_proto.c')
-rw-r--r-- | epan/wslua/wslua_proto.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/epan/wslua/wslua_proto.c b/epan/wslua/wslua_proto.c index 3700ed00a6..146a99e8a5 100644 --- a/epan/wslua/wslua_proto.c +++ b/epan/wslua/wslua_proto.c @@ -1595,6 +1595,36 @@ int Proto_register(lua_State* L) { return 1; } +/** + * Query field abbr that is defined and bound to a Proto in lua. + * They are not registered untill the end of the initialization. + */ +int wslua_is_field_available(lua_State* L, const char* field_abbr) { + lua_rawgeti(L, LUA_REGISTRYINDEX, protocols_table_ref); + lua_pushnil(L); + while (lua_next(L, -2)) { + Proto proto; + proto = checkProto(L, -1); + + lua_rawgeti(L, LUA_REGISTRYINDEX, proto->fields); + + lua_pushnil(L); + while (lua_next(L, -2)) { + ProtoField f = checkProtoField(L, -1); + if (strcmp(field_abbr, f->abbr) == 0) { + /* found! */ + lua_pop(L, 6); + return 1; + } + lua_pop(L, 1); /* table value */ + } + lua_pop(L, 2); /* proto->fields and table value */ + } + lua_pop(L, 1); /* protocols_table_ref */ + + return 0; +} + int Proto_commit(lua_State* L) { lua_settop(L,0); lua_rawgeti(L, LUA_REGISTRYINDEX, protocols_table_ref); |