C stack overflow when newindex encouters a undefined value

Hello. I was messing around trying to do oop proxies, but I encoutered a c stack overflow issue. Here is the script. Also, is this a mistake on my side or is this a roblox issue?

local t = setmetatable({x = 5}, {__index = function(t, key)
		print("User indexed t with "..key)
		return t[key]
	end,
	__newindex = function(t, key, value)
		print("updated or changed ".. key.. " in "..t.. " with the value".. value)
		t[key] = value
	end
	
})

print(t.x)
print(t.y)

Screen Shot 2020-08-27 at 10.24.02 PM
If I can get a answer please I would be really thankful for it!

t[key] invokes your __index metamethod again, indefinitely - after 200 invocations or so you can’t do this anymore.

You should use return rawget(t, key) and rawset(t, key, value) instead.

3 Likes