Can someone kindly explain the reason why I see this error ?
[code]
tax = {
_income = 0,
_rate = 0,
_tax = 0
}
tax.init = function (pIncome, pRate)
tax._income = pIncome
tax._rate = pRate
end
tax.setIncome = function (pIncome)
tax._income = pIncome
end
tax.getIncome = function ()
return tax._income
end
tax.setRate = function (pRate)
tax._rate = pRate
end
tax.getRate = function ()
return tax._rate
end
tax.getTax = function ()
tax._tax = tax._income * tax._rate
return tax._tax
end
tax:init(12200, 12)
print(tax:getIncome(), tax:getRate())
print(tax:getTax())
[/code]
[error]
>lua -e "io.stdout:setvbuf 'no'" "13.lua"
table: 0028CA00 12200
lua: 13.lua:30: attempt to perform arithmetic on field '_income' (a table value)
stack traceback:
13.lua:30: in function 'getTax'
13.lua:36: in main chunk
[C]: ?
>Exit code: 1
[/error]
What is the problem in doing arithmetic on the table-field ? On the interactive lua console, if I try to do the following:
[interactive-console]
> t = {}
> t[1] = 2
> t[2] = 3
> print(t[1]*t[2])
6
[/interactive-console]
So, there doesn't seem to be any issue in doing arithmetic with table fields !!