1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-12-26 07:33:21 -05:00

Lua balances: Fix order of operands pulled in

This commit is contained in:
Aaron Lindsay 2017-11-08 20:44:34 -05:00
parent 5daed2f508
commit bca3e3b408

View File

@ -56,23 +56,12 @@ func luaWeakCheckBalance(L *lua.LState, n int) *Balance {
return nil return nil
} }
func luaGetBalanceOperands(L *lua.LState, n int, m int) (*Balance, *Balance) { func luaGetBalanceOperands(L *lua.LState, m int, n int) (*Balance, *Balance) {
bn := luaWeakCheckBalance(L, n)
bm := luaWeakCheckBalance(L, m) bm := luaWeakCheckBalance(L, m)
bn := luaWeakCheckBalance(L, n)
if bn != nil && bm != nil { if bm != nil && bn != nil {
return bn, bm return bm, bn
} else if bn != nil {
nm := L.CheckNumber(m)
var balance Balance
var rat big.Rat
balance.Security = bn.Security
balance.Amount = rat.SetFloat64(float64(nm))
if balance.Amount == nil {
L.ArgError(n, "non-finite float invalid for operand to balance arithemetic")
return nil, nil
}
return bn, &balance
} else if bm != nil { } else if bm != nil {
nn := L.CheckNumber(n) nn := L.CheckNumber(n)
var balance Balance var balance Balance
@ -84,8 +73,19 @@ func luaGetBalanceOperands(L *lua.LState, n int, m int) (*Balance, *Balance) {
return nil, nil return nil, nil
} }
return bm, &balance return bm, &balance
} else if bn != nil {
nm := L.CheckNumber(m)
var balance Balance
var rat big.Rat
balance.Security = bn.Security
balance.Amount = rat.SetFloat64(float64(nm))
if balance.Amount == nil {
L.ArgError(m, "non-finite float invalid for operand to balance arithemetic")
return nil, nil
}
return &balance, bn
} }
L.ArgError(n, "balance expected") L.ArgError(m, "balance expected")
return nil, nil return nil, nil
} }