From db9e8e751c164a6d8f5d442c3527b2e72c54474c Mon Sep 17 00:00:00 2001 From: david Date: Fri, 2 Jan 2009 19:21:27 +0000 Subject: [PATCH] Add some more documentation to process_preparethread to note what's on the thread's stack when it is initialized. --- nse_main.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/nse_main.cc b/nse_main.cc index 24cc278d8..fff10f7ac 100644 --- a/nse_main.cc +++ b/nse_main.cc @@ -736,10 +736,17 @@ int process_pickScriptsForPort(lua_State* L, Target* target, Port* port, std::li return SCRIPT_ENGINE_SUCCESS; } -/* Create a new lua thread and prepare it for execution - * we store target info in the thread so that the mainloop - * knows where to put the script result. File closure is expected - * at stack index -2. +/* Create a new lua thread and prepare it for execution we store target info in + * the thread so that the mainloop knows where to put the script result. File + * closure is expected at stack index -2. (Index -1 has the boolean result of + * the hostrule or portrule, not used here.) + * + * The thread will have on its stack 3 values if it is a host script, or 4 if it + * is a port script: + * 1: environment table + * 2: action closure + * 3: host table + * 4: port table (port scripts only) * */ int process_preparethread(lua_State* L, struct thread_record *tr){ @@ -772,9 +779,9 @@ int process_preparethread(lua_State* L, struct thread_record *tr){ tr->runlevel = lua_tonumber(L, -1); lua_pop(L, 1); - // move the script action closure into the thread + // move the environment table and script action closure into the thread lua_getfield(L, -1, ACTION); // action closure - lua_xmove(L, thread, 2); + lua_xmove(L, thread, 2); // env, action lua_pop(L, 1); // filename lua_setfenv(L, -2); // reset old env lua_pop(L, 1); // file closure