diff options
author | Luis Ontanon <luis.ontanon@gmail.com> | 2006-02-04 20:00:58 +0000 |
---|---|---|
committer | Luis Ontanon <luis.ontanon@gmail.com> | 2006-02-04 20:00:58 +0000 |
commit | fedb9b5c92e7078e67e669b554e909ed27f733f5 (patch) | |
tree | be2540ba3ebceddcb040363b00b13d1136b0f3ad /plugins | |
parent | e487660dfce79cc3b96e6dcfda7164f56c1e8c7d (diff) |
Give lua a minimal gui.
svn path=/trunk/; revision=17150
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/lua/Makefile.am | 1 | ||||
-rw-r--r-- | plugins/lua/lua_gui.c | 125 | ||||
-rw-r--r-- | plugins/lua/lua_tvb.c | 2 | ||||
-rw-r--r-- | plugins/lua/packet-lua.c | 15 | ||||
-rw-r--r-- | plugins/lua/packet-lua.h | 8 |
5 files changed, 150 insertions, 1 deletions
diff --git a/plugins/lua/Makefile.am b/plugins/lua/Makefile.am index 1e3bde5c4a..b92001f012 100644 --- a/plugins/lua/Makefile.am +++ b/plugins/lua/Makefile.am @@ -33,6 +33,7 @@ lua_la_SOURCES = \ lua_tree.c \ lua_pinfo.c \ lua_tap.c \ + lua_gui.c \ packet-lua.c \ packet-lua.h \ plugin.c diff --git a/plugins/lua/lua_gui.c b/plugins/lua/lua_gui.c new file mode 100644 index 0000000000..d97802a028 --- /dev/null +++ b/plugins/lua/lua_gui.c @@ -0,0 +1,125 @@ +/* + * lua_gui.c + * + * + * Created by L. E. G. O. on 2006/02/04. + * Copyright 2006 __MyCompanyName__. All rights reserved. + * + */ + +#include "packet-lua.h" + +LUA_CLASS_DEFINE(TextWindow,TEXT_WINDOW,NOP) + +static const funnel_ops_t* ops = NULL; + +static int TextWindow_new(lua_State* L) { + const gchar* title; + TextWindow tw; + + if (!ops) { + luaL_error(L,"GUI system not available"); + return 0; + } + + title = luaL_optstring(L,1,"Untitled Window"); + tw = ops->new_text_window(title); + pushTextWindow(L,tw); + + return 1; +} + +static int TextWindow_set_text(lua_State* L) { + TextWindow tw = shiftTextWindow(L,1); + const gchar* text = luaL_checkstring(L,1); + + if (!text) return 0; + + ops->set_text(tw,text); + + pushTextWindow(L,tw); + return 1; +} + +static int TextWindow_append_text(lua_State* L) { + TextWindow tw = shiftTextWindow(L,1); + const gchar* text = luaL_checkstring(L,1); + + if (!text) return 0; + + ops->append_text(tw,text); + + pushTextWindow(L,tw); + return 1; +} + +static int TextWindow_prepend_text(lua_State* L) { + TextWindow tw = shiftTextWindow(L,1); + const gchar* text = luaL_checkstring(L,1); + + if (!text) return 0; + + ops->prepend_text(tw,text); + + pushTextWindow(L,tw); + return 1; +} + +static int TextWindow_clear_text(lua_State* L) { + TextWindow tw = shiftTextWindow(L,1); + + ops->clear_text(tw); + + pushTextWindow(L,tw); + return 1; +} + +static int TextWindow_get_text(lua_State* L) { + TextWindow tw = shiftTextWindow(L,1); + const gchar* text = ops->get_text(tw); + + lua_pushstring(L,text); + return 1; +} + +static int TextWindow_gc(lua_State* L) { + TextWindow tw = shiftTextWindow(L,1); + + ops->destroy_text_window(tw); + return 1; +} + + +static const luaL_reg TextWindow_methods[] = { + {"new", TextWindow_new}, + {"set", TextWindow_set_text}, + {"append", TextWindow_append_text}, + {"prepend", TextWindow_prepend_text}, + {"clear", TextWindow_clear_text}, + {0, 0} +}; + +static const luaL_reg TextWindow_meta[] = { + {"__tostring", TextWindow_get_text}, + {"__GC", TextWindow_gc}, + {0, 0} +}; + +int TextWindow_register(lua_State* L) { + + ops = funnel_get_funnel_ops(); + + luaL_openlib(L, TEXT_WINDOW, TextWindow_methods, 0); + luaL_newmetatable(L, TEXT_WINDOW); + luaL_openlib(L, 0, TextWindow_meta, 0); + lua_pushliteral(L, "__index"); + lua_pushvalue(L, -3); + lua_rawset(L, -3); + lua_pushliteral(L, "__metatable"); + lua_pushvalue(L, -3); + lua_rawset(L, -3); + lua_pop(L, 1); + + return 1; +} + diff --git a/plugins/lua/lua_tvb.c b/plugins/lua/lua_tvb.c index b8432ca57b..7d3abb60c1 100644 --- a/plugins/lua/lua_tvb.c +++ b/plugins/lua/lua_tvb.c @@ -239,7 +239,7 @@ static int ByteArray_tostring(lua_State* L) { static int Tvb_new_real (lua_State *L); static const luaL_reg ByteArray_methods[] = { - {"new", ByteArray_new}, + {"new", ByteArray_new}, {"len", ByteArray_len}, {"prepend", ByteArray_prepend}, {"append", ByteArray_append}, diff --git a/plugins/lua/packet-lua.c b/plugins/lua/packet-lua.c index 199075c31e..bf84124a2d 100644 --- a/plugins/lua/packet-lua.c +++ b/plugins/lua/packet-lua.c @@ -39,6 +39,18 @@ tvbuff_t* lua_tvb; int lua_malformed; dissector_handle_t lua_data_handle; + +const gchar* lua_shiftstring(lua_State* L, int i) { + const gchar* p = luaL_checkstring(L, i); + + if (p) { + lua_remove(L,i); + return p; + } else { + return NULL; + } +} + static int lua_format_date(lua_State* LS) { lua_Number time = luaL_checknumber(LS,1); nstime_t then; @@ -292,6 +304,9 @@ static int init_error_handler(lua_State* L) { static void init_lua(void) { if ( ! lua_initialized ) { + + TextWindow_register(L); + GString* tap_error = lua_register_all_taps(); if ( tap_error ) { diff --git a/plugins/lua/packet-lua.h b/plugins/lua/packet-lua.h index 4b1896b8a3..ce071f1dd0 100644 --- a/plugins/lua/packet-lua.h +++ b/plugins/lua/packet-lua.h @@ -47,6 +47,7 @@ #include <epan/filesystem.h> #include <epan/report_err.h> #include <epan/emem.h> +#include <epan/funnel.h> #define LUA_DISSECTORS_TABLE "dissectors" #define LUA_INIT_ROUTINES "init_routines" @@ -166,6 +167,9 @@ typedef struct _eth_tap { gboolean registered; }* Tap; +#define TEXT_WINDOW "TextWindow" +typedef funnel_text_window_t* TextWindow; + #define NOP /* @@ -242,12 +246,16 @@ LUA_CLASS_DECLARE(ProtoItem,ITEM); LUA_CLASS_DECLARE(Dissector,DISSECTOR); LUA_CLASS_DECLARE(DissectorTable,DISSECTOR_TABLE); LUA_CLASS_DECLARE(Address,ADDRESS); +LUA_CLASS_DECLARE(TextWindow,TEXT_WINDOW); extern void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree); extern int lua_tap_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const void *data _U_); extern void lua_tap_reset(void *tapdata); extern void lua_tap_draw(void *tapdata); +extern const gchar* lua_shiftstring(lua_State* L,int idx); + + extern GString* lua_register_all_taps(void); extern void lua_prime_all_fields(proto_tree* tree); void lua_register_subtrees(void); |