__index being ran multiple times?

MT.__index 	= function(this, index)
							if (not FinishedSetup) then return end
							local stack, string 		= {}, STR_LOWER(index);

							--[[for string in STR_GMATCH(string .. "or", "(%w-)or") do print(string);
								TABLE_INSERT(stack, string);
							end--]]
							print("Indexed", index);
							return true
						end

So I have a ModuleScript that includes a metatable, and the metatable has a __index metamethod in it.
Whenever I try to index this ModuleScript, it should print “Indexed” once, like this:

	local a 			= typer.Boolean
-- expected output
-- Indexed, Boolean

Instead, the function is called multiple times for seemingly no reason.

local a = typer.Boolean
--> Indexed Boolean (x4)

What am I missing?

Use assert(false) on different recurrences of the __index function call so you can see the call stack (and hopefully what code is indexing the table)

1 Like