Comments (16)
Okay, I don't think I can reproduce this without using discordia and a bot token.
https://discordapp.com/developers/applications/me
local discordia = require('discordia')
local client = discordia.Client()
client:run('Bot INSERT_TOKEN_HERE')
inspect(client)
That should be enough, if it does not error it might require the bot to be in a guild.
from inspect.lua.
I would have to investigate this in more detail. In order to fix this issue I would need to be able to reproduce it in the first place. Do you think you can produce a minimal example showing the issue?
from inspect.lua.
I'll try to find a way to reproduce it without having to create a bot.
from inspect.lua.
Hi there @Tenrys,
Sorry it took me a little while to get back to you on this. I just pushed a change to master that might solve your issue with inspect.lua. Could you please that new version in discord?
from inspect.lua.
Got the same error, different line though
libs/inspect.lua:247: attempt to compare number with nil
from inspect.lua.
Wow that was fast. Please try again. I had a bit of a problem with git and had to repush.
from inspect.lua.
Well now it "works", it returns a stack overflow.
from inspect.lua.
Ok. Thanks for the quick response. I think something is not quite right with the change I made. I thought it was correct because my tests were locally passing but now it seems that I had a version of inspect installed via luarocks and it was used on the tests instead of using my dev one. I'm checking.
from inspect.lua.
I have removed the change from master and will continue working on a branch (as I should have). Apologies for the inconveniences.
from inspect.lua.
It's all good, I made a simple similar function for my own needs in the meantime and it works alright.
from inspect.lua.
For reference, here is what I'm getting when pretty-printing a newly created discordia client using vinspect: https://gist.github.com/mpeterv/64baa14b072a35077c7426053bcc386b
from inspect.lua.
So the problem is that inspect iterates over table pairs in two different ways and gets conflicting results. When counting table appearances it uses pairs
, but when pretty-printing tables it first iterates over array keys using rawget
, and only uses pairs
for remaining keys.
The problem is that a table within discordia client (client[6]
) overrides __pairs
so that pairs
returns no keys. As a result, tables within actual array part are not counted as appeared and so when they are discovered during pretty printing the error is thrown.
Testing:
local discordia = require "discordia"
local client = discordia.Client()
print("pairs():")
for key, value in pairs(client[6]) do
print(key, value)
end
print("rawget():")
for i = 1, 4 do
print(i, rawget(client[6], i))
end
print("raw pairs():")
getmetatable(client[6]).__pairs = nil
for key, value in pairs(client[6]) do
print(key, value)
end
Output:
pairs():
rawget():
1 0
2 table: 0x418f0cc8
3 class User
4 Client
raw pairs():
1 0
2 table: 0x418f0cc8
3 class User
4 Client
Replacing pairs(t)
with next, t
everywhere in inspect fixes the issue.
from inspect.lua.
(I wrote vinspect for 1. interactive inspection 2. situations like this where everything is broken (inspired by Penlight overriding type
with something returning tables... vinspect somewhat handles that), not sure if inspect needs to be that defensive particularly since it wants to avoid stuff like debug.metatable
, but in cases like this it couldn't hurt.)
from inspect.lua.
Wow, thanks for the analysis! I will certainly look at using next
instead of pairs
.
from inspect.lua.
@Tenrys can you try with the implementation that I put on the rawpairs branch?
https://github.com/kikito/inspect.lua/blob/rawpairs/inspect.lua
I changed it so that it always ignores __pairs
and __ipairs
, as mentioned by @mpeterv .
from inspect.lua.
I have merged rawpairs in the main branch now - it was solving a problem even if it didn't solve the problem (which I think is solved as well, but I'll leave this open for a while in case you want to try it out)
from inspect.lua.
Related Issues (20)
- 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
- Can you please make metatables output optionally disablable? HOT 5
- 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 HOT 1
- 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
- Buggy escape in smartQuote HOT 1
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.