No pairs metamethod?

Soo… in the Lua 5.2, there is a reference to a metamethod that can be called when using pairs on a metatable, however, when I actually do it, it no work. Any thoughts?

local Gui = {}
Gui.__index = Gui
Gui.__pairs = function(tbl)
	return function(tbl, k)
		local v 
		k,v = next(tbl, k)
		if v and type(v) == "table" then 
			return k,v
		end
	end, tbl, nil
end
1 Like

Roblox uses Lua 5.1.4. (30 30 30 characters)

1 Like

It’s rather that or they removed it from the api reference. Roblox does that a lot (io.read(), etc)

well thats rather mean of them if you ask me, this only due to my stubborn nature…

Look at these developers, making me have to rewrite their own functions :frowning:

local specialpairs = function(tbl)
	tbl.Object = nil
	return function(tbl, k)
		local v 
		k,v = next(tbl, k)
		if v and type(v) == "table" then 
			return k,v
		end
	end, tbl, nil
end
1 Like

Don’t know if they removed it or if it doesn’t support it. But I do know io.read() was removed because there’s already gui objects and io.read() is for the console (Vannila Lua).

The io library was intentionally disabled, but __pairs just doesn’t work because Roblox uses an old version of Lua. You were right the first time.

3 Likes