MCPcopy
hub / github.com/go-qml/qml / hookGoValueWriteField

Function hookGoValueWriteField

bridge.go:409–433  ·  view source on GitHub ↗

export hookGoValueWriteField

(enginep, foldp unsafe.Pointer, reflectIndex, setIndex C.int, assigndv *C.DataValue)

Source from the content-addressed store, hash-verified

407
408//export hookGoValueWriteField
409func hookGoValueWriteField(enginep, foldp unsafe.Pointer, reflectIndex, setIndex C.int, assigndv *C.DataValue) {
410 fold := ensureEngine(enginep, foldp)
411 v := reflect.ValueOf(fold.gvalue)
412 ve := v
413 for ve.Type().Kind() == reflect.Ptr {
414 ve = ve.Elem()
415 }
416 var field, setMethod reflect.Value
417 if reflectIndex >= 0 {
418 // It's a real field rather than a getter.
419 field = ve.Field(int(reflectIndex))
420 }
421 if setIndex >= 0 {
422 // It has a setter.
423 setMethod = v.Method(int(setIndex))
424 }
425
426 assign := unpackDataValue(assigndv, fold.engine)
427
428 // TODO Return false to the call site if it fails. That's how Qt seems to handle it internally.
429 err := convertAndSet(field, reflect.ValueOf(assign), setMethod)
430 if err != nil {
431 panic(err.Error())
432 }
433}
434
435func convertAndSet(to, from reflect.Value, setMethod reflect.Value) (err error) {
436 var toType reflect.Type

Callers

nothing calls this directly

Calls 3

ensureEngineFunction · 0.85
unpackDataValueFunction · 0.85
convertAndSetFunction · 0.85

Tested by

no test coverage detected