From 8540cab0a6109134be6dd71a586ee5bb14ccbf4e Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 19 Jan 2010 22:19:40 -0500 Subject: [PATCH] Enhancement - hooks - Improved diagnostics of C++ side of the Lua API. --- src/API.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/API.cpp b/src/API.cpp index fa10f321e..566692710 100644 --- a/src/API.cpp +++ b/src/API.cpp @@ -491,10 +491,11 @@ bool API::callProgramHook ( throw std::string ("Error calling '") + function + "' - " + lua_tostring (L, -1); // Call successful - get return values. - if (!lua_isnumber (L, -2)) throw std::string ("Error: '") + function + "' did not return a success indicator"; + 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"; + if (!lua_isstring (L, -1) && !lua_isnil (L, -1)) + throw std::string ("Error: '") + function + "' did not return a message or nil"; int rc = lua_tointeger (L, -2); const char* message = lua_tostring (L, -1);