From aa2f54ffa31d47244dfe75dae1fd1560f36ec0a2 Mon Sep 17 00:00:00 2001 From: batrick Date: Sun, 12 Jun 2011 01:47:36 +0000 Subject: [PATCH] Originally, adding the script to the array of scripts would handle the case where the Script.new failed: chosen_scripts[#chosen_scripts+1] = Script.new(path); if Script.new returns nil, then the operation is a no-op (as intended). So, just add the script to the array. Script.new now accepts a selected_by_name argument so we don't set it manually. --- nse_main.lua | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/nse_main.lua b/nse_main.lua index 421ebfc2b..52a01e2bd 100644 --- a/nse_main.lua +++ b/nse_main.lua @@ -380,7 +380,7 @@ do -- filename The filename (path) of the script to load. -- Returns: -- script The script (class) created. - function Script.new (filename) + function Script.new (filename, selected_by_name) assert(type(filename) == "string", "string expected"); if not find(filename, "%.nse$") then log_error( @@ -457,7 +457,7 @@ do license = rawget(env, "license"), dependencies = rawget(env, "dependencies"), threads = {}, - selected_by_name = false, + selected_by_name = not not selected_by_name, }; return setmetatable(script, {__index = Script, __metatable = Script}); end @@ -567,8 +567,7 @@ local function get_chosen_scripts (rules) local t, path = cnse.fetchscript(filename); if t == "file" then if not files_loaded[path] then - script = Script.new(path); - chosen_scripts[#chosen_scripts+1] = script; + chosen_scripts[#chosen_scripts+1] = Script.new(path); files_loaded[path] = true; -- do not break so other rules can be marked as used end @@ -599,10 +598,9 @@ local function get_chosen_scripts (rules) if t == nil then error("'"..rule.."' did not match a category, filename, or directory"); elseif t == "file" and not files_loaded[path] then - local script = Script.new(path); - script.selected_by_name = true; + local script = Script.new(path, true); chosen_scripts[#chosen_scripts+1] = script; - print_debug(2, "Script %s was selected by name.", script.filename); + print_debug(2, "Script %s was selected by name.", path); files_loaded[path] = true; elseif t == "directory" then for f in cnse.dir(path) do