mirror of
https://github.com/kikito/inspect.lua.git
synced 2025-01-02 01:44:19 +00:00
Fix process example in README
This commit is contained in:
parent
33af4ee2ea
commit
c22d3381e7
@ -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…
Reference in New Issue
Block a user