reflect: implement support for array types

This commit is contained in:
Ayke van Laethem
2019-08-16 22:08:44 +02:00
committed by Ron Evans
parent bbc3046687
commit c19c738f52
8 changed files with 184 additions and 20 deletions
+6 -2
View File
@@ -91,7 +91,8 @@ func main() {
[]complex128{1, 1.128 + 0.4i},
myslice{5, 3, 11},
// array
[4]int{1, 2, 3, 4},
[3]int64{5, 8, 2},
[2]uint8{3, 5},
// functions
zeroFunc,
emptyFunc,
@@ -287,7 +288,10 @@ func showValue(rv reflect.Value, indent string) {
case reflect.UnsafePointer:
println(indent+" pointer:", rv.Pointer() != 0)
case reflect.Array:
println(indent + " array")
println(indent+" array:", rt.Len(), rt.Elem().Kind().String(), int(rt.Size()))
for i := 0; i < rv.Len(); i++ {
showValue(rv.Index(i), indent+" ")
}
case reflect.Chan:
println(indent+" chan:", rt.Elem().Kind().String())
println(indent+" nil:", rv.IsNil())
+13 -1
View File
@@ -203,7 +203,19 @@ reflect type: slice
reflect type: uint8 settable=true
uint: 11
reflect type: array
array
array: 3 int64 24
reflect type: int64
int: 5
reflect type: int64
int: 8
reflect type: int64
int: 2
reflect type: array
array: 2 uint8 2
reflect type: uint8
uint: 3
reflect type: uint8
uint: 5
reflect type: func
func
nil: true