aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/lua
diff options
context:
space:
mode:
authorLuis Ontanon <luis.ontanon@gmail.com>2006-02-27 01:54:22 +0000
committerLuis Ontanon <luis.ontanon@gmail.com>2006-02-27 01:54:22 +0000
commit8b84860a235a83653800f62de76b6d32da94a14e (patch)
tree6eacd9cab1448e89e657abd24772e6395afd6860 /plugins/lua
parenta39ec4c80d881bcfe11d1822908372c766d018f9 (diff)
- Some more comments
svn path=/trunk/; revision=17415
Diffstat (limited to 'plugins/lua')
-rw-r--r--plugins/lua/elua.h2
-rw-r--r--plugins/lua/elua_tap.c40
2 files changed, 23 insertions, 19 deletions
diff --git a/plugins/lua/elua.h b/plugins/lua/elua.h
index 4ed6e6bbb7..23b215bcac 100644
--- a/plugins/lua/elua.h
+++ b/plugins/lua/elua.h
@@ -164,7 +164,7 @@ C* push##C(lua_State* L, C v) { \
}\
gboolean is##C(lua_State* L,int i) { \
void *p; \
- if(lua_isuserdata(L,i)) return FALSE; \
+ if(!lua_isuserdata(L,i)) return FALSE; \
p = lua_touserdata(L, i); \
lua_getfield(L, LUA_REGISTRYINDEX, #C); \
if (p == NULL || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p=NULL; \
diff --git a/plugins/lua/elua_tap.c b/plugins/lua/elua_tap.c
index de4a0934fc..add0179ede 100644
--- a/plugins/lua/elua_tap.c
+++ b/plugins/lua/elua_tap.c
@@ -29,6 +29,9 @@
#include "elua.h"
ELUA_CLASS_DEFINE(Field,NOP)
+/*
+ A Field extractor to to obtain field values.
+ */
static GPtrArray* wanted_fields = NULL;
@@ -85,16 +88,21 @@ void lua_prime_all_fields(proto_tree* tree _U_) {
}
-static int Field_get (lua_State *L) {
- const gchar* name = luaL_checkstring(L,1);
+ELUA_FUNCTION new_field(lua_State *L) {
+ /*
+ Create a Field extractor
+ */
+#define ELUA_ARG_Field_get_FIELDNAME 1 /* The filter name of the field (e.g. ip.addr) */
+ const gchar* name = luaL_checkstring(L,ELUA_ARG_Field_get_FIELDNAME);
Field f;
if (!name) return 0;
- if (!wanted_fields) {
- luaL_error(L,"too late to define a Field extractor");
- return 0;
- }
+ if (!proto_registrar_get_byname(name))
+ ELUA_ARG_ERROR(Field_get,FIELDNAME,"a field with this name must exist");
+
+ if (!wanted_fields)
+ ELUA_ERROR(Field_get,"a Field extractor must be defined before Taps or Dissectors get called");
f = g_malloc(sizeof(void*));
*f = (header_field_info*)g_strdup(name); /* cheating */
@@ -102,10 +110,10 @@ static int Field_get (lua_State *L) {
g_ptr_array_add(wanted_fields,f);
pushField(L,f);
- return 1;
+ ELUA_RETURN(1); /* The field extractor */
}
-static int Field_fetch (lua_State* L) {
+ELUA_METAMETHOD Field__call (lua_State* L) {
Field f = checkField(L,1);
int items_found = 0;
header_field_info* in = *f;
@@ -116,8 +124,7 @@ static int Field_fetch (lua_State* L) {
}
if (! lua_pinfo ) {
- g_warning("pinfo: %p",lua_pinfo);
- luaL_error(L,"fields cannot be used outside dissectors or taps");
+ ELUA_ERROR(Field__call,"fields cannot be used outside dissectors or taps");
return 0;
}
@@ -169,8 +176,7 @@ static int Field_fetch (lua_State* L) {
}
}
}
- return items_found;
-
+ ELUA_RETURN(items_found); /* All the values of this field */
}
static int Field_tostring(lua_State* L) {
@@ -192,7 +198,7 @@ static int Field_tostring(lua_State* L) {
static const luaL_reg Field_meta[] = {
{"__tostring", Field_tostring},
- {"__call", Field_fetch},
+ {"__call", Field__call},
{0, 0}
};
@@ -202,17 +208,15 @@ int Field_register(lua_State* L) {
ELUA_REGISTER_META(Field);
- lua_pushstring(L, "Field");
- lua_pushcfunction(L, Field_get);
- lua_settable(L, LUA_GLOBALSINDEX);
-
return 1;
}
ELUA_CLASS_DEFINE(Tap,NOP)
-
+/*
+
+ */
struct _eth_tap {
gchar* name;
gchar* filter;