Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How do I properly set up the __index function?

Asked by 3 years ago

I don't know why, but I literally forgot how to do that. I use __index for all my modules, but it is just doing setmetatable(table,{__index = table)}) so I don't remember how to set up the actual function. It was something like this:

local tab = {}
local tabMT = {

function tab.__index()
    return 1
end

}

however, it does not work.

1 answer

Log in to vote
1
Answered by 3 years ago

__index is set up like so:

local tab = {}
local mt = {

    __index = function()

        return 1

    end

}

setmetatable(tab,mt) -- and you can setmetatable, idk if you forgot to do that but just leaving it here
0
Thanks! User#32819 0 — 3y
Ad

Answer this question