From f8fd960cb8f5378c8ab6b20b4bc7f0b73498d057 Mon Sep 17 00:00:00 2001 From: Balint Reczey Date: Sat, 20 Apr 2024 18:57:17 +0200 Subject: [PATCH] wslua: Fix support for Lua 5.1 and 5.2 on 32bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add macros to use lua_pushnumber for Lua 5.1/5.2 and lua_pushinteger for Lua 5.3/5.4 based on change proposal by Stig Bjørlykke. Ping #10881 Follow up for commit 8cac5932f79b87deda26480769a266ff344036e6. Co-authored-by: Stig Bjørlykke --- epan/wslua/init_wslua.c | 10 +++--- epan/wslua/lrexlib/pcre2/lpcre2.c | 2 +- epan/wslua/make-taps.py | 24 +++++++------- epan/wslua/wslua.h | 7 +++++ epan/wslua/wslua_byte_array.c | 12 +++---- epan/wslua/wslua_dissector.c | 4 +-- epan/wslua/wslua_field.c | 12 +++---- epan/wslua/wslua_file.c | 6 ++-- epan/wslua/wslua_file_handler.c | 8 ++--- epan/wslua/wslua_frame_info.c | 8 ++--- epan/wslua/wslua_pinfo.c | 2 +- epan/wslua/wslua_pref.c | 4 +-- epan/wslua/wslua_struct.c | 10 +++--- epan/wslua/wslua_tree.c | 6 ++-- epan/wslua/wslua_tvb.c | 52 +++++++++++++++---------------- epan/wslua/wslua_wtap.c | 10 +++--- 16 files changed, 92 insertions(+), 85 deletions(-) --- a/epan/wslua/init_wslua.c +++ b/epan/wslua/init_wslua.c @@ -969,7 +969,7 @@ lua_getglobal(L, table); /* Set symbol in table. */ lua_pushstring(L, name); - lua_pushinteger(L, value); + WSLUA_PUSHINTEGER(L, value); lua_settable(L, -3); /* Pop table from stack. */ lua_pop(L, 1); @@ -979,7 +979,7 @@ add_global_symbol(const char *name, int value) { /* Set symbol in global environment. */ - lua_pushinteger(L, value); + WSLUA_PUSHINTEGER(L, value); lua_setglobal(L, name); } @@ -988,7 +988,7 @@ { lua_getglobal(L, WSLUA_EXPERT_TABLE); lua_getfield(L, -1, WSLUA_EXPERT_SEVERITY_TABLE); - lua_pushinteger(L, value); + WSLUA_PUSHINTEGER(L, value); lua_setfield(L, -2, name); lua_pop(L, 2); } @@ -998,7 +998,7 @@ { lua_getglobal(L, WSLUA_EXPERT_TABLE); lua_getfield(L, -1, WSLUA_EXPERT_GROUP_TABLE); - lua_pushinteger(L, value); + WSLUA_PUSHINTEGER(L, value); lua_setfield(L, -2, name); lua_pop(L, 2); } @@ -1007,7 +1007,7 @@ add_menu_group_symbol(const char *name, int value) { /* Set symbol in global environment. */ - lua_pushinteger(L, value); + WSLUA_PUSHINTEGER(L, value); char *str = g_strdup(name); char *s = strstr(str, "_GROUP_"); if (s == NULL) --- a/epan/wslua/lrexlib/pcre2/lpcre2.c +++ b/epan/wslua/lrexlib/pcre2/lpcre2.c @@ -432,7 +432,7 @@ #define SET_INFO_FIELD(L,ud,what,name,valtype) { \ valtype val; \ if (0 == pcre2_pattern_info (ud->pr, what, &val)) { \ - lua_pushinteger (L, val); \ + WSLUA_PUSHINTEGER (L, val); \ lua_setfield (L, -2, name); \ } \ } --- a/epan/wslua/make-taps.py +++ b/epan/wslua/make-taps.py @@ -34,18 +34,18 @@ types = { 'gchar[]': 'lua_pushstring(L,(const char*)v->STR);', 'gchar*': 'lua_pushstring(L,(const char*)v->STR);', - 'guint': 'lua_pushinteger(L,(lua_Integer)v->STR);', - 'guint8': 'lua_pushinteger(L,(lua_Integer)v->STR);', - 'guint16': 'lua_pushinteger(L,(lua_Integer)v->STR);', - 'guint32': 'lua_pushinteger(L,(lua_Integer)v->STR);', - 'gint': 'lua_pushinteger(L,(lua_Integer)v->STR);', - 'gint8': 'lua_pushinteger(L,(lua_Integer)v->STR);', - 'gint16': 'lua_pushinteger(L,(lua_Integer)v->STR);', - 'gint32': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'guint': 'WSLUA_PUSHINTEGER_WITH_CAST(L,v->STR);', + 'guint8': 'WSLUA_PUSHINTEGER_WITH_CAST(L,v->STR);', + 'guint16': 'WSLUA_PUSHINTEGER_WITH_CAST(L,v->STR);', + 'guint32': 'WSLUA_PUSHINTEGER_WITH_CAST(L,v->STR);', + 'gint': 'WSLUA_PUSHINTEGER_WITH_CAST(L,v->STR);', + 'gint8': 'WSLUA_PUSHINTEGER_WITH_CAST(L,v->STR);', + 'gint16': 'WSLUA_PUSHINTEGER_WITH_CAST(L,v->STR);', + 'gint32': 'WSLUA_PUSHINTEGER_WITH_CAST(L,v->STR);', 'gboolean': 'lua_pushboolean(L,(int)v->STR);', 'address': '{ Address a = (Address)g_malloc(sizeof(address)); copy_address(a, &(v->STR)); pushAddress(L,a); }', 'address*': '{ Address a = (Address)g_malloc(sizeof(address)); copy_address(a, v->STR); pushAddress(L,a); }', - 'int': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'int': 'WSLUA_PUSHINTEGER_WITH_CAST(L,v->STR);', 'nstime_t': 'lua_pushnumber(L,(lua_Number)nstime_to_sec(&(v->STR)));', 'nstime_t*': 'lua_pushnumber(L,(lua_Number)nstime_to_sec(v->STR));', } @@ -79,7 +79,7 @@ for enum in enum_types: m = re.search(fr'typedef\s+enum[^{{]*{{([^}}]*)}}[\s\n]*{enum}[\s\n]*;', buf, flags=re.DOTALL) if m: - types[enum] = f'lua_pushinteger(L,(lua_Integer)v->STR); /* {enum} */' + types[enum] = f'WSLUA_PUSHINTEGER_WITH_CAST(L,v->STR); /* {enum} */' econsts = m.group(1).splitlines() econsts = [re.sub(r'\s+', '', item) for item in econsts] econsts = [re.sub(',', '', item) for item in econsts] @@ -183,9 +183,9 @@ c_body += f'\n\t/*\n\t * {enum}\n\t */\n\tlua_newtable(L);\n' for econst in enums[enum]: c_body += f'''\ - lua_pushinteger(L,(lua_Integer){econst}); + WSLUA_PUSHINTEGER_WITH_CAST(L,{econst}); lua_setglobal(L,"{econst}"); - lua_pushinteger(L,(lua_Integer){econst}); + WSLUA_PUSHINTEGER_WITH_CAST(L,{econst}); lua_pushstring(L,"{econst}"); lua_settable(L,-3); ''' --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -81,6 +81,13 @@ #define wslua_optguint32(L,i,d) (guint32) ( luaL_optnumber(L,i,d) ) #define wslua_optguint64(L,i,d) (guint64) ( luaL_optnumber(L,i,d) ) +#if LUA_VERSION_NUM < 503 +#define WSLUA_PUSHINTEGER(L, i) lua_pushnumber(L, i) +#define WSLUA_PUSHINTEGER_WITH_CAST(L, i) lua_pushnumber(L, (lua_Number)i) +#else +#define WSLUA_PUSHINTEGER(L, i) lua_pushinteger(L, i) +#define WSLUA_PUSHINTEGER_WITH_CAST(L, i) lua_pushinteger(L, (lua_Integer)i) +#endif struct _wslua_tvb { tvbuff_t* ws_tvb; --- a/epan/wslua/wslua_byte_array.c +++ b/epan/wslua/wslua_byte_array.c @@ -214,7 +214,7 @@ luaL_argerror(L,2,"index out of range"); return 0; } - lua_pushinteger(L,ba->data[idx]); + WSLUA_PUSHINTEGER(L,ba->data[idx]); WSLUA_RETURN(1); /* The value [0-255] of the byte. */ } @@ -255,7 +255,7 @@ value |= (guint8)ba->data[offset + i]; } - lua_pushinteger(L, value); + WSLUA_PUSHINTEGER(L, value); WSLUA_RETURN(1); /* The value of the little endian encoded signed integer beginning at given offset with given length. */ } @@ -337,7 +337,7 @@ value |= (guint8)ba->data[offset + i]; } - lua_pushinteger(L, value); + WSLUA_PUSHINTEGER(L, value); WSLUA_RETURN(1); /* The value of the little endian encoded unsigned integer beginning at given offset with given length. */ } @@ -419,7 +419,7 @@ value |= (guint8)ba->data[offset + i]; } - lua_pushinteger(L, value); + WSLUA_PUSHINTEGER(L, value); WSLUA_RETURN(1); /* The value of the big endian encoded 32 bit signed integer beginning at given offset with given length. */ } @@ -501,7 +501,7 @@ value |= (guint8)ba->data[offset + i]; } - lua_pushinteger(L, value); + WSLUA_PUSHINTEGER(L, value); WSLUA_RETURN(1); /* The value of the big endian encoded 32 bit unsigned integer beginning at given offset with given length. */ } @@ -551,7 +551,7 @@ /* Obtain the length of a <>. */ ByteArray ba = checkByteArray(L,1); - lua_pushinteger(L,(lua_Integer)ba->len); + WSLUA_PUSHINTEGER_WITH_CAST(L,ba->len); WSLUA_RETURN(1); /* The length of the <>. */ } --- a/epan/wslua/wslua_dissector.c +++ b/epan/wslua/wslua_dissector.c @@ -107,7 +107,7 @@ are normal conditions and possibly don't need the Lua traceback. */ if (error) { WSLUA_ERROR(Dissector_call,error); } - lua_pushinteger(L,(lua_Integer)len); + WSLUA_PUSHINTEGER_WITH_CAST(L,len); WSLUA_RETURN(1); /* Number of bytes dissected. Note that some dissectors always return number of bytes in incoming buffer, so be aware. */ } @@ -618,7 +618,7 @@ if (error) { WSLUA_ERROR(DissectorTable_try,error); } - lua_pushinteger(L,(lua_Integer)len); + WSLUA_PUSHINTEGER_WITH_CAST(L,len); WSLUA_RETURN(1); /* Number of bytes dissected. Note that some dissectors always return number of bytes in incoming buffer, so be aware. */ } --- a/epan/wslua/wslua_field.c +++ b/epan/wslua/wslua_field.c @@ -50,7 +50,7 @@ */ FieldInfo fi = checkFieldInfo(L,1); - lua_pushinteger(L,fi->ws_fi->length); + WSLUA_PUSHINTEGER(L,fi->ws_fi->length); return 1; } @@ -61,7 +61,7 @@ */ FieldInfo fi = checkFieldInfo(L,1); - lua_pushinteger(L,fi->ws_fi->start); + WSLUA_PUSHINTEGER(L,fi->ws_fi->start); return 1; } @@ -91,13 +91,13 @@ case FT_UINT24: case FT_UINT32: case FT_FRAMENUM: - lua_pushinteger(L,(lua_Integer)(fvalue_get_uinteger(fi->ws_fi->value))); + WSLUA_PUSHINTEGER_WITH_CAST(L,(fvalue_get_uinteger(fi->ws_fi->value))); return 1; case FT_INT8: case FT_INT16: case FT_INT24: case FT_INT32: - lua_pushinteger(L,(lua_Integer)(fvalue_get_sinteger(fi->ws_fi->value))); + WSLUA_PUSHINTEGER_WITH_CAST(L,(fvalue_get_sinteger(fi->ws_fi->value))); return 1; case FT_FLOAT: case FT_DOUBLE: @@ -268,7 +268,7 @@ FieldInfo fi = checkFieldInfo(L,1); if (fi->ws_fi->hfinfo) { - lua_pushinteger(L, fi->ws_fi->hfinfo->type); + WSLUA_PUSHINTEGER(L, fi->ws_fi->hfinfo->type); } else { lua_pushnil(L); @@ -710,7 +710,7 @@ Field f = checkField(L,1); header_field_info* hfinfo = NULL; - GET_HFINFO_MEMBER(lua_pushinteger, type); + GET_HFINFO_MEMBER(WSLUA_PUSHINTEGER, type); return 1; } --- a/epan/wslua/wslua_file.c +++ b/epan/wslua/wslua_file.c @@ -152,7 +152,7 @@ buff[buff_end] = '\0'; if (buff_end > 0 && num_digits > 0 && sscanf(buff, "%lf", &d) == 1) { - lua_pushinteger(L, d); + WSLUA_PUSHINTEGER(L, d); return 1; } else { @@ -355,7 +355,7 @@ return 2; } - lua_pushinteger(L, (lua_Integer)(file_tell(f->file))); + lua_pushnumber(L, (lua_Number)(file_tell(f->file))); } else { offset = wtap_dump_file_seek(f->wdh, offset, mode[op], &err); @@ -374,7 +374,7 @@ return 2; } - lua_pushinteger(L, (lua_Integer)(offset)); + lua_pushnumber(L, (lua_Number)(offset)); } WSLUA_RETURN(1); /* The current file cursor position as a number. */ --- a/epan/wslua/wslua_file_handler.c +++ b/epan/wslua/wslua_file_handler.c @@ -326,7 +326,7 @@ fp = push_File(L, wth->random_fh); fc = push_CaptureInfo(L, wth, FALSE); fi = push_FrameInfo(L, rec, buf); - lua_pushinteger(L, (lua_Integer)seek_off); + lua_pushnumber(L, (lua_Number)seek_off); switch ( lua_pcall(L,4,1,1) ) { case 0: @@ -474,7 +474,7 @@ INIT_FILEHANDLER_ROUTINE(can_write_encap,WTAP_ERR_UNWRITABLE_ENCAP,NULL,NULL); - lua_pushinteger(L, encap); + WSLUA_PUSHINTEGER(L, encap); switch ( lua_pcall(L,1,1,1) ) { case 0: @@ -842,7 +842,7 @@ fh->registered = TRUE; registered_file_handlers = g_slist_prepend(registered_file_handlers, fh); - lua_pushinteger(L, fh->file_type); + WSLUA_PUSHINTEGER(L, fh->file_type); WSLUA_RETURN(1); /* the new type number for this file reader/write */ } @@ -1207,7 +1207,7 @@ break;\ } \ } \ - lua_pushinteger(L, (lua_Integer)supported_comment_types); \ + lua_pushnumber(L, (lua_Number)supported_comment_types); \ }); WSLUA_ATTRIBUTE_SET(FileHandler,supported_comment_types, { \ guint supported_comment_types; \ --- a/epan/wslua/wslua_frame_info.c +++ b/epan/wslua/wslua_frame_info.c @@ -89,7 +89,7 @@ g_free(err_info); /* is this right? */ } else lua_pushnil(L); - lua_pushinteger(L, err); + WSLUA_PUSHINTEGER(L, err); return 3; } @@ -120,7 +120,7 @@ lua_createtable(L, n_comments, 0); for (i = 0; i < n_comments; i++) { comment = NULL; - lua_pushinteger(L, i+1); + WSLUA_PUSHINTEGER(L, i+1); if (WTAP_OPTTYPE_SUCCESS == wtap_block_get_nth_string_option_value(block, OPT_COMMENT, i, &comment)) { lua_pushstring(L, comment); @@ -371,7 +371,7 @@ if (!wtap_dump_file_write(fh->wdh, fi->pd, (size_t)(len), &err)) { lua_pushboolean(L, FALSE); lua_pushfstring(L, "FrameInfoConst write_data() error: %s", g_strerror(err)); - lua_pushinteger(L, err); + WSLUA_PUSHINTEGER(L, err); return 3; } @@ -403,7 +403,7 @@ lua_createtable(L, n_comments, 0); for (i = 0; i < n_comments; i++) { comment = NULL; - lua_pushinteger(L, i+1); + WSLUA_PUSHINTEGER(L, i+1); if (WTAP_OPTTYPE_SUCCESS == wtap_block_get_nth_string_option_value(block, OPT_COMMENT, i, &comment)) { lua_pushstring(L, comment); --- a/epan/wslua/wslua_pinfo.c +++ b/epan/wslua/wslua_pinfo.c @@ -308,7 +308,7 @@ if (pinfo->ws_pinfo->match_string) { lua_pushstring(L,pinfo->ws_pinfo->match_string); } else { - lua_pushinteger(L,(lua_Integer)(pinfo->ws_pinfo->match_uint)); + WSLUA_PUSHINTEGER_WITH_CAST(L,(pinfo->ws_pinfo->match_uint)); } return 1; --- a/epan/wslua/wslua_pref.c +++ b/epan/wslua/wslua_pref.c @@ -515,9 +515,9 @@ if ( g_str_equal(prefs_p->name,name) ) { switch (prefs_p->type) { case PREF_BOOL: lua_pushboolean(L, prefs_p->value.b); break; - case PREF_UINT: lua_pushinteger(L,(lua_Integer)prefs_p->value.u); break; + case PREF_UINT: WSLUA_PUSHINTEGER_WITH_CAST(L,prefs_p->value.u); break; case PREF_STRING: lua_pushstring(L,prefs_p->value.s); break; - case PREF_ENUM: lua_pushinteger(L,(lua_Integer)prefs_p->value.e); break; + case PREF_ENUM: WSLUA_PUSHINTEGER_WITH_CAST(L,prefs_p->value.e); break; case PREF_RANGE: { char *push_str = range_convert_range(NULL, prefs_p->value.r); --- a/epan/wslua/wslua_struct.c +++ b/epan/wslua/wslua_struct.c @@ -410,7 +410,7 @@ * given endianness and size. If the integer type is signed, this makes * the Lua number be +/- correctly as well. */ -static lua_Integer getinteger (const gchar *buff, int endian, +static lua_Number getinteger (const gchar *buff, int endian, int issigned, int size) { Uinttype l = 0; int i; @@ -427,12 +427,12 @@ } } if (!issigned) - return (lua_Integer)l; + return (lua_Number)l; else { /* signed format */ Uinttype mask = (Uinttype)(~((Uinttype)0)) << (size*8 - 1); if (l & mask) /* negative value? */ l |= mask; /* signal extension */ - return (lua_Integer)(Inttype)l; + return (lua_Number)(Inttype)l; } } @@ -470,8 +470,8 @@ case 'b': case 'B': case 'h': case 'H': case 'l': case 'L': case 'T': case 'i': case 'I': { /* integer types */ int issigned = g_ascii_islower(opt); - lua_Integer res = getinteger(data+pos, h.endian, issigned, (int)size); - lua_pushinteger(L, res); + lua_Number res = getinteger(data+pos, h.endian, issigned, (int)size); + WSLUA_PUSHINTEGER(L, res); break; } case 'e': { --- a/epan/wslua/wslua_tree.c +++ b/epan/wslua/wslua_tree.c @@ -123,7 +123,7 @@ item = proto_tree_add_item_ret_int(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding, &ret); - lua_pushinteger(L, (lua_Integer)ret); + lua_pushnumber(L, (lua_Number)ret); lua_pushinteger(L, tvbr->offset + tvbr->len); } break; @@ -152,7 +152,7 @@ item = proto_tree_add_item_ret_uint(tree_item-> tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding, &ret); - lua_pushinteger(L, (lua_Integer)ret); + lua_pushnumber(L, (lua_Number)ret); lua_pushinteger(L, tvbr->offset + tvbr->len); } break; @@ -502,7 +502,7 @@ switch(type) { case FT_PROTOCOL: item = proto_tree_add_item(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,ENC_NA); - lua_pushinteger(L,0); + WSLUA_PUSHINTEGER(L,0); lua_insert(L,1); break; case FT_BOOLEAN: --- a/epan/wslua/wslua_tvb.c +++ b/epan/wslua/wslua_tvb.c @@ -135,7 +135,7 @@ /* Obtain the reported length (length on the network) of a <>. */ Tvb tvb = checkTvb(L,1); - lua_pushinteger(L,tvb_reported_length(tvb->ws_tvb)); + WSLUA_PUSHINTEGER(L,tvb_reported_length(tvb->ws_tvb)); WSLUA_RETURN(1); /* The reported length of the <>. */ } @@ -143,7 +143,7 @@ /* Obtain the captured length (amount saved in the capture process) of a <>. */ Tvb tvb = checkTvb(L,1); - lua_pushinteger(L,tvb_captured_length(tvb->ws_tvb)); + WSLUA_PUSHINTEGER(L,tvb_captured_length(tvb->ws_tvb)); WSLUA_RETURN(1); /* The captured length of the <>. */ } @@ -152,7 +152,7 @@ Same as captured_len; kept only for backwards compatibility */ Tvb tvb = checkTvb(L,1); - lua_pushinteger(L,tvb_captured_length(tvb->ws_tvb)); + WSLUA_PUSHINTEGER(L,tvb_captured_length(tvb->ws_tvb)); WSLUA_RETURN(1); /* The captured length of the <>. */ } @@ -163,7 +163,7 @@ Tvb tvb = checkTvb(L,1); int offset = (int) luaL_optinteger(L, Tvb_reported_length_remaining_OFFSET, 0); - lua_pushinteger(L,tvb_reported_length_remaining(tvb->ws_tvb, offset)); + WSLUA_PUSHINTEGER(L,tvb_reported_length_remaining(tvb->ws_tvb, offset)); WSLUA_RETURN(1); /* The captured length of the <>. */ } @@ -210,7 +210,7 @@ /* Returns the raw offset (from the beginning of the source <>) of a sub <>. */ Tvb tvb = checkTvb(L,1); - lua_pushinteger(L,tvb_raw_offset(tvb->ws_tvb)); + WSLUA_PUSHINTEGER(L,tvb_raw_offset(tvb->ws_tvb)); WSLUA_RETURN(1); /* The raw offset of the <>. */ } @@ -441,16 +441,16 @@ switch (tvbr->len) { case 1: - lua_pushinteger(L,tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER(L,tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: - lua_pushinteger(L,tvb_get_ntohs(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER(L,tvb_get_ntohs(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 3: - lua_pushinteger(L,tvb_get_ntoh24(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER(L,tvb_get_ntoh24(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 4: - lua_pushinteger(L,tvb_get_ntohl(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER(L,tvb_get_ntohl(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The unsigned integer value. */ default: luaL_error(L,"TvbRange:uint() does not handle %d byte integers",tvbr->len); @@ -474,16 +474,16 @@ switch (tvbr->len) { case 1: /* XXX unsigned anyway */ - lua_pushinteger(L,(lua_Integer)(guint)tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER_WITH_CAST(L,(guint)tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: - lua_pushinteger(L,tvb_get_letohs(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER(L,tvb_get_letohs(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 3: - lua_pushinteger(L,tvb_get_letoh24(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER(L,tvb_get_letoh24(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 4: - lua_pushinteger(L,tvb_get_letohl(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER(L,tvb_get_letohl(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The unsigned integer value */ default: luaL_error(L,"TvbRange:le_uint() does not handle %d byte integers",tvbr->len); @@ -594,16 +594,16 @@ switch (tvbr->len) { case 1: - lua_pushinteger(L,tvb_get_gint8(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER(L,tvb_get_gint8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: - lua_pushinteger(L,tvb_get_ntohis(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER(L,tvb_get_ntohis(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 3: - lua_pushinteger(L,tvb_get_ntohi24(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER(L,tvb_get_ntohi24(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 4: - lua_pushinteger(L,tvb_get_ntohil(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER(L,tvb_get_ntohil(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The signed integer value. */ /* * XXX: @@ -633,16 +633,16 @@ switch (tvbr->len) { case 1: - lua_pushinteger(L,tvb_get_gint8(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER(L,tvb_get_gint8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: - lua_pushinteger(L,tvb_get_letohis(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER(L,tvb_get_letohis(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 3: - lua_pushinteger(L,tvb_get_letohi24(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER(L,tvb_get_letohi24(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 4: - lua_pushinteger(L,tvb_get_letohil(tvbr->tvb->ws_tvb,tvbr->offset)); + WSLUA_PUSHINTEGER(L,tvb_get_letohil(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The signed integer value. */ default: luaL_error(L,"TvbRange:le_int() does not handle %d byte integers",tvbr->len); @@ -1237,13 +1237,13 @@ } if (len <= 8) { - lua_pushinteger(L,(lua_Integer)(guint)tvb_get_bits8(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len)); + WSLUA_PUSHINTEGER_WITH_CAST(L,(guint)tvb_get_bits8(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len)); return 1; } else if (len <= 16) { - lua_pushinteger(L,tvb_get_bits16(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, FALSE)); + WSLUA_PUSHINTEGER(L,tvb_get_bits16(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, FALSE)); return 1; } else if (len <= 32) { - lua_pushinteger(L,tvb_get_bits32(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, FALSE)); + WSLUA_PUSHINTEGER(L,tvb_get_bits32(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, FALSE)); return 1; } else if (len <= 64) { pushUInt64(L,tvb_get_bits64(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, FALSE)); @@ -1334,7 +1334,7 @@ luaL_error(L,"expired tvb"); return 0; } - lua_pushinteger(L,(lua_Integer)tvbr->len); + WSLUA_PUSHINTEGER_WITH_CAST(L,tvbr->len); return 1; } @@ -1347,7 +1347,7 @@ luaL_error(L,"expired tvb"); return 0; } - lua_pushinteger(L,(lua_Integer)tvbr->offset); + WSLUA_PUSHINTEGER_WITH_CAST(L,tvbr->offset); return 1; } --- a/epan/wslua/wslua_wtap.c +++ b/epan/wslua/wslua_wtap.c @@ -85,7 +85,7 @@ if (filetype == -1) lua_pushnil(LS); else - lua_pushinteger(LS,filetype); + WSLUA_PUSHINTEGER(LS,filetype); WSLUA_RETURN(1); /* The filetype value for the file type with that name, or nil if there is no such file type. */ } @@ -96,7 +96,7 @@ @since 3.2.12, 3.4.4 */ lua_Number filetype = wtap_pcap_file_type_subtype(); - lua_pushinteger(LS,filetype); + WSLUA_PUSHINTEGER(LS,filetype); WSLUA_RETURN(1); /* The filetype value for pcap files. */ } @@ -107,7 +107,7 @@ @since 3.2.12, 3.4.4 */ lua_Number filetype = wtap_pcap_nsec_file_type_subtype(); - lua_pushinteger(LS,filetype); + WSLUA_PUSHINTEGER(LS,filetype); WSLUA_RETURN(1); /* The filetype value for nanosecond-resolution pcap files. */ } @@ -118,7 +118,7 @@ @since 3.2.12, 3.4.4 */ lua_Number filetype = wtap_pcapng_file_type_subtype(); - lua_pushinteger(LS,filetype); + WSLUA_PUSHINTEGER(LS,filetype); WSLUA_RETURN(1); /* The filetype value for pcapng files. */ } @@ -148,7 +148,7 @@ * it. */ lua_pushstring(LS, entry->name); - lua_pushinteger(LS, entry->ft); + WSLUA_PUSHINTEGER(LS, entry->ft); /* * The -3 is the index, relative to the top of the stack, of * the table; the two elements on top of it are the ft and