MCPcopy Index your code
hub / github.com/yuin/gopher-lua / objectArith

Function objectArith

_vm.go:885–928  ·  view source on GitHub ↗
(L *LState, opcode int, lhs, rhs LValue)

Source from the content-addressed store, hash-verified

883}
884
885func objectArith(L *LState, opcode int, lhs, rhs LValue) LValue {
886 event := ""
887 switch opcode {
888 case OP_ADD:
889 event = "__add"
890 case OP_SUB:
891 event = "__sub"
892 case OP_MUL:
893 event = "__mul"
894 case OP_DIV:
895 event = "__div"
896 case OP_MOD:
897 event = "__mod"
898 case OP_POW:
899 event = "__pow"
900 }
901 op := L.metaOp2(lhs, rhs, event)
902 if _, ok := op.(*LFunction); ok {
903 L.reg.Push(op)
904 L.reg.Push(lhs)
905 L.reg.Push(rhs)
906 L.Call(2, 1)
907 return L.reg.Pop()
908 }
909 if str, ok := lhs.(LString); ok {
910 if lnum, err := parseNumber(string(str)); err == nil {
911 lhs = lnum
912 }
913 }
914 if str, ok := rhs.(LString); ok {
915 if rnum, err := parseNumber(string(str)); err == nil {
916 rhs = rnum
917 }
918 }
919 if v1, ok1 := lhs.(LNumber); ok1 {
920 if v2, ok2 := rhs.(LNumber); ok2 {
921 return numberArith(L, opcode, LNumber(v1), LNumber(v2))
922 }
923 }
924 L.RaiseError(fmt.Sprintf("cannot perform %v operation between %v and %v",
925 strings.TrimLeft(event, "_"), lhs.Type().String(), rhs.Type().String()))
926
927 return LNil
928}
929
930func stringConcat(L *LState, total, last int) LValue {
931 rhs := L.reg.Get(last)

Callers 1

opArithFunction · 0.70

Calls 10

parseNumberFunction · 0.85
LNumberTypeAlias · 0.85
numberArithFunction · 0.70
PushMethod · 0.65
PopMethod · 0.65
StringMethod · 0.65
TypeMethod · 0.65
metaOp2Method · 0.45
CallMethod · 0.45
RaiseErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…