- wslua_util.c: replace Lua's loadfile and dofile for versions that will try to open the file in perscofdir then dataconfdir if there's no such file in cwd
- wslua_field.c: avoid FieldInfo:__tostring() crashing when the ftype has no val_to_string_repr - init.lua: inform the user that a packet has been disabled, intead of a cryptic "attemt to call nil" - Makefile.am: add register_wslua.c and declare_wslua.h to MAINTAINERCLEANFILES - wslua_gui.c: fix a typo svn path=/trunk/; revision=19425
This commit is contained in:
parent
7ecb3721a3
commit
ba90067e62
|
@ -61,6 +61,8 @@ DISTCLEANFILES = \
|
|||
|
||||
MAINTAINERCLEANFILES = \
|
||||
Makefile.in \
|
||||
register_wslua.c \
|
||||
declare_wslua.h \
|
||||
doc/*.pod \
|
||||
init.lua
|
||||
|
||||
|
|
|
@ -26,8 +26,7 @@
|
|||
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
-- If lua is to be disabled even if it was installed uncomment the following
|
||||
-- line.
|
||||
-- If lua is to be completely disabled uncomment the following line.
|
||||
-- disable_lua = true; do return end;
|
||||
|
||||
|
||||
|
@ -35,15 +34,19 @@
|
|||
-- tells whether scripts other than this one are to be run.
|
||||
run_user_scripts_when_superuser = false
|
||||
|
||||
|
||||
-- disable potentialy harmful lua functions when running superuser
|
||||
if running_superuser then
|
||||
local disabled_lib = {}
|
||||
setmetatable(disabled_lib,{ __index = function() error("this package has been disabled") end } );
|
||||
|
||||
dofile = function() error("dofile has been disabled") end
|
||||
loadfile = function() error("loadfile has been disabled") end
|
||||
loadlib = function() error("loadlib has been disabled") end
|
||||
require = function() error("require has been disabled") end
|
||||
os = {}
|
||||
io = {}
|
||||
file = {}
|
||||
os = disabled_lib
|
||||
io = disabled_lib
|
||||
file = disabled_lib
|
||||
end
|
||||
|
||||
-- to avoid output to stdout which can caause problems lua's print ()
|
||||
|
|
|
@ -137,7 +137,10 @@ WSLUA_METAMETHOD FieldInfo__call(lua_State* L) {
|
|||
WSLUA_METAMETHOD FieldInfo__tostring(lua_State* L) {
|
||||
FieldInfo fi = checkFieldInfo(L,1);
|
||||
if (fi) {
|
||||
lua_pushstring(L,fvalue_to_string_repr(&fi->value,FTREPR_DISPLAY,NULL));
|
||||
if (fi->value.ftype->val_to_string_repr)
|
||||
lua_pushstring(L,fvalue_to_string_repr(&fi->value,FTREPR_DISPLAY,NULL));
|
||||
else
|
||||
luaL_error(L,"field has no string representation");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -574,7 +574,7 @@ WSLUA_FUNCTION wslua_set_filter(lua_State* L) { /* set the main filter text */
|
|||
|
||||
WSLUA_FUNCTION wslua_apply_filter(lua_State* L) { /* apply the filter in the main filter box */
|
||||
if (!ops->apply_filter) {
|
||||
WSLUA_ERROR(wslua_set_filter, "does not work on TShark");
|
||||
WSLUA_ERROR(wslua_apply_filter, "does not work on TShark");
|
||||
}
|
||||
|
||||
ops->apply_filter();
|
||||
|
@ -583,8 +583,7 @@ WSLUA_FUNCTION wslua_apply_filter(lua_State* L) { /* apply the filter in the mai
|
|||
}
|
||||
|
||||
|
||||
WSLUA_FUNCTION wslua_reload(lua_State* L) { /* set the main filter text */
|
||||
#define WSLUA_ARG_set_filter_TEXT 1 /* The filter's text. */
|
||||
WSLUA_FUNCTION wslua_reload(lua_State* L) { /* reload the current capture file */
|
||||
|
||||
if (!ops->reload) {
|
||||
WSLUA_ERROR(wslua_reload, "does not work on TShark");
|
||||
|
|
|
@ -126,4 +126,58 @@ WSLUA_FUNCTION wslua_debug( lua_State* L ) { /* Will add a log entry with debug
|
|||
return 0;
|
||||
}
|
||||
|
||||
const char* get_actual_filename(const char* fname) {
|
||||
const char* filename;
|
||||
|
||||
if ( file_exists(fname) ) {
|
||||
return fname;
|
||||
}
|
||||
|
||||
filename = get_persconffile_path(fname,FALSE);
|
||||
|
||||
if ( file_exists(filename) ) {
|
||||
return filename;
|
||||
}
|
||||
|
||||
filename = get_datafile_path(fname);
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
WSLUA_FUNCTION wslua_loadfile(lua_State* L) {
|
||||
#define WSLUA_ARG_loadfile_FILENAME 1
|
||||
const char *given_fname = luaL_checkstring(L, WSLUA_ARG_loadfile_FILENAME);
|
||||
const char* filename;
|
||||
|
||||
if (!given_fname) WSLUA_ARG_ERROR(loadfile,FILENAME,"must be a string");
|
||||
|
||||
filename = get_actual_filename(given_fname);
|
||||
|
||||
if (!filename) WSLUA_ARG_ERROR(loadfile,FILENAME,"file does not exist");
|
||||
|
||||
if (luaL_loadfile(L, filename) == 0) {
|
||||
return 1;
|
||||
} else {
|
||||
lua_pushnil(L);
|
||||
lua_insert(L, -2);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
WSLUA_FUNCTION wslua_dofile(lua_State* L) {
|
||||
#define WSLUA_ARG_dofile_FILENAME 1
|
||||
const char *given_fname = luaL_checkstring(L, WSLUA_ARG_dofile_FILENAME);
|
||||
const char* filename;
|
||||
int n;
|
||||
|
||||
if (!given_fname) WSLUA_ARG_ERROR(dofile,FILENAME,"must be a string");
|
||||
|
||||
filename = get_actual_filename(given_fname);
|
||||
|
||||
if (!filename) WSLUA_ARG_ERROR(dofile,FILENAME,"file does not exist");
|
||||
|
||||
n = lua_gettop(L);
|
||||
if (luaL_loadfile(L, filename) != 0) lua_error(L);
|
||||
lua_call(L, 0, LUA_MULTRET);
|
||||
return lua_gettop(L) - n;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue