aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorDeveloper Alexander <dev@alex-mails.de>2021-06-27 13:05:52 +0200
committerWireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2021-07-13 06:52:55 +0000
commit69fb2a17e45fa10383cc4b28df2e1e9a9605d59e (patch)
tree601418413d970e4302f107ac359e274795507c9b /epan
parent054868cb0e9fd13ee5ccef2d312667510d5f1f72 (diff)
lua: dialog with prefilled values
new_dialog() lua api gets extended to enable that dialog fields can be prefilled by lua scripts instead of always starting empty.
Diffstat (limited to 'epan')
-rw-r--r--epan/funnel.h9
-rw-r--r--epan/wslua/wslua_gui.c65
2 files changed, 57 insertions, 17 deletions
diff --git a/epan/funnel.h b/epan/funnel.h
index 99a57cb88c..24ae0b3ead 100644
--- a/epan/funnel.h
+++ b/epan/funnel.h
@@ -60,10 +60,11 @@ typedef struct _funnel_ops_t {
void (*add_button)(funnel_text_window_t* win, funnel_bt_t* cb, const char* label);
void (*new_dialog)(const gchar* title,
- const gchar** fieldnames,
- funnel_dlg_cb_t dlg_cb,
- void* data,
- funnel_dlg_cb_data_free_t dlg_cb_data_free);
+ const gchar** field_names,
+ const gchar** field_values,
+ funnel_dlg_cb_t dlg_cb,
+ void* data,
+ funnel_dlg_cb_data_free_t dlg_cb_data_free);
void (*close_dialogs)(void);
diff --git a/epan/wslua/wslua_gui.c b/epan/wslua/wslua_gui.c
index 0e3cffbf4e..ec0c4c426b 100644
--- a/epan/wslua/wslua_gui.c
+++ b/epan/wslua/wslua_gui.c
@@ -246,12 +246,14 @@ WSLUA_FUNCTION wslua_new_dialog(lua_State* L) { /*
*/
#define WSLUA_ARG_new_dialog_TITLE 1 /* The title of the dialog. */
#define WSLUA_ARG_new_dialog_ACTION 2 /* Action to be performed when the user presses btn:[OK]. */
-/* WSLUA_MOREARGS new_dialog Strings to be used a labels of the dialog's fields. Each string creates a new labeled field. The first field is required. */
+/* WSLUA_MOREARGS new_dialog Strings to be used a labels of the dialog's fields. Each string creates a new labeled field. The first field is required.
+Instead of a strings it is possible to provide tables with fields 'name' and 'value' of type string. Then the created dialog's field will labeld with the content of name and prefilled with the content of value.*/
const gchar* title;
int top = lua_gettop(L);
int i;
- GPtrArray* labels;
+ GPtrArray* field_names;
+ GPtrArray* field_values;
struct _dlg_cb_data* dcbd;
if (! ops) {
@@ -286,26 +288,63 @@ WSLUA_FUNCTION wslua_new_dialog(lua_State* L) { /*
dcbd->func_ref = luaL_ref(L, LUA_REGISTRYINDEX);
lua_remove(L,1);
- labels = g_ptr_array_new_with_free_func(g_free);
+ field_names = g_ptr_array_new_with_free_func(g_free);
+ field_values = g_ptr_array_new_with_free_func(g_free);
top -= 2;
- for (i = 1; i <= top; i++) {
- if (! lua_isstring(L,i)) {
- g_ptr_array_free(labels,TRUE);
- g_free (dcbd);
- WSLUA_ERROR(new_dialog,"All fields must be strings");
+ for (i = 1; i <= top; i++)
+ {
+ if (lua_isstring(L, i))
+ {
+ gchar* field_name = g_strdup(luaL_checkstring(L, i));
+ gchar* field_value = g_strdup("");
+ g_ptr_array_add(field_names, (gpointer)field_name);
+ g_ptr_array_add(field_values, (gpointer)field_value);
+ }
+ else if (lua_istable(L, i))
+ {
+ lua_getfield(L, i, "name");
+ lua_getfield(L, i, "value");
+
+ if (!lua_isstring(L, -2))
+ {
+ lua_pop(L, 2);
+
+ g_ptr_array_free(field_names, TRUE);
+ g_ptr_array_free(field_values, TRUE);
+ g_free(dcbd);
+ WSLUA_ERROR(new_dialog, "All fields must be strings or a table with a string field 'name'.");
+ return 0;
+ }
+
+ gchar* field_name = g_strdup(luaL_checkstring(L, -2));
+ gchar* field_value = lua_isstring(L, -1) ?
+ g_strdup(luaL_checkstring(L, -1)) :
+ g_strdup("");
+
+ g_ptr_array_add(field_names, (gpointer)field_name);
+ g_ptr_array_add(field_values, (gpointer)field_value);
+
+ lua_pop(L, 2);
+ }
+ else
+ {
+ g_ptr_array_free(field_names, TRUE);
+ g_ptr_array_free(field_values, TRUE);
+ g_free(dcbd);
+ WSLUA_ERROR(new_dialog, "All fields must be strings or a table with a string field 'name'.");
return 0;
}
-
- g_ptr_array_add(labels,(gpointer)g_strdup(luaL_checkstring(L,i)));
}
- g_ptr_array_add(labels,NULL);
+ g_ptr_array_add(field_names, NULL);
+ g_ptr_array_add(field_values, NULL);
- ops->new_dialog(title, (const gchar**)(labels->pdata), lua_dialog_cb, dcbd, g_free);
+ ops->new_dialog(title, (const gchar**)(field_names->pdata), (const gchar**)(field_values->pdata), lua_dialog_cb, dcbd, g_free);
- g_ptr_array_free(labels,TRUE);
+ g_ptr_array_free(field_names, TRUE);
+ g_ptr_array_free(field_values, TRUE);
WSLUA_RETURN(0);
}