Giter Club home page Giter Club logo

Comments (5)

kikito avatar kikito commented on May 26, 2024 1

@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.

vyacheslav-nosov avatar vyacheslav-nosov commented on May 26, 2024

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.

lua-rocks avatar lua-rocks commented on May 26, 2024

@vyacheslav-nosov thank you for the answer but this solution removes __tostring comments from output

from inspect.lua.

kikito avatar kikito commented on May 26, 2024

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.

justinmk avatar justinmk commented on May 26, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.