From e4a140c7f0558f50f1134f851c02571c38920e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Wed, 29 Jan 2014 16:05:48 +0100 Subject: Lua: Added a utility function file_exists(). This function can be used to check for files before calling dofile(), which will fail for non-existing files. Change-Id: Iae7b7ef6d8eb6e0e18f98fee7c740d2a5705eef3 --- epan/wslua/template-init.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'epan/wslua/template-init.lua') diff --git a/epan/wslua/template-init.lua b/epan/wslua/template-init.lua index e6ec4ae9ae..74380263d9 100644 --- a/epan/wslua/template-init.lua +++ b/epan/wslua/template-init.lua @@ -64,6 +64,11 @@ function typeof(obj) return mt and mt.__typeof or type(obj) end +function file_exists(name) + local f = io.open(name,"r") + if f ~= nil then io.close(f) return true else return false end +end + -- %WTAP_ENCAPS% -- %WTAP_FILETYPES% -- cgit v1.2.3