# # patch "ChangeLog" # from [aeaa70dc60e7ea72725657887f24f35d9715e6fb] # to [ca125534ab1a91128443d096c29f3eddc4e51936] # # patch "lua.cc" # from [174258e3ab931585b49e5490ffd82c83257bf63e] # to [8ce1c41f34fb0b52d6b4ba1646f5ed782835cc03] # # patch "testsuite.at" # from [00f75eef6202608c3cdfb512a2ef98014dda907a] # to [ba4c8f075ffc9901c34429f102f05e9703f251d3] # --- ChangeLog +++ ChangeLog @@ -1,5 +1,17 @@ 2005-05-08 Matthew Gregan + * lua.cc (report_error, load{file,string}): New member functions. + Error handling in call moved into report_error. + (call): Call report_error. + (run_{file,string}): Call load{file,string} member functions to + load Lua code into the VM. Allows us to report syntax errors when + loading rc files. + * testsuite.at: test_hooks.lua was calling nonexistent (obsolete) + strfind function and failing silently. The improved error + reporting from Lua caught this and cause testsuite failures. + +2005-05-08 Matthew Gregan + * monotone.1: Document --pid-file option. Also make some minor spelling and punctuation fixes. --- lua.cc +++ lua.cc @@ -8,6 +8,7 @@ extern "C" { #include #include +#include } #include @@ -217,6 +218,15 @@ { return !failed; } + + void report_error() + { + I(lua_isstring(st, -1)); + string err = string(lua_tostring(st, -1), lua_strlen(st, -1)); + W(F("%s\n") % err); + lua_pop(st, 1); + failed = true; + } // getters @@ -453,11 +463,7 @@ I(lua_checkstack (st, out)); if (lua_pcall(st, in, out, 0) != 0) { - I(lua_isstring (st, -1)); - string err = string(lua_tostring(st, -1), lua_strlen(st, -1)); - L(F("lua pcall() failed: %s\n") % err); - lua_pop(st, 1); - failed = true; + report_error(); } return *this; } @@ -492,6 +498,29 @@ return *this; } + Lua & loadstring(string const & str) + { + if (!failed) + { + if (luaL_loadbuffer(st, str.c_str(), str.size(), "")) + { + report_error(); + } + } + return *this; + } + + Lua & loadfile(string const & filename) + { + if (!failed) + { + if (luaL_loadfile(st, filename.c_str())) + { + report_error(); + } + } + return *this; + } }; std::set Lua::missing_functions; @@ -502,10 +531,8 @@ I(st); return Lua(st) - .func("loadstring") - .push_str(str) - .call(1,1) - .call(0,0) + .loadstring(str) + .call(0,1) .ok(); } @@ -515,10 +542,8 @@ I(st); return Lua(st) - .func("loadfile") - .push_str(filename) - .call(1,1) - .call(0,0) + .loadfile(filename) + .call(0,1) .ok(); } --- testsuite.at +++ testsuite.at @@ -118,8 +118,8 @@ end function ignore_file(name) - if (strfind(name, "test_hooks.lua")) then return true end - if (strfind(name, "test.db")) then return true end + if (string.find(name, "test_hooks.lua")) then return true end + if (string.find(name, "test.db")) then return true end return false end