Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pairs() consided harmful (Metatable with metatable) #1625

Closed
SoniEx2 opened this issue Jan 21, 2016 · 7 comments
Closed

pairs() consided harmful (Metatable with metatable) #1625

SoniEx2 opened this issue Jan 21, 2016 · 7 comments
Milestone

Comments

@SoniEx2
Copy link
Contributor

SoniEx2 commented Jan 21, 2016

This code behaves differently in OC vs the standalone Lua interpreter:

local t = {}
local mt = {
  __index = {"1", "2", "3", test="hi"}, -- index 
  __gc = function() end -- dummy __gc, to trigger bug
}
local mtmt = {
  __pairs = function() -- dummy __pairs that returns an empty iterator
    return next, {}, nil
  end
}
setmetatable(mt, mtmt) -- needs to be done first
setmetatable(t, mt) -- trigger bug
-- ok so now let's test our __index shall we?
print(t[1], t[2], t[3], t.test) -- nil, nil, nil, nil
-- wait what?! it doesn't work!

Proposed solution: change setmetatable() to use for k, v in next, t do.

@SoniEx2 SoniEx2 changed the title Usage of pairs() can cause issues (Metatable with metatable) pairs() consided harmful (Metatable with metatable) Jan 26, 2016
@RyanSquared
Copy link
Contributor

I lost all faith in you the second I saw you write "pairs() considered harmful" - it's not harmful, it's just not usable in this spot.

@SoniEx2
Copy link
Contributor Author

SoniEx2 commented Jan 26, 2016

@ChickenNuggers I know but extortion tactics.

@skyem123
Copy link
Contributor

You do know, when people get annoyed at you (like most OC people), titles like this are more likely to make them ignore it...

@SoniEx2
Copy link
Contributor Author

SoniEx2 commented Jan 26, 2016

@skyem123 Really? Because people started paying attention when I changed it to this...

@RyanSquared
Copy link
Contributor

I mainly just called you an idiot because I saw you mention it elsewhere, a channel we unfortunately share.

@skyem123
Copy link
Contributor

I would have checked it anyway... >_<

@fnuecke
Copy link
Member

fnuecke commented Jan 31, 2016

Next time, just make a PR, and don't be a passive-aggressive dick about it.

@MightyPirates MightyPirates locked and limited conversation to collaborators Jan 31, 2016
@fnuecke fnuecke added this to the v1.6.0 milestone Jan 31, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants