wslua: Return nil from Dissector.get() when not found

Return nil from Dissector.get() and DissectorTable.get() when the
reference is not found. This can be used to check for existence of
a dissector or dissector table before use.

We already do this for DissectorTable.get_dissector().
This commit is contained in:
Stig Bjørlykke 2020-09-30 12:05:41 +02:00 committed by Wireshark GitLab Utility
parent 9b46447bb1
commit ebfa1f8a4b
1 changed files with 8 additions and 9 deletions

View File

@ -40,11 +40,11 @@ WSLUA_CONSTRUCTOR Dissector_get (lua_State *L) {
if ((d = find_dissector(name))) { if ((d = find_dissector(name))) {
pushDissector(L, d); pushDissector(L, d);
WSLUA_RETURN(1); /* The <<lua_class_Dissector,`Dissector`>> reference. */ } else {
lua_pushnil(L);
} }
WSLUA_ARG_ERROR(Dissector_get,NAME,"No such dissector"); WSLUA_RETURN(1); /* The <<lua_class_Dissector,`Dissector`>> reference if found, otherwise `nil`. */
return 0;
} }
/* Allow dissector key names to be sorted alphabetically. */ /* Allow dissector key names to be sorted alphabetically. */
@ -303,12 +303,11 @@ WSLUA_CONSTRUCTOR DissectorTable_get (lua_State *L) {
dt->expired = FALSE; dt->expired = FALSE;
pushDissectorTable(L, dt); pushDissectorTable(L, dt);
} else {
WSLUA_RETURN(1); /* The `DissectorTable`. */ lua_pushnil(L);
} }
WSLUA_ARG_ERROR(DissectorTable_get,TABLENAME,"no such dissector_table"); WSLUA_RETURN(1); /* The <<lua_class_DissectorTable,`DissectorTable`>> reference if found, otherwise `nil`. */
return 0;
} }
WSLUA_METHOD DissectorTable_add (lua_State *L) { WSLUA_METHOD DissectorTable_add (lua_State *L) {
@ -597,11 +596,11 @@ WSLUA_METHOD DissectorTable_get_dissector (lua_State *L) {
if (handle) { if (handle) {
pushDissector(L,handle); pushDissector(L,handle);
WSLUA_RETURN(1); /* The <<lua_class_Dissector,`Dissector`>> handle if found, otherwise `nil` */
} else { } else {
lua_pushnil(L); lua_pushnil(L);
WSLUA_RETURN(1);
} }
WSLUA_RETURN(1); /* The <<lua_class_Dissector,`Dissector`>> handle if found, otherwise `nil` */
} }
WSLUA_METHOD DissectorTable_add_for_decode_as (lua_State *L) { WSLUA_METHOD DissectorTable_add_for_decode_as (lua_State *L) {