lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I have some code that I want to use to add an invert method to tables.

table.invert = function (t)
	local i = {}
	for k in pairs(t) do
		i[t[k]] = true
	return i

When I call it as "table.invert(a)" it works fine, but it errors when I call it as "a:invert()"

lua: invert.lua:15: attempt to call method 'invert' (a nil value)

My understanding was that a:invert() was just sugar on table.invert(a), what am I doing wrong?