- wslua_gui.c:

- remove data_ref where it is not used anymore (callbacks won't pass userdata as this ius better done using lua's closures)
  - have TextWindow:set_editable() using its argument

- add wslua_optbool(L,n,d) to pull an optional boolean from the stack

- several fixes to docbook generation (now it compiles!)



svn path=/trunk/; revision=19608
This commit is contained in:
Luis Ontanon 2006-10-19 17:02:23 +00:00
parent 631a4936c5
commit 82abc5f08b
7 changed files with 169 additions and 38 deletions

View File

@ -102,7 +102,7 @@ register_wslua.c: declare_wslua.h
declare_wslua.h: make-reg.pl $(wslua_modules) taps_wslua.c
$(PERL) $(srcdir)/make-reg.pl $(wslua_modules);
doc: make-doc.pl $(wslua_modules)
doc: make-doc.pl $(wslua_modules) template-wsluarm.xml
$(PERL) $(srcdir)/make-doc.pl $(wslua_modules)
dummy:

View File

@ -40,17 +40,20 @@ sub gorolla {
my $s = shift;
$s =~ s/^([\n]|\s)*//ms;
$s =~ s/([\n]|\s)*$//ms;
$s =~ s/\</&lt;/ms;
$s =~ s/\>/&gt;/ms;
$s;
}
my %module = ();
my %modules = ();
my $class;
my %classes;
my $function;
my @functions;
my $docbook_template = {
module_header => "<chapter id='lua_module_%s'><title>%s</title>\n",
module_header => "<chapter id='lua_module_%s'>\n\t<title>%s</title>\n",
module_desc => "\t<para>%s</para>\n",
module_footer => "</chapter>\n",
class_header => "\t<section id='lua_class_%s'><title>%s</title>\n",
@ -64,7 +67,7 @@ my $docbook_template = {
class_attributes_footer => "\t\t</section> <!-- class_attributes_footer: %s -->\n",
class_attr_header => "\t\t<section id='lua_class_attrib_%s'>\n\t\t\t<title>%s</title>\n",
class_attr_footer => "\t\t</section> <!-- class_attr_footer: %s -->\n",
class_attr_descr => "\t\t\t<para>%s<para>\n",
class_attr_descr => "\t\t\t<para>%s</para>\n",
function_header => "\t\t\t<section id='lua_fn_%s'>\n\t\t\t\t<title>%s</title>\n",
function_descr => "\t\t\t\t<para>%s</para>\n",
function_footer => "\t\t\t</section> <!-- function_footer: %s -->\n",
@ -206,12 +209,14 @@ sub {
deb ">cm=$1=$2=$3=$4=$5=$6=$7=\n";
my $name = $metamethods{$2};
my ($c,$d) = ($1,$5);
my $sname = $2;
$name =~ s/__/$c/g;
$function = {
returns => [],
arglist => [],
args => {},
name => $name,
section_name => $sname,
descr => gorolla($d),
type => 'metamethod'
};
@ -290,6 +295,8 @@ while ( $file = shift) {
next unless -f $file;
%module = ();
my $docfile = $file;
$docfile =~ s/\.c$/.$out_extension/;
@ -312,6 +319,8 @@ while ( $file = shift) {
}
}
$modules{$module{name}} = $docfile;
printf D ${$template_ref}{module_header}, $module{name}, $module{name};
if ( exists ${$template_ref}{module_desc} ) {
printf D ${$template_ref}{module_desc}, $module{descr}, $module{descr};
@ -372,7 +381,7 @@ while ( $file = shift) {
}
if ($#functions >= 0) {
print D ${$template_ref}{non_method_functions_header};
printf D ${$template_ref}{non_method_functions_header}, $module{name};
for my $f (@functions) {
function_descr($f);
@ -392,12 +401,36 @@ while ( $file = shift) {
close D;
}
my $wsluarm = '';
open B, "< template-wsluarm.xml";
$wsluarm .= $_ while(<B>);
close B;
my $ents = '';
my $txt = '';
for my $module_name (keys %modules) {
$ents .= <<"_ENT";
<!ENTITY $module_name SYSTEM "$modules{$module_name}">
_ENT
$txt .= "&$module_name;\n";
}
$wsluarm =~ s/<!-- WSLUA_MODULE_ENTITIES -->/$ents/;
$wsluarm =~ s/<!-- WSLUA_MODULE_TEXT -->/$txt/;
open X, "> doc/wsluarm.xml";
print X $wsluarm;
close X;
sub function_descr {
my $f = $_[0];
my $label = $_[1];
if (defined $label ) {
printf D ${$template_ref}{function_header}, $label, $label;
$label =~ s/>/&gt;/;
$label =~ s/</&lt;/;
printf D ${$template_ref}{function_header}, ${$f}{section_name}, $label;
} else {
my $arglist = '';
@ -408,7 +441,7 @@ sub function_descr {
}
$arglist =~ s/, $//;
printf D ${$template_ref}{function_header}, "${$f}{name}($arglist)", "${$f}{name}($arglist)";
}
@ -438,7 +471,9 @@ sub function_descr {
}
if ( $#{${$f}{errors}} >= 0) {
printf D ${$template_ref}{function_errors_header}, ${$f}{name};
my $sname = exists ${$f}{section_name} ? ${$f}{section_name} : ${$f}{name};
printf D ${$template_ref}{function_errors_header}, $sname;
printf D ${$template_ref}{function_errors}, $_ for @{${$f}{errors}};
printf D ${$template_ref}{function_errors_footer}, ${$f}{name};
}

View File

@ -0,0 +1,77 @@
<?xml version="1.0"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
<!-- $Id$ -->
<!--
BIOGRAPHICAL SECTION
-Use this section to encode all biographical information
-->
<!-- Author's Names -->
<!ENTITY AuthorFullName "Luis E. Garcia Ontanon">
<!ENTITY AuthorFirstName "Luis">
<!ENTITY AuthorOtherName "Enrrique">
<!ENTITY AuthorSurname "Garcia Ontanon">
<!--Author's Affiliation -->
<!ENTITY AuthorShortAffiliation "">
<!ENTITY AuthorJobTitle "">
<!ENTITY AuthorOrgName "">
<!ENTITY AuthorOrgDiv "">
<!ENTITY AuthorEmail "luis.ontanon[at]gmail.com">
<!--
DOCUMENT SECTION
-Use this section to encode all document information
-->
<!ENTITY DocumentTitle "Wireshark's LUA API Reference Manual">
<!ENTITY DocumentSubTitle "&SvnVersion; for Wireshark &WiresharkCurrentVersion;">
<!ENTITY DocumentTitleAbbreviation "WSLUARM">
<!ENTITY DocumentCopyrightHolder1 "Luis E. Garcia Ontanon">
<!ENTITY DocumentCopyrightYear "2006">
<!ENTITY DocumentEdition "First ">
<!ENTITY DocumentVersion "V0.1">
<!ENTITY DocumentPubDate "2006">
<!ENTITY DocumentLegalNotice "<para>Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation.</para><para>All logos and trademarks in this document are property of their respective owner.</para>">
<!--
Wireshark Info
-->
<!ENTITY WiresharkCurrentVersion "0.99.3">
<!--
Gnu info
-->
<!ENTITY GPLWebsite "http://www.gnu.org/copyleft/gpl.html">
<!--
Timezone info
-->
<!ENTITY TimezoneGMTSite "http://wwp.greenwichmeantime.com/">
<!ENTITY TimezoneWorldClockSite "http://www.timeanddate.com/worldclock/">
<!ENTITY NTPSite "http://www.ntp.org/">
<!ENTITY WikipediaWebsite "http://en.wikipedia.org">
<!ENTITY WikipediaTimezone "&WikipediaWebsite;/wiki/Time_zone">
<!ENTITY WikipediaDaylightSaving "&WikipediaWebsite;/wiki/Daylight_saving">
<!ENTITY WikipediaUTC "&WikipediaWebsite;/wiki/Coordinated_Universal_Time">
<!--
FILE SECTION
-Use this section to specify the files that make up the book. Use FPI (public identifiers)
-->
<!-- These refer to graphics files and figures contained in the document -->
<!-- These are the actual files that make up the document -->
<!-- WSLUA_MODULE_ENTITIES -->
]>
<book>
<title>&DocumentTitle;</title>
<!-- WSLUA_MODULE_TEXT -->
</book>

View File

@ -5,7 +5,7 @@
*
* (c) 2006, Luis E. Garcia Ontanon <luis.ontanon@gmail.com>
*
* $Id: wslua.h 18231 2006-05-28 16:32:49Z etxrab $
* $Id$
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
@ -315,6 +315,7 @@ WSLUA_DECLARE_FUNCTIONS()
extern lua_State* wslua_state(void);
extern gboolean wslua_optbool(lua_State* L, int n, gboolean def);
extern const gchar* lua_shiftstring(lua_State* L,int idx);
extern void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree);

View File

@ -48,13 +48,26 @@ WSLUA_FUNCTION wslua_gui_enabled(lua_State* L) { /* Checks whether the GUI facil
void lua_menu_callback(gpointer data) {
struct _lua_menu_data* md = data;
lua_pushcfunction(md->L,menu_cb_error_handler);
lua_rawgeti(md->L, LUA_REGISTRYINDEX, md->cb_ref);
lua_State* L = md->L;
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;
}
/* XXX handle error */
lua_pcall(md->L,0,0,1);
return;
}
@ -99,7 +112,6 @@ WSLUA_FUNCTION wslua_register_menu(lua_State* L) { /* Register a menu item in t
struct _dlg_cb_data {
lua_State* L;
int func_ref;
int data_ref;
};
static int dlg_cb_error_handler(lua_State* L) {
@ -117,7 +129,6 @@ static void lua_dialog_cb(gchar** user_input, void* data) {
lua_settop(L,0);
lua_pushcfunction(L,dlg_cb_error_handler);
lua_rawgeti(L, LUA_REGISTRYINDEX, dcbd->func_ref);
lua_rawgeti(L, LUA_REGISTRYINDEX, dcbd->data_ref);
for (i = 0; (input = user_input[i]) ; i++) {
lua_pushstring(L,input);
@ -126,7 +137,7 @@ static void lua_dialog_cb(gchar** user_input, void* data) {
g_free(user_input);
switch ( lua_pcall(L,i+1,0,1) ) {
switch ( lua_pcall(L,i,0,1) ) {
case 0:
break;
case LUA_ERRRUN:
@ -182,14 +193,10 @@ WSLUA_FUNCTION wslua_new_dialog(lua_State* L) { /* Pops up a new dialog */
lua_pushvalue(L, 1);
dcbd->func_ref = luaL_ref(L, LUA_REGISTRYINDEX);
lua_remove(L,1);
lua_pushvalue(L, 1);
dcbd->data_ref = luaL_ref(L, LUA_REGISTRYINDEX);
lua_remove(L,1);
labels = g_ptr_array_new();
top -= 3;
top -= 2;
for (i = 1; i <= top; i++) {
gchar* label = (void*)luaL_checkstring(L,i);
@ -205,7 +212,7 @@ WSLUA_FUNCTION wslua_new_dialog(lua_State* L) { /* Pops up a new dialog */
ops->new_dialog(title, (const gchar**)labels->pdata, lua_dialog_cb, dcbd);
g_ptr_array_free(labels,TRUE);
g_ptr_array_free(labels,FALSE);
WSLUA_RETURN(0);
}
@ -214,6 +221,8 @@ WSLUA_FUNCTION wslua_new_dialog(lua_State* L) { /* Pops up a new dialog */
WSLUA_CLASS_DEFINE(TextWindow,NOP,NOP); /* Manages a text window. */
/* XXX: button and close callback data is being leaked */
WSLUA_CONSTRUCTOR TextWindow_new(lua_State* L) { /* Creates a new TextWindow. */
#define WSLUA_OPTARG_TextWindow_new_TITLE 1 /* Title of the new window. */
@ -230,7 +239,6 @@ WSLUA_CONSTRUCTOR TextWindow_new(lua_State* L) { /* Creates a new TextWindow. */
struct _close_cb_data {
lua_State* L;
int func_ref;
int data_ref;
};
int text_win_close_cb_error_handler(lua_State* L) {
@ -243,11 +251,11 @@ static void text_win_close_cb(void* data) {
struct _close_cb_data* cbd = data;
lua_State* L = cbd->L;
lua_settop(L,0);
lua_pushcfunction(L,text_win_close_cb_error_handler);
lua_rawgeti(L, LUA_REGISTRYINDEX, cbd->func_ref);
lua_rawgeti(L, LUA_REGISTRYINDEX, cbd->data_ref);
switch ( lua_pcall(L,1,0,1) ) {
switch ( lua_pcall(L,0,0,1) ) {
case 0:
break;
case LUA_ERRRUN:
@ -271,7 +279,7 @@ WSLUA_METHOD TextWindow_set_atclose(lua_State* L) { /* Set the function that wil
if (!tw)
WSLUA_ERROR(TextWindow_at_close,"cannot be called for something not a TextWindow");
lua_settop(L,3);
lua_settop(L,2);
if (! lua_isfunction(L,2))
WSLUA_ARG_ERROR(TextWindow_at_close,ACTION,"must be a function");
@ -279,7 +287,6 @@ WSLUA_METHOD TextWindow_set_atclose(lua_State* L) { /* Set the function that wil
cbd = g_malloc(sizeof(struct _close_cb_data));
cbd->L = L;
cbd->data_ref = luaL_ref(L, LUA_REGISTRYINDEX);
cbd->func_ref = luaL_ref(L, LUA_REGISTRYINDEX);
ops->set_close_cb(tw,text_win_close_cb,cbd);
@ -372,14 +379,14 @@ static int TextWindow__gc(lua_State* L) {
WSLUA_ERROR(TextWindow_gc,"cannot be called for something not a TextWindow");
ops->destroy_text_window(tw);
return 1;
return 0;
}
WSLUA_METHOD TextWindow_set_editable(lua_State* L) { /* Make this window editable */
#define WSLUA_OPTARG_TextWindow_set_editable_EDITABLE 2 /* A boolean flag, defaults to true */
TextWindow tw = checkTextWindow(L,1);
gboolean editable = luaL_optint(L,2,1);
gboolean editable = wslua_optbool(L,2,TRUE);
if (!tw)
WSLUA_ERROR(TextWindow_set_editable,"cannot be called for something not a TextWindow");
@ -394,7 +401,6 @@ WSLUA_METHOD TextWindow_set_editable(lua_State* L) { /* Make this window editabl
typedef struct _wslua_bt_cb_t {
lua_State* L;
int func_ref;
int data_ref;
} wslua_bt_cb_t;
static gboolean wslua_button_callback(funnel_text_window_t* tw, void* data) {
@ -405,9 +411,8 @@ static gboolean wslua_button_callback(funnel_text_window_t* tw, void* data) {
lua_pushcfunction(L,dlg_cb_error_handler);
lua_rawgeti(L, LUA_REGISTRYINDEX, cbd->func_ref);
pushTextWindow(L,tw);
lua_rawgeti(L, LUA_REGISTRYINDEX, cbd->data_ref);
switch ( lua_pcall(L,2,0,1) ) {
switch ( lua_pcall(L,1,0,1) ) {
case 0:
break;
case LUA_ERRRUN:
@ -427,7 +432,6 @@ static gboolean wslua_button_callback(funnel_text_window_t* tw, void* data) {
WSLUA_METHOD TextWindow_add_button(lua_State* L) {
#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 */
#define WSLUA_ARG_TextWindow_add_button_DATA 4 /* The data to be passed to the function (other than the window) */
TextWindow tw = checkTextWindow(L,1);
const gchar* label = luaL_checkstring(L,WSLUA_ARG_TextWindow_add_button_LABEL);
@ -440,7 +444,7 @@ WSLUA_METHOD TextWindow_add_button(lua_State* L) {
if (! lua_isfunction(L,WSLUA_ARG_TextWindow_add_button_FUNCTION) )
WSLUA_ARG_ERROR(TextWindow_add_button,FUNCTION,"must be a function");
lua_settop(L,4);
lua_settop(L,3);
if (ops->add_button) {
fbt = g_malloc(sizeof(funnel_bt_t));
@ -453,7 +457,6 @@ WSLUA_METHOD TextWindow_add_button(lua_State* L) {
fbt->free_data = g_free;
cbd->L = L;
cbd->data_ref = luaL_ref(L, LUA_REGISTRYINDEX);
cbd->func_ref = luaL_ref(L, LUA_REGISTRYINDEX);
ops->add_button(tw,fbt,label);

View File

@ -60,7 +60,7 @@ void* push_Pinfo(lua_State* L, Pinfo pinfo) {
#define PUSH_COLUMN(L,c) g_ptr_array_add(outstanding_stuff,pushColumn(L,c))
#define PUSH_COLUMNS(L,c) g_ptr_array_add(outstanding_stuff,pushColumns(L,c))
WSLUA_CLASS_DEFINE(Address,NOP,NOP);
WSLUA_CLASS_DEFINE(Address,NOP,NOP) /* Represents an address */
WSLUA_CONSTRUCTOR Address_ip(lua_State* L) { /* Creates an Address Object representing an IP address. */
#define WSLUA_ARG_Address_ip_HOSTNAME 1 /* The address or name of the IP host. */

View File

@ -29,6 +29,21 @@
#include "wslua.h"
#include <math.h>
WSLUA_API gboolean wslua_optbool(lua_State* L, int n, gboolean def) {
gboolean val = FALSE;
if ( lua_isboolean(L,n) ) {
val = lua_toboolean(L,n);
} else if ( lua_isnil(L,n) || lua_gettop(L) < n ){
val = def;
} else {
luaL_argerror(L,n,"must be a boolean");
}
return val;
}
WSLUA_API const gchar* lua_shiftstring(lua_State* L, int i) {
const gchar* p = luaL_checkstring(L, i);