diff --git a/src/API.cpp b/src/API.cpp index 3e2624a3c..718103d72 100644 --- a/src/API.cpp +++ b/src/API.cpp @@ -490,10 +490,9 @@ bool API::callProgramHook ( throw std::string ("Error calling '") + function + "' - " + lua_tostring (L, -1); // Call successful - get return values. - // 0, nil -> success - // 0, string -> warning - // 1, string -> error if (!lua_isnumber (L, -2)) throw std::string ("Error: '") + function + "' did not return a success indicator"; + +// TODO This doesn't seem to know that 'nil' was returned instead of a string. // if (!lua_isstring (L, -1)) throw std::string ("Error: '") + function + "' did not return a message"; int rc = lua_tointeger (L, -2); @@ -507,7 +506,7 @@ bool API::callProgramHook ( else { if (message) - throw std::string ("Error: ") + message; + throw std::string (message); } lua_pop (L, 1); diff --git a/src/Context.cpp b/src/Context.cpp index 8233fceb7..d45e157c4 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -194,8 +194,7 @@ int Context::dispatch (std::string &out) Timer t ("Context::dispatch"); - if (! hooks.trigger ("pre-dispatch")) - return rc; + hooks.trigger ("pre-dispatch"); // TODO Just look at this thing. It cries out for a dispatch table. if (cmd.command == "projects") { rc = handleProjects (out); } diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 99bbbfdde..90715df58 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -101,17 +101,22 @@ bool Hooks::trigger (const std::string& event) { if (it->event == event) { + bool rc = true; std::string type; if (eventType (event, type)) { // TODO Figure out where to get the calling-context info from. - if (type == "program") return api.callProgramHook (it->file, it->function); - else if (type == "list") return api.callListHook (it->file, it->function/*, tasks*/); - else if (type == "task") return api.callTaskHook (it->file, it->function, 0); - else if (type == "field") return api.callFieldHook (it->file, it->function, "field", "value"); + if (type == "program") rc = api.callProgramHook (it->file, it->function); + else if (type == "list") rc = api.callListHook (it->file, it->function/*, tasks*/); + else if (type == "task") rc = api.callTaskHook (it->file, it->function, 0); + else if (type == "field") rc = api.callFieldHook (it->file, it->function, "field", "value"); } else throw std::string ("Unrecognized hook event '") + event + "'"; + + // If any hook returns false, stop. + if (!rc) + return false; } } #endif