From eef62c82a2e58700fc1216b0b8c03e421bc77995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Sat, 30 Jun 2018 17:11:38 +0200 Subject: Modernize lua read (part 2 & 3): C++ templating assurance (#7410) * Modernize lua read (part 2 & 3): C++ templating assurance Implement the boolean reader Implement the string reader Also remove unused & unimplemented script_error_handler Add a reader with default value --- src/script/cpp_api/s_base.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/script/cpp_api/s_base.cpp') diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index 54ff8c495..293c774b0 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -133,7 +133,7 @@ int ScriptApiBase::luaPanic(lua_State *L) { std::ostringstream oss; oss << "LUA PANIC: unprotected error in call to Lua API (" - << lua_tostring(L, -1) << ")"; + << readParam(L, -1) << ")"; FATAL_ERROR(oss.str().c_str()); // NOTREACHED return 0; @@ -184,7 +184,7 @@ void ScriptApiBase::loadScript(const std::string &script_path) } ok = ok && !lua_pcall(L, 0, 0, error_handler); if (!ok) { - std::string error_msg = lua_tostring(L, -1); + std::string error_msg = readParam(L, -1); lua_pop(L, 2); // Pop error message and error handler throw ModError("Failed to load and run script from " + script_path + ":\n" + error_msg); @@ -286,10 +286,10 @@ void ScriptApiBase::stackDump(std::ostream &o) int t = lua_type(m_luastack, i); switch (t) { case LUA_TSTRING: /* strings */ - o << "\"" << lua_tostring(m_luastack, i) << "\""; + o << "\"" << readParam(m_luastack, i) << "\""; break; case LUA_TBOOLEAN: /* booleans */ - o << (lua_toboolean(m_luastack, i) ? "true" : "false"); + o << (readParam(m_luastack, i) ? "true" : "false"); break; case LUA_TNUMBER: /* numbers */ { char buf[10]; -- cgit v1.2.3