From 427f4a13c365feeb81ca9a97aaaa251f590f19f4 Mon Sep 17 00:00:00 2001 From: Michal Kottman Date: Tue, 13 Apr 2010 13:02:16 +0200 Subject: [PATCH] mode verbose error messages --- common/lqt_common.cpp | 7 +++++++ common/lqt_common.hpp | 1 + generator/classes.lua | 11 +++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/common/lqt_common.cpp b/common/lqt_common.cpp index e8e6ddc..39ed3fe 100644 --- a/common/lqt_common.cpp +++ b/common/lqt_common.cpp @@ -496,6 +496,13 @@ bool lqtL_testudata (lua_State *L, int index, const char *name) { return true; } +void lqtL_pushtrace(lua_State *L) { + lua_getglobal(L, "debug"); + lua_getfield(L, -1, "traceback"); + lua_remove(L, -2); + lua_call(L, 0, 1); +} + void lqtL_pushenum (lua_State *L, int value, const char *name) { lqtL_getenumtable(L); lua_getfield(L, -1, name); diff --git a/common/lqt_common.hpp b/common/lqt_common.hpp index 1388b7f..47e81c0 100644 --- a/common/lqt_common.hpp +++ b/common/lqt_common.hpp @@ -155,5 +155,6 @@ const char * lqtL_source(lua_State *L, int idx); bool lqtL_is_super(lua_State *L, int idx); int lqtL_register_super(lua_State *L); +void lqtL_pushtrace(lua_State *L); #endif // __LQT_COMMON_HPP diff --git a/generator/classes.lua b/generator/classes.lua index a148989..6b5d375 100644 --- a/generator/classes.lua +++ b/generator/classes.lua @@ -330,7 +330,9 @@ function fill_wrapper_code(f, types) stackn = stackn + sn wrap = wrap .. [[ if (NULL==self) { - lua_pushstring(L, "this pointer is NULL"); + lua_pushfstring(L, "Instance of %s has already been deleted in:\n", "]]..f.xarg.member_of_class..[["); + lqtL_pushtrace(L); + lua_concat(L, 2); lua_error(L); } ]] @@ -541,12 +543,13 @@ local print_metatable = function(c) local name = operators.rename_operator(n) local disp = 'static int lqt_dispatcher_'..name..c.xarg.id..' (lua_State *L) {\n' local testcode = {} - for _, f in pairs(l) do + for tc, f in pairs(l) do disp = disp..' if ('..f.test_code..') return lqt_bind'..f.xarg.id..'(L);\n' - testcode[#testcode+1] = _ + testcode[#testcode+1] = tc end disp = disp .. ' lua_settop(L, 0);\n' - disp = disp .. ' lua_pushstring(L, "'..c.xarg.fullname..'::'..n..': incorrect or extra arguments, expecting: "' .. string.format("%q", table.concat(testcode, " or ")) .. ');\n' + disp = disp .. ' lua_pushfstring(L, "%s: incorrect or extra arguments, expecting: %s", "' .. + c.xarg.fullname..'::'..n..'", '..string.format("%q", table.concat(testcode, ' or ')) .. ');\n' disp = disp .. ' return lua_error(L);\n}\n' --print_meta(disp) wrappers = wrappers .. disp .. '\n' -- 2.11.4.GIT