Fix process example in README

master
kikito 10 years ago
parent 33af4ee2ea
commit c22d3381e7
  1. 8
      README.md

@ -182,17 +182,17 @@ end
assert(inspect(t, {process = remove_mt}) == "{ 1, 2, 3 }") assert(inspect(t, {process = remove_mt}) == "{ 1, 2, 3 }")
``` ```
The previous exaple only works for a particular metatable. If you want to make *all* metatables, you can use `path`: The previous exaple only works for a particular metatable. If you want to make *all* metatables, you can use the `path` parameter to check
wether the last element is `inspect.METATABLE`, and return `nil` instead of the item:
``` lua ``` lua
local t, mt = ... -- (defined as before) local t, mt = ... -- (defined as before)
local remove_all_metatables = function(item, path) local remove_all_metatables = function(item, path)
if path[#path] ~= '<metatable>' then return item end if path[#path] ~= inspect.METATABLE then return item end
end end
-- Removes all metatables assert(inspect(t, {process = remove_all_metatables}) == "{ 1, 2, 3 }")
assert(inspect(t, {process = remove_mt}) == "{ 1, 2, 3 }")
``` ```
Filter a value: Filter a value:

Loading…
Cancel
Save