aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wslua
diff options
context:
space:
mode:
authorLuis Ontanon <luis.ontanon@gmail.com>2006-12-23 03:45:46 +0000
committerLuis Ontanon <luis.ontanon@gmail.com>2006-12-23 03:45:46 +0000
commit874912824ce8ba4f0ff8979f5f90d86297ed1cac (patch)
treeb71d0a44cfca02beb2341fece1c040aa62d624fb /epan/wslua
parent44535d37b287fd2833b316130881f0b863f361cf (diff)
- Fix an error in the tap listener callback
- add some comments to console.lua svn path=/trunk/; revision=20206
Diffstat (limited to 'epan/wslua')
-rw-r--r--epan/wslua/console.lua21
-rw-r--r--epan/wslua/wslua_listener.c12
2 files changed, 22 insertions, 11 deletions
diff --git a/epan/wslua/console.lua b/epan/wslua/console.lua
index 791d9effad..04e066bd00 100644
--- a/epan/wslua/console.lua
+++ b/epan/wslua/console.lua
@@ -25,14 +25,23 @@
if (gui_enabled()) then
+ -- Note that everything is "local" to this "if then"
+ -- this way we don't add globals
+
+ -- Evaluate Window
local function evaluate_lua()
local w = TextWindow.new("Evaluate Lua")
w:set_editable()
- function eval()
+ -- button callback
+ local function eval()
+ -- get the window's text and remove the result
local text = string.gsub(w:get_text(),"%c*--%[%[.*--%]%]$","")
+
+ -- if the text begins with '=' then convert = into return
text = string.gsub(text,"^=","return ")
+ -- evaluate text
local result = assert(loadstring(text))()
if (result ~= nil) then
@@ -50,16 +59,18 @@ if (gui_enabled()) then
local date = rawget(os,"date") -- use rawget to avoid disabled's os.__index
if type(date) ~= "function" then
- -- 'os' has been disabled use a dummy function for date
+ -- 'os' has been disabled, use a dummy function for date
date = function() return "" end
end
+ -- Console Window
local function run_console()
if console_open then return end
console_open = true
local w = TextWindow.new("Console")
+ -- save original logger functions
local orig = {
critical = critical,
warn = warn,
@@ -68,13 +79,15 @@ if (gui_enabled()) then
debug = debug
}
+ -- define new logger functions that append text to the window
function critical(x) w:append( date() .. " CRITICAL: " .. tostring(x) .. "\n") end
function warn(x) w:append( date() .. " WARN: " .. tostring(x) .. "\n") end
function message(x) w:append( date() .. " MESSAGE: " .. tostring(x) .. "\n") end
function info(x) w:append( date() .. " INFO: " .. tostring(x) .. "\n") end
function debug(x) w:append( date() .. " DEBUG: " .. tostring(x) .. "\n") end
- function at_close()
+ -- when the window gets closed restore the original logger functions
+ local function at_close()
critical = orig.critical
warn = orig.warn
message = orig.message
@@ -90,4 +103,4 @@ if (gui_enabled()) then
register_menu("Lua/Evaluate",evaluate_lua,MENU_TOOLS)
register_menu("Lua/Console",run_console,MENU_TOOLS)
-end \ No newline at end of file
+end
diff --git a/epan/wslua/wslua_listener.c b/epan/wslua/wslua_listener.c
index 182d25180e..3e33d99e92 100644
--- a/epan/wslua/wslua_listener.c
+++ b/epan/wslua/wslua_listener.c
@@ -81,7 +81,8 @@ int tap_packet_cb_error_handler(lua_State* L) {
int lua_tap_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const void *data) {
Listener tap = tapdata;
int retval = 0;
-
+ int top;
+
if (tap->packet_ref == LUA_NOREF) return 0;
lua_settop(tap->L,0);
@@ -104,14 +105,11 @@ int lua_tap_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const
lua_tree->tree = edt->tree;
lua_tree->item = NULL;
+ top = lua_gettop(tap->L);
+
switch ( lua_pcall(tap->L,3,1,1) ) {
case 0:
-
- if (lua_gettop(tap->L) > 0)
- retval = luaL_checkint(tap->L,1);
- else
- retval = 1;
-
+ retval = luaL_optint(tap->L,-1,1);
break;
case LUA_ERRRUN:
break;