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:
my $s = shift;
$s =~ s/^([\n]|\s)*//ms;
$s =~ s/([\n]|\s)*$//ms;
+ $s =~ s/\</</ms;
+ $s =~ s/\>/>/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",
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",
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'
};
next unless -f $file;
+ %module = ();
+
my $docfile = $file;
$docfile =~ s/\.c$/.$out_extension/;
}
}
+ $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};
}
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);
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/>/>/;
+ $label =~ s/</</;
+ printf D ${$template_ref}{function_header}, ${$f}{section_name}, $label;
} else {
my $arglist = '';
}
$arglist =~ s/, $//;
-
+
printf D ${$template_ref}{function_header}, "${$f}{name}($arglist)", "${$f}{name}($arglist)";
}
}
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};
}
--- /dev/null
+<?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>
*
* (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>
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);
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;
}
struct _dlg_cb_data {
lua_State* L;
int func_ref;
- int data_ref;
};
static int dlg_cb_error_handler(lua_State* L) {
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);
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:
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);
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);
}
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. */
struct _close_cb_data {
lua_State* L;
int func_ref;
- int data_ref;
};
int text_win_close_cb_error_handler(lua_State* L) {
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:
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");
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);
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");
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) {
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:
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);
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));
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);
#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. */
#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);