diff options
author | Jeff Morriss <jeff.morriss@ulticom.com> | 2010-10-21 02:50:27 +0000 |
---|---|---|
committer | Jeff Morriss <jeff.morriss@ulticom.com> | 2010-10-21 02:50:27 +0000 |
commit | 383df3dfe58cc5624d3cd401244ce09c9934e745 (patch) | |
tree | a46cec41aa5d5c09a2cac48359fc790c04f4a786 /epan/wslua/wslua_gui.c | |
parent | f3648fc66db36719b5bf4cc4a35ac45326153d20 (diff) |
Make the indentation consistent.
Pull function names to column 0 - except when necessary for autoregistration.
Put function comments before the function.
For readability, put the macros for functions before the function too.
Put class functions before the class.
svn path=/trunk/; revision=34599
Diffstat (limited to 'epan/wslua/wslua_gui.c')
-rw-r--r-- | epan/wslua/wslua_gui.c | 696 |
1 files changed, 390 insertions, 306 deletions
diff --git a/epan/wslua/wslua_gui.c b/epan/wslua/wslua_gui.c index a66373cc2c..577d352be7 100644 --- a/epan/wslua/wslua_gui.c +++ b/epan/wslua/wslua_gui.c @@ -35,73 +35,96 @@ struct _lua_menu_data { int cb_ref; }; -static int menu_cb_error_handler(lua_State* L) { +static int +menu_cb_error_handler(lua_State* L) +{ const gchar* error = lua_tostring(L,1); report_failure("Lua: Error During execution of Menu Callback:\n %s",error); return 0; } -WSLUA_FUNCTION wslua_gui_enabled(lua_State* L) { /* Checks whether the GUI facility is enabled. */ +/* Checks whether the GUI facility is enabled. */ +WSLUA_FUNCTION wslua_gui_enabled(lua_State* L) +{ lua_pushboolean(L,GPOINTER_TO_INT(ops && ops->add_button)); WSLUA_RETURN(1); /* A boolean: true if it is enabled, false if it isn't. */ } -static void lua_menu_callback(gpointer data) { +static void +lua_menu_callback(gpointer data) +{ struct _lua_menu_data* md = data; - lua_State* L = md->L; + lua_State* L = md->L; - lua_settop(L,0); + lua_settop(L,0); lua_pushcfunction(L,menu_cb_error_handler); lua_rawgeti(L, LUA_REGISTRYINDEX, md->cb_ref); - switch ( lua_pcall(L,0,0,1) ) { - case 0: - break; - case LUA_ERRRUN: - g_warning("Runtime error while calling menu callback"); - break; - case LUA_ERRMEM: - g_warning("Memory alloc error while calling menu callback"); - break; - default: - g_assert_not_reached(); - break; + switch ( lua_pcall(L,0,0,1) ) { + case 0: + break; + case LUA_ERRRUN: + g_warning("Runtime error while calling menu callback"); + break; + case LUA_ERRMEM: + g_warning("Memory alloc error while calling menu callback"); + break; + default: + g_assert_not_reached(); + break; } return; } -WSLUA_FUNCTION wslua_register_menu(lua_State* L) { /* Register a menu item in one of the main menus. */ -#define WSLUA_ARG_register_menu_NAME 1 /* The name of the menu item. The submenus are to be separated by '/'s. (string) */ -#define WSLUA_ARG_register_menu_ACTION 2 /* The function to be called when the menu item is invoked. (function taking no arguments and returning nothing) */ -#define WSLUA_OPTARG_register_menu_GROUP 3 /* The menu group into which the menu item is to be inserted. If omitted, defaults to MENU_STAT_GENERIC. One of MENU_STAT_UNSORTED (Statistics), MENU_STAT_GENERIC (Statistics, first section), MENU_STAT_CONVERSATION (Statistics/Conversation List), MENU_STAT_ENDPOINT (Statistics/Endpoint List), MENU_STAT_RESPONSE (Statistics/Service Response Time), MENU_STAT_TELEPHONY (Telephony), MENU_ANALYZE (Analyze), MENU_ANALYZE_CONVERSATION (Analyze/Conversation Filter), MENU_TOOLS_UNSORTED (Tools). (number) */ +/* Register a menu item in one of the main menus. */ + +/* The name of the menu item. The submenus are to be separated by '/'s. + * (string) + */ +#define WSLUA_ARG_register_menu_NAME 1 +/* The function to be called when the menu item is invoked. (function taking + * no arguments and returning nothing) + */ +#define WSLUA_ARG_register_menu_ACTION 2 +/* The menu group into which the menu item is to be inserted. If omitted, + * defaults to MENU_STAT_GENERIC. One of: + * - MENU_STAT_UNSORTED (Statistics) + * - MENU_STAT_GENERIC (Statistics, first section) + * - MENU_STAT_CONVERSATION (Statistics/Conversation List) + * - MENU_STAT_ENDPOINT (Statistics/Endpoint List) + * - MENU_STAT_RESPONSE (Statistics/Service Response Time) + * - MENU_STAT_TELEPHONY (Telephony), MENU_ANALYZE (Analyze) + * - MENU_ANALYZE_CONVERSATION (Analyze/Conversation Filter) + * - MENU_TOOLS_UNSORTED (Tools). + * (number) + */ +#define WSLUA_OPTARG_register_menu_GROUP 3 +WSLUA_FUNCTION wslua_register_menu(lua_State* L) +{ const gchar* name = luaL_checkstring(L,WSLUA_ARG_register_menu_NAME); struct _lua_menu_data* md; gboolean retap = FALSE; - register_stat_group_t group = (int)luaL_optnumber(L,WSLUA_OPTARG_register_menu_GROUP,REGISTER_STAT_GROUP_GENERIC); + register_stat_group_t group = (int)luaL_optnumber(L, WSLUA_OPTARG_register_menu_GROUP, REGISTER_STAT_GROUP_GENERIC); - if ( group > REGISTER_TOOLS_GROUP_UNSORTED) - WSLUA_OPTARG_ERROR(register_menu,GROUP,"Must be a defined MENU_* (see init.lua)"); + if ( group > REGISTER_TOOLS_GROUP_UNSORTED) + WSLUA_OPTARG_ERROR(register_menu,GROUP, "Must be a defined MENU_* (see init.lua)"); - if(!name) - WSLUA_ARG_ERROR(register_menu,NAME,"Must be a string"); + if(!name) + WSLUA_ARG_ERROR(register_menu,NAME,"Must be a string"); if (!lua_isfunction(L,WSLUA_ARG_register_menu_ACTION)) - WSLUA_ARG_ERROR(register_menu,ACTION,"Must be a function"); + WSLUA_ARG_ERROR(register_menu,ACTION,"Must be a function"); md = g_malloc(sizeof(struct _lua_menu_data)); md->L = L; - lua_pushvalue(L, 2); - md->cb_ref = luaL_ref(L, LUA_REGISTRYINDEX); - lua_remove(L,2); + lua_pushvalue(L, 2); + md->cb_ref = luaL_ref(L, LUA_REGISTRYINDEX); + lua_remove(L,2); - funnel_register_menu(name, - group, - lua_menu_callback, - md, - retap); + funnel_register_menu(name, group, lua_menu_callback, md, retap); WSLUA_RETURN(0); } @@ -114,13 +137,17 @@ struct _dlg_cb_data { int func_ref; }; -static int dlg_cb_error_handler(lua_State* L) { +static int +dlg_cb_error_handler(lua_State* L) +{ const gchar* error = lua_tostring(L,1); report_failure("Lua: Error During execution of dialog callback:\n %s",error); return 0; } -static void lua_dialog_cb(gchar** user_input, void* data) { +static void +lua_dialog_cb(gchar** user_input, void* data) +{ struct _dlg_cb_data* dcbd = data; int i = 0; gchar* input; @@ -160,18 +187,22 @@ struct _close_cb_data { }; -static int text_win_close_cb_error_handler(lua_State* L) { +static int +text_win_close_cb_error_handler(lua_State* L) +{ const gchar* error = lua_tostring(L,1); report_failure("Lua: Error During execution of TextWindow close callback:\n %s",error); return 0; } -static void text_win_close_cb(void* data) { +static void +text_win_close_cb(void* data) +{ struct _close_cb_data* cbd = data; lua_State* L = cbd->L; if (cbd->L) { /* close function is set */ - + lua_settop(L,0); lua_pushcfunction(L,text_win_close_cb_error_handler); lua_rawgeti(L, LUA_REGISTRYINDEX, cbd->func_ref); @@ -189,7 +220,7 @@ static void text_win_close_cb(void* data) { break; } } - + if (cbd->wslua_tw->expired) { g_free(cbd->wslua_tw); } else { @@ -198,11 +229,12 @@ static void text_win_close_cb(void* data) { } -WSLUA_FUNCTION wslua_new_dialog(lua_State* L) { /* Pops up a new dialog */ +/* Pops up a new dialog */ #define WSLUA_ARG_new_dialog_TITLE 1 /* Title of the dialog's window. */ #define WSLUA_ARG_new_dialog_ACTION 2 /* Action to be performed when OKd. */ /* WSLUA_MOREARGS new_dialog A series of strings to be used as labels of the dialog's fields */ - +WSLUA_FUNCTION wslua_new_dialog(lua_State* L) +{ const gchar* title; int top = lua_gettop(L); int i; @@ -246,9 +278,9 @@ WSLUA_FUNCTION wslua_new_dialog(lua_State* L) { /* Pops up a new dialog */ for (i = 1; i <= top; i++) { gchar* label = (void*)luaL_checkstring(L,i); - /* XXX leaks labels on error */ - if (! label) - WSLUA_ERROR(new_dialog,"All fields must be strings"); + /* XXX leaks labels on error */ + if (! label) + WSLUA_ERROR(new_dialog,"All fields must be strings"); g_ptr_array_add(labels,label); } @@ -266,98 +298,114 @@ WSLUA_FUNCTION wslua_new_dialog(lua_State* L) { /* Pops up a new dialog */ WSLUA_CLASS_DEFINE(ProgDlg,NOP,NOP); /* Manages a progress bar dialog. */ -WSLUA_CONSTRUCTOR ProgDlg_new(lua_State* L) { /* Creates a new TextWindow. */ +/* Creates a new TextWindow. */ #define WSLUA_OPTARG_ProgDlg_new_TITLE 2 /* Title of the new window, defaults to "Progress". */ #define WSLUA_OPTARG_ProgDlg_new_TASK 3 /* Current task, defaults to "". */ +WSLUA_CONSTRUCTOR +ProgDlg_new(lua_State* L) +{ ProgDlg pd = g_malloc(sizeof(struct _wslua_progdlg)); - pd->title = g_strdup(luaL_optstring(L,WSLUA_OPTARG_ProgDlg_new_TITLE,"Progress")); - pd->task = g_strdup(luaL_optstring(L,WSLUA_OPTARG_ProgDlg_new_TASK,"")); + pd->title = g_strdup(luaL_optstring(L, WSLUA_OPTARG_ProgDlg_new_TITLE, "Progress")); + pd->task = g_strdup(luaL_optstring(L, WSLUA_OPTARG_ProgDlg_new_TASK, "")); pd->stopped = FALSE; - + if (ops->new_progress_window) { pd->pw = ops->new_progress_window(pd->title,pd->task,TRUE,&(pd->stopped)); } - + pushProgDlg(L,pd); - - WSLUA_RETURN(1); /* The newly created TextWindow object. */ + + WSLUA_RETURN(1); /* The newly created TextWindow object. */ } -WSLUA_METHOD ProgDlg_update(lua_State* L) { /* Appends text */ +/* Appends text */ #define WSLUA_ARG_ProgDlg_update_PROGRESS 2 /* Part done ( e.g. 0.75 ). */ #define WSLUA_OPTARG_ProgDlg_update_TASK 3 /* Current task, defaults to "". */ - ProgDlg pd = checkProgDlg(L,1); - double pr = lua_tonumber(L,WSLUA_ARG_ProgDlg_update_PROGRESS); - const gchar* task = luaL_optstring(L,WSLUA_OPTARG_ProgDlg_update_TASK,""); - +WSLUA_METHOD +ProgDlg_update(lua_State* L) +{ + ProgDlg pd = checkProgDlg(L, 1); + double pr = lua_tonumber(L, WSLUA_ARG_ProgDlg_update_PROGRESS); + const gchar* task = luaL_optstring(L, WSLUA_OPTARG_ProgDlg_update_TASK, ""); + g_free(pd->task); pd->task = g_strdup(task); - if (!pd) { - WSLUA_ERROR(ProgDlg_update,"Cannot be called for something not a ProgDlg"); + if (!pd) { + WSLUA_ERROR(ProgDlg_update, "Cannot be called for something not a ProgDlg"); } - + if (pr >= 0.0 || pr <= 1.0) { ops->update_progress(pd->pw, (float) pr, task); } else { - WSLUA_ERROR(ProgDlg_update,"Progress value out of range (must be between 0.0 and 1.0)"); + WSLUA_ERROR(ProgDlg_update, "Progress value out of range (must be between 0.0 and 1.0)"); } - + return 0; } -WSLUA_METHOD ProgDlg_stopped(lua_State* L) { /* Checks wheher the user has pressed the stop button. */ +/* Checks wheher the user has pressed the stop button. */ +WSLUA_METHOD +ProgDlg_stopped(lua_State* L) +{ ProgDlg pd = checkProgDlg(L,1); - - if (!pd) { - WSLUA_ERROR(ProgDlg_stopped,"Cannot be called for something not a ProgDlg"); + + if (!pd) { + WSLUA_ERROR(ProgDlg_stopped,"Cannot be called for something not a ProgDlg"); } - + lua_pushboolean(L,pd->stopped); - - WSLUA_RETURN(1); /* true if the user has asked to stop the progress. */ -} + WSLUA_RETURN(1); /* true if the user has asked to stop the progress. */ +} -WSLUA_METHOD ProgDlg_close(lua_State* L) { /* Appends text */ +/* Appends text */ +WSLUA_METHOD +ProgDlg_close(lua_State* L) +{ ProgDlg pd = checkProgDlg(L,1); - - if (!pd) { - WSLUA_ERROR(ProgDlg_update,"Cannot be called for something not a ProgDlg"); + + if (!pd) { + WSLUA_ERROR(ProgDlg_update,"Cannot be called for something not a ProgDlg"); } if (pd->pw) { ops->destroy_progress_window(pd->pw); pd->pw = NULL; } + return 0; } -static int ProgDlg__tostring(lua_State* L) { +static int +ProgDlg__tostring(lua_State* L) +{ ProgDlg pd = checkProgDlg(L,1); - + if (pd) { lua_pushstring(L,ep_strdup_printf("%sstopped",pd->stopped?"":"not ")); } else { luaL_error(L, "ProgDlg__tostring has being passed something else!"); } - + return 0; } -static int ProgDlg__gc(lua_State* L) { +static int +ProgDlg__gc(lua_State* L) +{ ProgDlg pd = checkProgDlg(L,1); - + if (pd) { if (pd->pw) ops->destroy_progress_window(pd->pw); - + g_free(pd); } else { luaL_error(L, "ProgDlg__gc has being passed something else!"); } - + return 0; } @@ -376,12 +424,13 @@ WSLUA_META ProgDlg_meta[] = { {0, 0} }; -int ProgDlg_register(lua_State* L) { - +int +ProgDlg_register(lua_State* L) +{ ops = funnel_get_funnel_ops(); - - WSLUA_REGISTER_CLASS(ProgDlg); - + + WSLUA_REGISTER_CLASS(ProgDlg); + return 1; } @@ -390,12 +439,14 @@ int ProgDlg_register(lua_State* L) { WSLUA_CLASS_DEFINE(TextWindow,NOP,NOP); /* Manages a text window. */ /* XXX: button and close callback data is being leaked */ -/* XXX: lua callback function and TextWindow are not garbage collected because +/* XXX: lua callback function and TextWindow are not garbage collected because they stay in LUA_REGISTRYINDEX forever */ -WSLUA_CONSTRUCTOR TextWindow_new(lua_State* L) { /* Creates a new TextWindow. */ +/* Creates a new TextWindow. */ #define WSLUA_OPTARG_TextWindow_new_TITLE 1 /* Title of the new window. */ - +WSLUA_CONSTRUCTOR +TextWindow_new(lua_State* L) +{ const gchar* title; TextWindow tw = NULL; struct _close_cb_data* default_cbd; @@ -404,7 +455,7 @@ WSLUA_CONSTRUCTOR TextWindow_new(lua_State* L) { /* Creates a new TextWindow. */ tw = g_malloc(sizeof(struct _wslua_tw)); tw->expired = FALSE; tw->ws_tw = ops->new_text_window(title); - + default_cbd = g_malloc(sizeof(struct _close_cb_data)); default_cbd->L = NULL; @@ -415,17 +466,19 @@ WSLUA_CONSTRUCTOR TextWindow_new(lua_State* L) { /* Creates a new TextWindow. */ pushTextWindow(L,tw); - WSLUA_RETURN(1); /* The newly created TextWindow object. */ + WSLUA_RETURN(1); /* The newly created TextWindow object. */ } -WSLUA_METHOD TextWindow_set_atclose(lua_State* L) { /* Set the function that will be called when the window closes */ +/* Set the function that will be called when the window closes */ #define WSLUA_ARG_TextWindow_at_close_ACTION 2 /* A function to be executed when the user closes the window */ - +WSLUA_METHOD +TextWindow_set_atclose(lua_State* L) +{ TextWindow tw = checkTextWindow(L,1); struct _close_cb_data* cbd; - if (!tw) - WSLUA_ERROR(TextWindow_at_close,"Cannot be called for something not a TextWindow"); + if (!tw) + WSLUA_ERROR(TextWindow_at_close,"Cannot be called for something not a TextWindow"); lua_settop(L,2); @@ -440,130 +493,147 @@ WSLUA_METHOD TextWindow_set_atclose(lua_State* L) { /* Set the function that wil ops->set_close_cb(tw->ws_tw,text_win_close_cb,cbd); - WSLUA_RETURN(1); /* The TextWindow object. */ + WSLUA_RETURN(1); /* The TextWindow object. */ } -WSLUA_METHOD TextWindow_set(lua_State* L) { /* Sets the text. */ +/* Sets the text. */ #define WSLUA_ARG_TextWindow_set_TEXT 2 /* The text to be used. */ - +WSLUA_METHOD +TextWindow_set(lua_State* L) +{ TextWindow tw = checkTextWindow(L,1); const gchar* text = luaL_checkstring(L,WSLUA_ARG_TextWindow_set_TEXT); - if (!tw) - WSLUA_ERROR(TextWindow_set,"Cannot be called for something not a TextWindow"); + if (!tw) + WSLUA_ERROR(TextWindow_set,"Cannot be called for something not a TextWindow"); if (tw->expired) - WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); - + WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); + if (!text) - WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Must be a string"); + WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Must be a string"); ops->set_text(tw->ws_tw,text); - WSLUA_RETURN(1); /* The TextWindow object. */ + WSLUA_RETURN(1); /* The TextWindow object. */ } -WSLUA_METHOD TextWindow_append(lua_State* L) { /* Appends text */ +/* Appends text */ #define WSLUA_ARG_TextWindow_append_TEXT 2 /* The text to be appended */ +WSLUA_METHOD +TextWindow_append(lua_State* L) +{ TextWindow tw = checkTextWindow(L,1); const gchar* text = luaL_checkstring(L,WSLUA_ARG_TextWindow_append_TEXT); - if (!tw) - WSLUA_ERROR(TextWindow_append,"Cannot be called for something not a TextWindow"); + if (!tw) + WSLUA_ERROR(TextWindow_append,"Cannot be called for something not a TextWindow"); if (tw->expired) - WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); - - if (!text) - WSLUA_ARG_ERROR(TextWindow_append,TEXT,"Must be a string"); + WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); + + if (!text) + WSLUA_ARG_ERROR(TextWindow_append,TEXT,"Must be a string"); ops->append_text(tw->ws_tw,text); - WSLUA_RETURN(1); /* The TextWindow object. */ + WSLUA_RETURN(1); /* The TextWindow object. */ } -WSLUA_METHOD TextWindow_prepend(lua_State* L) { /* Prepends text */ +/* Prepends text */ #define WSLUA_ARG_TextWindow_prepend_TEXT 2 /* The text to be appended */ +WSLUA_METHOD +TextWindow_prepend(lua_State* L) +{ TextWindow tw = checkTextWindow(L,1); const gchar* text = luaL_checkstring(L,WSLUA_ARG_TextWindow_prepend_TEXT); - if (!tw) - WSLUA_ERROR(TextWindow_prepend,"Cannot be called for something not a TextWindow"); + if (!tw) + WSLUA_ERROR(TextWindow_prepend,"Cannot be called for something not a TextWindow"); if (tw->expired) - WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); - - if (!text) - WSLUA_ARG_ERROR(TextWindow_prepend,TEXT,"Must be a string"); + WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); + + if (!text) + WSLUA_ARG_ERROR(TextWindow_prepend,TEXT,"Must be a string"); ops->prepend_text(tw->ws_tw,text); - WSLUA_RETURN(1); /* The TextWindow object. */ + WSLUA_RETURN(1); /* The TextWindow object. */ } -WSLUA_METHOD TextWindow_clear(lua_State* L) { /* Erases all text in the window. */ +/* Erases all text in the window. */ +WSLUA_METHOD +TextWindow_clear(lua_State* L) +{ TextWindow tw = checkTextWindow(L,1); - if (!tw) - WSLUA_ERROR(TextWindow_clear,"Cannot be called for something not a TextWindow"); + if (!tw) + WSLUA_ERROR(TextWindow_clear,"Cannot be called for something not a TextWindow"); if (tw->expired) - WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); - + WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); + ops->clear_text(tw->ws_tw); - WSLUA_RETURN(1); /* The TextWindow object. */ + WSLUA_RETURN(1); /* The TextWindow object. */ } -WSLUA_METHOD TextWindow_get_text(lua_State* L) { /* Get the text of the window */ +/* Get the text of the window */ +WSLUA_METHOD +TextWindow_get_text(lua_State* L) +{ TextWindow tw = checkTextWindow(L,1); - const gchar* text; + const gchar* text; - if (!tw) - WSLUA_ERROR(TextWindow_get_text,"Cannot be called for something not a TextWindow"); + if (!tw) + WSLUA_ERROR(TextWindow_get_text,"Cannot be called for something not a TextWindow"); if (tw->expired) - WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); - - text = ops->get_text(tw->ws_tw); + WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); + + text = ops->get_text(tw->ws_tw); lua_pushstring(L,text); - WSLUA_RETURN(1); /* The TextWindow's text. */ + WSLUA_RETURN(1); /* The TextWindow's text. */ } -static int TextWindow__gc(lua_State* L) { +static int +TextWindow__gc(lua_State* L) +{ TextWindow tw = checkTextWindow(L,1); - if (!tw) - return 0; - - if (!tw->expired) { - tw->expired = TRUE; - ops->destroy_text_window(tw->ws_tw); - } else { - g_free(tw); - } - - + if (!tw) + return 0; + + if (!tw->expired) { + tw->expired = TRUE; + ops->destroy_text_window(tw->ws_tw); + } else { + g_free(tw); + } + return 0; } -WSLUA_METHOD TextWindow_set_editable(lua_State* L) { /* Make this window editable */ +/* Make this window editable */ #define WSLUA_OPTARG_TextWindow_set_editable_EDITABLE 2 /* A boolean flag, defaults to true */ +WSLUA_METHOD +TextWindow_set_editable(lua_State* L) +{ + TextWindow tw = checkTextWindow(L,1); + gboolean editable = wslua_optbool(L,WSLUA_OPTARG_TextWindow_set_editable_EDITABLE,TRUE); - TextWindow tw = checkTextWindow(L,1); - gboolean editable = wslua_optbool(L,WSLUA_OPTARG_TextWindow_set_editable_EDITABLE,TRUE); - - if (!tw) - WSLUA_ERROR(TextWindow_set_editable,"Cannot be called for something not a TextWindow"); + if (!tw) + WSLUA_ERROR(TextWindow_set_editable,"Cannot be called for something not a TextWindow"); if (tw->expired) - WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); - - if (ops->set_editable) - ops->set_editable(tw->ws_tw,editable); + WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); + + if (ops->set_editable) + ops->set_editable(tw->ws_tw,editable); - WSLUA_RETURN(1); /* The TextWindow object. */ + WSLUA_RETURN(1); /* The TextWindow object. */ } typedef struct _wslua_bt_cb_t { @@ -572,71 +642,75 @@ typedef struct _wslua_bt_cb_t { int wslua_tw_ref; } wslua_bt_cb_t; -static gboolean wslua_button_callback(funnel_text_window_t* ws_tw, void* data) { - wslua_bt_cb_t* cbd = data; - lua_State* L = cbd->L; - (void) ws_tw; /* ws_tw is unused since we need wslua_tw_ref and it is stored in cbd */ - - lua_settop(L,0); - lua_pushcfunction(L,dlg_cb_error_handler); - lua_rawgeti(L, LUA_REGISTRYINDEX, cbd->func_ref); - lua_rawgeti(L, LUA_REGISTRYINDEX, cbd->wslua_tw_ref); - - switch ( lua_pcall(L,1,0,1) ) { - case 0: - break; - case LUA_ERRRUN: - g_warning("Runtime error while calling button callback"); - break; - case LUA_ERRMEM: - g_warning("Memory alloc error while calling button callback"); - break; - default: - g_assert_not_reached(); - break; - } - - return TRUE; -} - -WSLUA_METHOD TextWindow_add_button(lua_State* L) { +static gboolean +wslua_button_callback(funnel_text_window_t* ws_tw, void* data) +{ + wslua_bt_cb_t* cbd = data; + lua_State* L = cbd->L; + (void) ws_tw; /* ws_tw is unused since we need wslua_tw_ref and it is stored in cbd */ + + lua_settop(L,0); + lua_pushcfunction(L,dlg_cb_error_handler); + lua_rawgeti(L, LUA_REGISTRYINDEX, cbd->func_ref); + lua_rawgeti(L, LUA_REGISTRYINDEX, cbd->wslua_tw_ref); + + switch ( lua_pcall(L,1,0,1) ) { + case 0: + break; + case LUA_ERRRUN: + g_warning("Runtime error while calling button callback"); + break; + case LUA_ERRMEM: + g_warning("Memory alloc error while calling button callback"); + break; + default: + g_assert_not_reached(); + break; + } + + return TRUE; +} + #define WSLUA_ARG_TextWindow_add_button_LABEL 2 /* The label of the button */ #define WSLUA_ARG_TextWindow_add_button_FUNCTION 3 /* The function to be called when clicked */ - TextWindow tw = checkTextWindow(L,1); - const gchar* label = luaL_checkstring(L,WSLUA_ARG_TextWindow_add_button_LABEL); +WSLUA_METHOD +TextWindow_add_button(lua_State* L) +{ + TextWindow tw = checkTextWindow(L,1); + const gchar* label = luaL_checkstring(L,WSLUA_ARG_TextWindow_add_button_LABEL); - funnel_bt_t* fbt; - wslua_bt_cb_t* cbd; + funnel_bt_t* fbt; + wslua_bt_cb_t* cbd; - if (!tw) - WSLUA_ERROR(TextWindow_add_button,"Cannot be called for something not a TextWindow"); + if (!tw) + WSLUA_ERROR(TextWindow_add_button,"Cannot be called for something not a TextWindow"); if (tw->expired) - WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); - - if (! lua_isfunction(L,WSLUA_ARG_TextWindow_add_button_FUNCTION) ) - WSLUA_ARG_ERROR(TextWindow_add_button,FUNCTION,"must be a function"); + WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); - lua_settop(L,3); + if (! lua_isfunction(L,WSLUA_ARG_TextWindow_add_button_FUNCTION) ) + WSLUA_ARG_ERROR(TextWindow_add_button,FUNCTION,"must be a function"); - if (ops->add_button) { - fbt = g_malloc(sizeof(funnel_bt_t)); - cbd = g_malloc(sizeof(wslua_bt_cb_t)); + lua_settop(L,3); - fbt->tw = tw->ws_tw; - fbt->func = wslua_button_callback; - fbt->data = cbd; - fbt->free_fcn = g_free; - fbt->free_data_fcn = g_free; + if (ops->add_button) { + fbt = g_malloc(sizeof(funnel_bt_t)); + cbd = g_malloc(sizeof(wslua_bt_cb_t)); - cbd->L = L; - cbd->func_ref = luaL_ref(L, LUA_REGISTRYINDEX); - cbd->wslua_tw_ref = luaL_ref(L, LUA_REGISTRYINDEX); + fbt->tw = tw->ws_tw; + fbt->func = wslua_button_callback; + fbt->data = cbd; + fbt->free_fcn = g_free; + fbt->free_data_fcn = g_free; - ops->add_button(tw->ws_tw,fbt,label); - } + cbd->L = L; + cbd->func_ref = luaL_ref(L, LUA_REGISTRYINDEX); + cbd->wslua_tw_ref = luaL_ref(L, LUA_REGISTRYINDEX); - WSLUA_RETURN(1); /* The TextWindow object. */ + ops->add_button(tw->ws_tw,fbt,label); + } + + WSLUA_RETURN(1); /* The TextWindow object. */ } WSLUA_METHODS TextWindow_methods[] = { @@ -650,7 +724,7 @@ WSLUA_METHODS TextWindow_methods[] = { WSLUA_CLASS_FNREG(TextWindow,set_editable), WSLUA_CLASS_FNREG(TextWindow,get_text), WSLUA_CLASS_FNREG(TextWindow,add_button), - {0, 0} + {0, 0} }; WSLUA_META TextWindow_meta[] = { @@ -659,155 +733,165 @@ WSLUA_META TextWindow_meta[] = { {0, 0} }; -int TextWindow_register(lua_State* L) { - +int +TextWindow_register(lua_State* L) +{ ops = funnel_get_funnel_ops(); - WSLUA_REGISTER_CLASS(TextWindow); + WSLUA_REGISTER_CLASS(TextWindow); return 1; } -WSLUA_FUNCTION wslua_retap_packets(lua_State* L) { - /* - Rescan all packets and just run taps - don't reconstruct the display. - */ - if ( ops->retap_packets ) { - ops->retap_packets(); - } else { - WSLUA_ERROR(wslua_retap_packets, "Does not work on TShark"); - } +/* Rescan all packets and just run taps - don't reconstruct the display. */ +WSLUA_FUNCTION wslua_retap_packets(lua_State* L) +{ + if ( ops->retap_packets ) { + ops->retap_packets(); + } else { + WSLUA_ERROR(wslua_retap_packets, "Does not work on TShark"); + } - return 0; + return 0; } -WSLUA_FUNCTION wslua_copy_to_clipboard(lua_State* L) { /* Copy a string into the clipboard */ +/* Copy a string into the clipboard */ #define WSLUA_ARG_copy_to_clipboard_TEXT 1 /* The string to be copied into the clipboard. */ - const char* copied_str = luaL_checkstring(L,WSLUA_ARG_copy_to_clipboard_TEXT); - GString* gstr; - if (!ops->copy_to_clipboard) { - WSLUA_ERROR(wslua_copy_to_clipboard, "Does not work on TShark"); - } +WSLUA_FUNCTION wslua_copy_to_clipboard(lua_State* L) +{ + const char* copied_str = luaL_checkstring(L,WSLUA_ARG_copy_to_clipboard_TEXT); + GString* gstr; + if (!ops->copy_to_clipboard) { + WSLUA_ERROR(wslua_copy_to_clipboard, "Does not work on TShark"); + } - if (!copied_str) { - WSLUA_ARG_ERROR(copy_to_clipboard,TEXT,"Must be a string"); - } + if (!copied_str) { + WSLUA_ARG_ERROR(copy_to_clipboard,TEXT,"Must be a string"); + } - gstr = g_string_new(copied_str); + gstr = g_string_new(copied_str); - ops->copy_to_clipboard(gstr); + ops->copy_to_clipboard(gstr); - g_string_free(gstr,TRUE); + g_string_free(gstr,TRUE); - return 0; + return 0; } -WSLUA_FUNCTION wslua_open_capture_file(lua_State* L) { /* Open and display a capture file */ +/* Open and display a capture file */ #define WSLUA_ARG_open_capture_file_FILENAME 1 /* The name of the file to be opened. */ #define WSLUA_ARG_open_capture_file_FILTER 2 /* A filter to be applied as the file gets opened. */ +WSLUA_FUNCTION wslua_open_capture_file(lua_State* L) +{ + const char* fname = luaL_checkstring(L,WSLUA_ARG_open_capture_file_FILENAME); + const char* filter = luaL_optstring(L,WSLUA_ARG_open_capture_file_FILTER,NULL); + const char* error = NULL; + + if (!ops->open_file) { + WSLUA_ERROR(wslua_open_capture_file, "Does not work on TShark"); + } - const char* fname = luaL_checkstring(L,WSLUA_ARG_open_capture_file_FILENAME); - const char* filter = luaL_optstring(L,WSLUA_ARG_open_capture_file_FILTER,NULL); - const char* error = NULL; - - if (!ops->open_file) { - WSLUA_ERROR(wslua_open_capture_file, "Does not work on TShark"); - } - - if (!fname) { - WSLUA_ARG_ERROR(open_capture_file,FILENAME,"Must be a string"); - } + if (!fname) { + WSLUA_ARG_ERROR(open_capture_file,FILENAME,"Must be a string"); + } - if (! ops->open_file(fname,filter,&error) ) { - lua_pushboolean(L,FALSE); + if (! ops->open_file(fname,filter,&error) ) { + lua_pushboolean(L,FALSE); - if (error) - lua_pushstring(L,error); - else - lua_pushnil(L); + if (error) + lua_pushstring(L,error); + else + lua_pushnil(L); - return 2; - } else { - lua_pushboolean(L,TRUE); - return 1; - } + return 2; + } else { + lua_pushboolean(L,TRUE); + return 1; + } } -WSLUA_FUNCTION wslua_set_filter(lua_State* L) { /* Set the main filter text */ +/* Set the main filter text */ #define WSLUA_ARG_set_filter_TEXT 1 /* The filter's text. */ - const char* filter_str = luaL_checkstring(L,WSLUA_ARG_set_filter_TEXT); +WSLUA_FUNCTION wslua_set_filter(lua_State* L) +{ + const char* filter_str = luaL_checkstring(L,WSLUA_ARG_set_filter_TEXT); - if (!ops->set_filter) { - WSLUA_ERROR(wslua_set_filter, "Does not work on TShark"); - } + if (!ops->set_filter) { + WSLUA_ERROR(wslua_set_filter, "Does not work on TShark"); + } - if (!filter_str) { - WSLUA_ARG_ERROR(set_filter,TEXT,"Must be a string"); - } + if (!filter_str) { + WSLUA_ARG_ERROR(set_filter,TEXT,"Must be a string"); + } - ops->set_filter(filter_str); + ops->set_filter(filter_str); - return 0; + return 0; } -WSLUA_FUNCTION wslua_apply_filter(lua_State* L) { /* Apply the filter in the main filter box */ - if (!ops->apply_filter) { - WSLUA_ERROR(wslua_apply_filter, "Does not work on TShark"); - } +/* Apply the filter in the main filter box */ +WSLUA_FUNCTION wslua_apply_filter(lua_State* L) +{ + if (!ops->apply_filter) { + WSLUA_ERROR(wslua_apply_filter, "Does not work on TShark"); + } - ops->apply_filter(); + ops->apply_filter(); - return 0; + return 0; } -WSLUA_FUNCTION wslua_reload(lua_State* L) { /* Reload the current capture file */ - - if (!ops->reload) { - WSLUA_ERROR(wslua_reload, "Does not work on TShark"); - } +/* Reload the current capture file */ +WSLUA_FUNCTION wslua_reload(lua_State* L) +{ + if (!ops->reload) { + WSLUA_ERROR(wslua_reload, "Does not work on TShark"); + } - ops->reload(); + ops->reload(); - return 0; + return 0; } -WSLUA_FUNCTION wslua_browser_open_url(lua_State* L) { /* Open an url in a browser */ +/* Open an url in a browser */ #define WSLUA_ARG_browser_open_url_URL 1 /* The url. */ - const char* url = luaL_checkstring(L,WSLUA_ARG_browser_open_url_URL); +WSLUA_FUNCTION wslua_browser_open_url(lua_State* L) +{ + const char* url = luaL_checkstring(L,WSLUA_ARG_browser_open_url_URL); - if (!ops->browser_open_url) { - WSLUA_ERROR(browser_open_url, "Does not work on TShark"); - } + if (!ops->browser_open_url) { + WSLUA_ERROR(browser_open_url, "Does not work on TShark"); + } - if (!url) { - WSLUA_ARG_ERROR(browser_open_url,URL,"Must be a string"); - } + if (!url) { + WSLUA_ARG_ERROR(browser_open_url,URL,"Must be a string"); + } - ops->browser_open_url(url); + ops->browser_open_url(url); - return 0; + return 0; } -WSLUA_FUNCTION wslua_browser_open_data_file(lua_State* L) { /* Open an file in a browser */ +/* Open an file in a browser */ #define WSLUA_ARG_browser_open_data_file_FILENAME 1 /* The url. */ - const char* file = luaL_checkstring(L,WSLUA_ARG_browser_open_data_file_FILENAME); +WSLUA_FUNCTION wslua_browser_open_data_file(lua_State* L) +{ + const char* file = luaL_checkstring(L,WSLUA_ARG_browser_open_data_file_FILENAME); - if (!ops->browser_open_data_file) { - WSLUA_ERROR(browser_open_data_file, "Does not work on TShark"); - } + if (!ops->browser_open_data_file) { + WSLUA_ERROR(browser_open_data_file, "Does not work on TShark"); + } - if (!file) { - WSLUA_ARG_ERROR(browser_open_data_file,FILENAME,"Must be a string"); - } + if (!file) { + WSLUA_ARG_ERROR(browser_open_data_file,FILENAME,"Must be a string"); + } - ops->browser_open_data_file(file); + ops->browser_open_data_file(file); - return 0; + return 0; } - - |