LUA API improvements
1. Add col_set_fence() equivalent 2. Update __tostring function to actually return column text From Hadriel Kaplan, bug 8295 (https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8295) svn path=/trunk/; revision=47882
This commit is contained in:
parent
8692843ee3
commit
41bd69d601
|
@ -165,6 +165,26 @@ col_set_fence(column_info *cinfo, const gint el)
|
|||
}
|
||||
}
|
||||
|
||||
/* Gets the text of a column */
|
||||
const gchar *
|
||||
col_get_text(column_info *cinfo, const gint el)
|
||||
{
|
||||
int i;
|
||||
const gchar* text = NULL;
|
||||
|
||||
if (!(cinfo && (cinfo)->col_first[el] >= 0)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
|
||||
if (cinfo->fmt_matx[i][el]) {
|
||||
text = (cinfo->col_data[i]);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
/* Use this to clear out a column, especially if you're going to be
|
||||
appending to it later; at least on some platforms, it's more
|
||||
efficient than using "col_add_str()" with a null string, and
|
||||
|
|
|
@ -117,6 +117,15 @@ extern gint check_col(column_info *cinfo, const gint col);
|
|||
*/
|
||||
extern void col_set_fence(column_info *cinfo, const gint col);
|
||||
|
||||
/** Gets the text of a column element.
|
||||
*
|
||||
* @param cinfo the current packet row
|
||||
* @param col the column to use, e.g. COL_INFO
|
||||
*
|
||||
* @return the text string
|
||||
*/
|
||||
extern const gchar *col_get_text(column_info *cinfo, const gint col);
|
||||
|
||||
/** Clears the text of a column element.
|
||||
*
|
||||
* @param cinfo the current packet row
|
||||
|
|
|
@ -604,17 +604,21 @@ static const gchar* col_id_to_name(gint id) {
|
|||
|
||||
WSLUA_METAMETHOD Column__tostring(lua_State *L) {
|
||||
Column c = checkColumn(L,1);
|
||||
const gchar* name;
|
||||
const gchar* text;
|
||||
|
||||
if (!(c)) {
|
||||
return 0;
|
||||
if (!c) {
|
||||
lua_pushstring(L,"(nil)");
|
||||
}
|
||||
else if (!c->cinfo) {
|
||||
text = col_id_to_name(c->col);
|
||||
lua_pushfstring(L, "(%s)", text ? text : "unknown");
|
||||
}
|
||||
else {
|
||||
text = col_get_text(c->cinfo, c->col);
|
||||
lua_pushstring(L, text ? text : "(nil)");
|
||||
}
|
||||
|
||||
/* XXX: should return the column's text ! */
|
||||
name = col_id_to_name(c->col);
|
||||
lua_pushstring(L,name ? name : "Unknown Column");
|
||||
|
||||
WSLUA_RETURN(1); /* A string representing the column */
|
||||
WSLUA_RETURN(1); /* The column's string text (in parenthesis if not available) */
|
||||
}
|
||||
|
||||
static int Column__gc(lua_State* L) {
|
||||
|
@ -691,12 +695,24 @@ WSLUA_METHOD Column_prepend(lua_State *L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
WSLUA_METHOD Column_fence(lua_State *L) {
|
||||
/* Sets Column text fence, to prevent overwriting */
|
||||
Column c = checkColumn(L,1);
|
||||
|
||||
if (c && c->cinfo)
|
||||
col_set_fence(c->cinfo, c->col);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
WSLUA_METHODS Column_methods[] = {
|
||||
WSLUA_CLASS_FNREG(Column,clear),
|
||||
WSLUA_CLASS_FNREG(Column,set),
|
||||
WSLUA_CLASS_FNREG(Column,append),
|
||||
WSLUA_CLASS_FNREG(Column,prepend),
|
||||
WSLUA_CLASS_FNREG_ALIAS(Column,preppend,prepend),
|
||||
WSLUA_CLASS_FNREG(Column,fence),
|
||||
{0,0}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue