Comments (5)
@justinmk that is a good point. I don't have a lot of bandwith to do the writing part right now, but send me a PR if you want and I'll review.
I have created the workaround
label and applied it to the items you mentioned.
from inspect.lua.
from factorio stdlib
local function no_meta(item, path)
if path[#path] == inspect.METATABLE then
return {item.__class}
end
return item
end
--- Inspect the class
function Core.inspect(self)
return inspect(self, {process = no_meta})
end
from inspect.lua.
@vyacheslav-nosov thank you for the answer but this solution removes __tostring
comments from output
from inspect.lua.
I don't think this will be ever implemented on this library.
May I suggest using this instead:
local inspect = require "inspect"
local function no_meta_with_description(item, path)
if path[#path] == inspect.METATABLE then
return { __tostring = item.__tostring }
end
return item
end
local function my_inspect(t)
return inspect(t, {process = no_meta_with_description})
end
--- tests:
local person_mt = {
__tostring = function(t) return "A person named " .. t.name end
}
-- add 100 fields to person_mt
for i=1,100 do
person_mt["field" .. tostring(i)] = true
end
local peter = setmetatable({ name = "peter" }, person_mt)
local john = setmetatable({ name = "john" }, person_mt)
print(my_inspect(peter))
print(my_inspect(john))
The output will be similar to what you want. Tables will have their __tostring
comments. They will still have a metatable field, but it will be very small, with only one field.
{ -- A person named peter
name = "peter",
<metatable> = {
__tostring = <function 1>
}
}
{ -- A person named john
name = "john",
<metatable> = {
__tostring = <function 1>
}
}
I hope this is an acceptable compromise.
from inspect.lua.
@kikito for all of these "wontfix" it will avoid a lot of confusion if the workarounds you mention, are documented in https://github.com/kikito/inspect.lua#examples-of-use . Or at least, mark these issues with a tag like wontfix
or workaround
and link to that issue search from the readme.
from inspect.lua.
Related Issues (20)
- Incompatible with luvit or the Discordia library HOT 16
- custom __metatable metafield that is not nil or table breaks inspecting HOT 3
- Printing with metatable's "__tostring" if userdata has it? HOT 9
- Error when inspecting table returned by luaposix.dir HOT 3
- inspect does not render non printable values correctly HOT 7
- "Array"-style display option for tables HOT 2
- Error: attempt to compare number with nil HOT 3
- Option to display strings with newlines as multi-line strings HOT 1
- Use dofile in Gideros HOT 1
- Looks strange with `inspect {{ x = 1 }}` HOT 3
- PERF: countCycles doesn't respect options.depth HOT 1
- No option to print lua table in one line HOT 1
- How to remove `<table id>`? HOT 2
- Lua crashes when inspecting _G HOT 6
- Idea: integration with middleclass
- compat requirement unmentioned in installation guide HOT 1
- inspect option to output binary value as hex codes instead of escaped characters
- Use LuaBuffers in LuaJIT
- Typo in the examples, oops
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inspect.lua.