Yepessin / slb

Automatically exported from code.google.com/p/slb
0 stars 0 forks source link

Error messages get stomped when loading files #17

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When attempting to load a file with syntax or other errors, SLB checks the 
return status of luaL_loadfile and sets _lastError appropriately. However, it 
then goes on to unconditionally try to execute the loaded object, which in the 
case of an error may not be a function. 

The result is an unhelpful error message like

    SLB Exception: 
    -------------------------------------------------------
    Lua Error:
            attempt to call a string value
    Traceback:
             [ 0 (C) ] 

Applying a patch like

diff --git a/src/Script.cpp b/src/Script.cpp
--- a/src/Script.cpp
+++ b/src/Script.cpp
@@ -171,7 +171,7 @@ namespace SLB {
     }

     // otherwise...
-    if( _errorHandler->call(_lua_state, 0, 0))
+    if(result && _errorHandler->call(_lua_state, 0, 0))
     {
       _lastError = lua_tostring(L,-1);
       result = false;

seems to produce more appropriate error messages, such as

    cannot open test1.lua: No such file or directory

or

    test1.lua:41: syntax error near <eof>

Original issue reported on code.google.com by str...@google.com on 21 Aug 2012 at 5:10

GoogleCodeExporter commented 8 years ago
ACK, thanks!

Original comment by joseLuis...@gmail.com on 28 Aug 2012 at 7:11