diff options
author | stig <stig@f5534014-38df-0310-8fa8-9805f1628bb7> | 2010-01-06 22:14:25 +0000 |
---|---|---|
committer | stig <stig@f5534014-38df-0310-8fa8-9805f1628bb7> | 2010-01-06 22:14:25 +0000 |
commit | bf43b198b42c363876b13e9fba287f554816f920 (patch) | |
tree | a928fdd2482966f35e3fc6f79c0640943e2399a2 /epan/wslua | |
parent | f4dcae9888f48b4cea58c2bbc3479c818521f1f6 (diff) |
Added concat meta method for TvbRange, Int64 and UInt64.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@31458 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'epan/wslua')
-rw-r--r-- | epan/wslua/wslua_tvb.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/epan/wslua/wslua_tvb.c b/epan/wslua/wslua_tvb.c index 147973b1c7..2004e7782a 100644 --- a/epan/wslua/wslua_tvb.c +++ b/epan/wslua/wslua_tvb.c @@ -1114,6 +1114,27 @@ WSLUA_METAMETHOD TvbRange__tostring(lua_State* L) { return 1; } +WSLUA_METAMETHOD TvbRange__concat(lua_State* L) { + /* Concatenate a string and a TvbRange */ + + const gchar *str = luaL_checkstring(L,1); + TvbRange tvbr = checkTvbRange(L,2); + + if (str == NULL) { + luaL_error(L, "Only string concat for tvb range"); + return 0; + } + + if (!(tvbr && tvbr->tvb)) return 0; + if (tvbr->tvb->expired) { + luaL_error(L,"expired tvb"); + return 0; + } + + lua_pushstring(L,ep_strdup_printf("%s%s", str, tvb_bytes_to_str(tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len))); + return 1; +} + static const luaL_reg TvbRange_methods[] = { {"uint", TvbRange_uint}, {"le_uint", TvbRange_le_uint}, @@ -1141,6 +1162,7 @@ static const luaL_reg TvbRange_methods[] = { static const luaL_reg TvbRange_meta[] = { {"__tostring", TvbRange__tostring}, + {"__concat", TvbRange__concat}, {"__call", TvbRange_range}, { NULL, NULL } }; @@ -1168,6 +1190,20 @@ WSLUA_METAMETHOD Int64__tostring(lua_State* L) { return 1; } +WSLUA_METAMETHOD Int64__concat(lua_State* L) { + /* Concatenate a string and a Int64 */ + const gchar *str = luaL_checkstring(L,1); + Int64 num = checkInt64(L,2); + + if (str == NULL) { + luaL_error(L, "Only string concat for int64"); + return 0; + } + + lua_pushstring(L,ep_strdup_printf("%s%" G_GINT64_MODIFIER "d",str,(gint64)*(num))); + return 1; +} + static int Int64__gc(lua_State* L) { Int64 num = checkInt64(L,1); @@ -1184,6 +1220,7 @@ static const luaL_reg Int64_methods[] = { static const luaL_reg Int64_meta[] = { {"__tostring", Int64__tostring}, + {"__concat", Int64__concat}, {"__gc", Int64__gc}, { NULL, NULL } }; @@ -1203,6 +1240,20 @@ WSLUA_METAMETHOD UInt64__tostring(lua_State* L) { return 1; } +WSLUA_METAMETHOD UInt64__concat(lua_State* L) { + /* Concatenate a string and a UInt64 */ + const gchar *str = luaL_checkstring(L,1); + UInt64 num = checkUInt64(L,2); + + if (str == NULL) { + luaL_error(L, "Only string concat for uint64"); + return 0; + } + + lua_pushstring(L,ep_strdup_printf("%s%" G_GINT64_MODIFIER "u",str,(guint64)*(num))); + return 1; +} + static int UInt64__gc(lua_State* L) { UInt64 num = checkUInt64(L,1); @@ -1219,6 +1270,7 @@ static const luaL_reg UInt64_methods[] = { static const luaL_reg UInt64_meta[] = { {"__tostring", UInt64__tostring}, + {"__concat", UInt64__concat}, {"__gc", UInt64__gc}, { NULL, NULL } }; |