Does anyone know of a better way to nest the 'this' table while still being able to use it as a dictionary? It looks ugly and I'm blanking.
local bank = {}
bank.__index = bank
setmetatable(bank, {
__index = function(ogt, bank_id)
-- Converting to a dictionary and nesting 'this'
ogt[bank_id] = {}
local this = ogt[bank_id]
this.balance = 0
this.banker = bank_id
setmetatable(this, bank)
return this
end
})
function bank:withdraw(how_much)
self.balance = self.balance - how_much
return self.balance
end
function bank:deposit(how_much)
self.balance = self.balance + how_much
return self.balance
end
function bank:get_balance()
return self.balance
end
function bank:set_balance(how_much)
self.balance = how_much
return self.balance
end
print(bank['person299']:set_balance(10))
`

1 comment
Thanks, but that's not what I mean :3