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

Function objectArith

vm.go:2301–2344  ·  view source on GitHub ↗
(L *LState, opcode int, lhs, rhs LValue)

Source from the content-addressed store, hash-verified

2299}
2300
2301func objectArith(L *LState, opcode int, lhs, rhs LValue) LValue {
2302 event := ""
2303 switch opcode {
2304 case OP_ADD:
2305 event = "__add"
2306 case OP_SUB:
2307 event = "__sub"
2308 case OP_MUL:
2309 event = "__mul"
2310 case OP_DIV:
2311 event = "__div"
2312 case OP_MOD:
2313 event = "__mod"
2314 case OP_POW:
2315 event = "__pow"
2316 }
2317 op := L.metaOp2(lhs, rhs, event)
2318 if _, ok := op.(*LFunction); ok {
2319 L.reg.Push(op)
2320 L.reg.Push(lhs)
2321 L.reg.Push(rhs)
2322 L.Call(2, 1)
2323 return L.reg.Pop()
2324 }
2325 if str, ok := lhs.(LString); ok {
2326 if lnum, err := parseNumber(string(str)); err == nil {
2327 lhs = lnum
2328 }
2329 }
2330 if str, ok := rhs.(LString); ok {
2331 if rnum, err := parseNumber(string(str)); err == nil {
2332 rhs = rnum
2333 }
2334 }
2335 if v1, ok1 := lhs.(LNumber); ok1 {
2336 if v2, ok2 := rhs.(LNumber); ok2 {
2337 return numberArith(L, opcode, LNumber(v1), LNumber(v2))
2338 }
2339 }
2340 L.RaiseError(fmt.Sprintf("cannot perform %v operation between %v and %v",
2341 strings.TrimLeft(event, "_"), lhs.Type().String(), rhs.Type().String()))
2342
2343 return LNil
2344}
2345
2346func stringConcat(L *LState, total, last int) LValue {
2347 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…