From c01833da4ed32392f96a03f163e86a96297ced2b Mon Sep 17 00:00:00 2001 From: Daniel Wallin Date: Tue, 20 May 2003 22:22:09 +0000 Subject: [PATCH] inspector reports all defines that are not undef'ed in the same file --- examples/filesystem/inspect.lua | 28 +++++++++++++++++++++++++++- luabind/detail/object_rep.hpp | 2 +- src/class_rep.cpp | 12 ++++++++++-- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/examples/filesystem/inspect.lua b/examples/filesystem/inspect.lua index 62942d0..195ce4f 100755 --- a/examples/filesystem/inspect.lua +++ b/examples/filesystem/inspect.lua @@ -104,6 +104,31 @@ class 'line_length_inspector' (inspector) end end +-- checks that the file doesn't contain too long lines +class 'define_inspector' (inspector) + + function define_inspector:__init() + super("define inspector") + end + + function define_inspector:inspect(path) + if has_endings(path:leaf(), ".hpp") then + + local defs = {} + + for line in io.lines(path:string()) do + local pos, _, def = string.find(line, "#%s*define%s+([%w_]+)") + if pos ~= nil then defs[def] = true end + local pos, _, def = string.find(line, "#%s*undef%s+([%w_]+)") + if pos ~= nil then defs[def] = nil end + end + + table.foreach(defs, function(def) + self:warning(path, def) + end) + end + end + -- helper functions function file_ending(name) @@ -137,7 +162,8 @@ end -- main inspectors = { filename_length(31), filename_case(), - tab_inspector(), line_length_inspector(79) } + tab_inspector(), line_length_inspector(79), + define_inspector() } number_of_files = 0 if args.n >= 3 then root = filesystem.path(args[3]) diff --git a/luabind/detail/object_rep.hpp b/luabind/detail/object_rep.hpp index 8cbde56..fa3c56b 100644 --- a/luabind/detail/object_rep.hpp +++ b/luabind/detail/object_rep.hpp @@ -141,7 +141,7 @@ namespace luabind { namespace detail class_rep* m_classrep; // the class information about this object's type int m_flags; int m_lua_table_ref; // reference to lua table if this is a lua class - void(*m_destructor)(void*); // this could be in class_rep? + void(*m_destructor)(void*); // this could be in class_rep? it can't: see intrusive_ptr int m_dependency_cnt; // counts dependencies int m_dependency_ref; // reference to lua table holding dependency references }; diff --git a/src/class_rep.cpp b/src/class_rep.cpp index 5e51d28..5f80773 100755 --- a/src/class_rep.cpp +++ b/src/class_rep.cpp @@ -1221,7 +1221,11 @@ void luabind::detail::class_rep::add_static_constant(const char* name, int val) lua_pushvalue(L, 2); lua_gettable(L, -2); - if (!lua_isnil(L, -1)) return 1; + if (!lua_isnil(L, -1)) + { + lua_remove(L, -2); // remove table + return 1; + } lua_pop(L, 2); @@ -1229,7 +1233,11 @@ void luabind::detail::class_rep::add_static_constant(const char* name, int val) lua_pushvalue(L, 2); lua_gettable(L, -2); - if (!lua_isnil(L, -1)) return 1; + if (!lua_isnil(L, -1)) + { + lua_remove(L, -2); // more table + return 1; + } lua_pop(L, 2); -- 2.11.4.GIT