MCPcopy Index your code
hub / github.com/Shopify/go-lua / Arith

Method Arith

lua.go:715–729  ·  view source on GitHub ↗

Arith performs an arithmetic operation over the two values (or one, in case of negation) at the top of the stack, with the value at the top being the second operand, ops these values and pushes the result of the operation. The function follows the semantics of the corresponding Lua operator (that is

(op Operator)

Source from the content-addressed store, hash-verified

713//
714// http://www.lua.org/manual/5.2/manual.html#lua_arith
715func (l *State) Arith(op Operator) {
716 if op != OpUnaryMinus {
717 l.checkElementCount(2)
718 } else {
719 l.checkElementCount(1)
720 l.push(l.stack[l.top-1])
721 }
722 o1, o2 := l.stack[l.top-2], l.stack[l.top-1]
723 if n1, n2, ok := pairAsNumbers(o1, o2); ok {
724 l.stack[l.top-2] = arith(op, n1, n2)
725 } else {
726 l.stack[l.top-2] = l.arith(o1, o2, tm(op-OpAdd)+tmAdd)
727 }
728 l.top--
729}
730
731// RawEqual verifies that the values at index1 and index2 are primitively
732// equal (that is, without calling their metamethods).

Callers

nothing calls this directly

Calls 6

checkElementCountMethod · 0.95
pushMethod · 0.95
arithMethod · 0.95
pairAsNumbersFunction · 0.85
arithFunction · 0.85
tmTypeAlias · 0.85

Tested by

no test coverage detected