Module: stdgo.reflect
Overview
Package reflect implements run-time reflection, allowing a program to manipulate objects with arbitrary types. The typical use is to take a value with static type interface{} and extract its dynamic type information by calling TypeOf, which returns a Type.
A call to ValueOf returns a Value representing the run-time data. Zero takes a Type and returns a Value representing a zero value for that type.
See "The Laws of Reflection" for an introduction to reflection in Go: https://golang.org/doc/articles/laws_of_reflection.html
Index
-
function append(_s:stdgo.reflect.Value, _x:haxe.Rest<stdgo.reflect.Value>):stdgo.reflect.Value
-
function appendSlice(_s:stdgo.reflect.Value, _t:stdgo.reflect.Value):stdgo.reflect.Value
-
function arrayOf(_length:stdgo.GoInt, _elem:stdgo.reflect.Type_):stdgo.reflect.Type_
-
function chanOf(_dir:stdgo.reflect.ChanDir, _t:stdgo.reflect.Type_):stdgo.reflect.Type_
-
function copy(_dst:stdgo.reflect.Value, _src:stdgo.reflect.Value):stdgo.GoInt
-
function deepEqual(_x:stdgo.AnyInterface, _y:stdgo.AnyInterface):Bool
-
function indirect(_v:stdgo.reflect.Value):stdgo.reflect.Value
-
function makeChan(_typ:stdgo.reflect.Type_, _buffer:stdgo.GoInt):stdgo.reflect.Value
-
function makeMap(_typ:stdgo.reflect.Type_):stdgo.reflect.Value
-
function makeMapWithSize(_typ:stdgo.reflect.Type_, _n:stdgo.GoInt):stdgo.reflect.Value
-
function makeSlice(_typ:stdgo.reflect.Type_, _len:stdgo.GoInt, _cap:stdgo.GoInt):stdgo.reflect.Value
-
function mapOf(_key:stdgo.reflect.Type_, _elem:stdgo.reflect.Type_):stdgo.reflect.Type_
-
function newAt(_typ:stdgo.reflect.Type_, _p:stdgo.unsafe.UnsafePointer):stdgo.reflect.Value
-
function pointerTo(_t:stdgo.reflect.Type_):stdgo.reflect.Type_
-
function sliceOf(_t:stdgo.reflect.Type_):stdgo.reflect.Type_
-
function structOf(_fields:stdgo.Slice<stdgo.reflect.StructField>):stdgo.reflect.Type_
-
function swapper(_slice:stdgo.AnyInterface):(_i:stdgo.GoInt, _j:stdgo.GoInt):Void
-
function visibleFields(_t:stdgo.reflect.Type_):stdgo.Slice<stdgo.reflect.StructField>
-
function new(?data:stdgo.GoUIntptr, ?len:stdgo.GoInt, ?cap:stdgo.GoInt):Void
-
function call( _in:stdgo.Slice<stdgo.reflect.Value>):stdgo.Slice<stdgo.reflect.Value>
-
function callSlice( _in:stdgo.Slice<stdgo.reflect.Value>):stdgo.Slice<stdgo.reflect.Value>
-
function convert( _t:stdgo.reflect.Type_):stdgo.reflect.Value
-
function fieldByIndex( _index:stdgo.Slice<stdgo.GoInt>):stdgo.reflect.Value
-
function fieldByName( _name:stdgo.GoString):stdgo.reflect.Value
-
function mapIndex( _key:stdgo.reflect.Value):stdgo.reflect.Value
-
function methodByName( _name:stdgo.GoString):stdgo.reflect.Value
-
function setIterKey( _iter:stdgo.Ref<stdgo.reflect.MapIter>):Void
-
function setIterValue( _iter:stdgo.Ref<stdgo.reflect.MapIter>):Void
-
function setMapIndex( _key:stdgo.reflect.Value, _elem:stdgo.reflect.Value):Void
-
function slice( _i:stdgo.GoInt, _j:stdgo.GoInt):stdgo.reflect.Value
-
function slice3( _i:stdgo.GoInt, _j:stdgo.GoInt, _k:stdgo.GoInt):stdgo.reflect.Value
-
function new(?method:stdgo.GoString, ?kind:stdgo.reflect.Kind, ?toString:():String):Void
Constants
import stdgo.reflect.Reflect
final array:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final bool_:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final bothDir:stdgo.reflect.ChanDir = ((((0 : stdgo.GoInt)) : stdgo.reflect.Reflect.ChanDir))
chan
final chan:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final complex128:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final complex64:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final float32:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final float64:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final func:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final int16:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final int32:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final int64:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final int8:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final int_:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final interface_:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final invalid:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final map_:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final pointer:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final ptr:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
Ptr is the old name for the Pointer kind.
final recvDir:stdgo.reflect.ChanDir = ((((0 : stdgo.GoInt)) : stdgo.reflect.Reflect.ChanDir))
\<-chan
final selectDefault:Null<Dynamic> = @:unknown_default_value null
default
final selectRecv:Null<Dynamic> = @:unknown_default_value null
case \<-Chan:
final selectSend:Null<Dynamic> = @:unknown_default_value null
case Chan \<- Send
final sendDir:stdgo.reflect.ChanDir = ((((0 : stdgo.GoInt)) : stdgo.reflect.Reflect.ChanDir))
chan\<-
final slice:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final string:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final struct_:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final uint:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final uint16:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final uint32:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final uint64:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final uint8:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final uintptr:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
final unsafePointer:stdgo.reflect.Kind = ((((0 : stdgo.GoUInt)) : stdgo.reflect.Reflect.Kind))
Functions
import stdgo.reflect.Reflect
function append
function append(_s:stdgo.reflect.Value, _x:haxe.Rest<stdgo.reflect.Value>):stdgo.reflect.Value
Append appends the values x to a slice s and returns the resulting slice. As in Go, each x's value must be assignable to the slice's element type.
function appendSlice
function appendSlice(_s:stdgo.reflect.Value, _t:stdgo.reflect.Value):stdgo.reflect.Value
AppendSlice appends a slice t to a slice s and returns the resulting slice. The slices s and t must have the same element type.
function arrayOf
function arrayOf(_length:stdgo.GoInt, _elem:stdgo.reflect.Type_):stdgo.reflect.Type_
ArrayOf returns the array type with the given length and element type. For example, if t represents int, ArrayOf(5, t) represents [5]int.
If the resulting type would be larger than the available address space, ArrayOf panics.
function chanOf
function chanOf(_dir:stdgo.reflect.ChanDir, _t:stdgo.reflect.Type_):stdgo.reflect.Type_
ChanOf returns the channel type with the given direction and element type. For example, if t represents int, ChanOf(RecvDir, t) represents \<-chan int.
The gc runtime imposes a limit of 64 kB on channel element types. If t's size is equal to or exceeds this limit, ChanOf panics.
function copy
function copy(_dst:stdgo.reflect.Value, _src:stdgo.reflect.Value):stdgo.GoInt
Copy copies the contents of src into dst until either dst has been filled or src has been exhausted. It returns the number of elements copied. Dst and src each must have kind Slice or Array, and dst and src must have the same element type.
As a special case, src can have kind String if the element type of dst is kind Uint8.
function deepEqual
function deepEqual(_x:stdgo.AnyInterface, _y:stdgo.AnyInterface):Bool
DeepEqual reports whether x and y are “deeply equal,” defined as follows. Two values of identical type are deeply equal if one of the following cases applies. Values of distinct types are never deeply equal.
Array values are deeply equal when their corresponding elements are deeply equal.
Struct values are deeply equal if their corresponding fields, both exported and unexported, are deeply equal.
Func values are deeply equal if both are nil; otherwise they are not deeply equal.
Interface values are deeply equal if they hold deeply equal concrete values.
Map values are deeply equal when all of the following are true: they are both nil or both non-nil, they have the same length, and either they are the same map object or their corresponding keys (matched using Go equality) map to deeply equal values.
Pointer values are deeply equal if they are equal using Go's == operator or if they point to deeply equal values.
Slice values are deeply equal when all of the following are true: they are both nil or both non-nil, they have the same length, and either they point to the same initial entry of the same underlying array (that is, &x[0] == &y[0]) or their corresponding elements (up to length) are deeply equal. Note that a non-nil empty slice and a nil slice (for example, []byte{} and []byte(nil)) are not deeply equal.
Other values - numbers, bools, strings, and channels - are deeply equal if they are equal using Go's == operator.
In general DeepEqual is a recursive relaxation of Go's == operator. However, this idea is impossible to implement without some inconsistency. Specifically, it is possible for a value to be unequal to itself, either because it is of func type (uncomparable in general) or because it is a floating-point NaN value (not equal to itself in floating-point comparison), or because it is an array, struct, or interface containing such a value. On the other hand, pointer values are always equal to themselves, even if they point at or contain such problematic values, because they compare equal using Go's == operator, and that is a sufficient condition to be deeply equal, regardless of content. DeepEqual has been defined so that the same short-cut applies to slices and maps: if x and y are the same slice or the same map, they are deeply equal regardless of content.
As DeepEqual traverses the data values it may find a cycle. The second and subsequent times that DeepEqual compares two pointer values that have been compared before, it treats the values as equal rather than examining the values to which they point. This ensures that DeepEqual terminates.
function funcOf
function funcOf(_in:stdgo.Slice<stdgo.reflect.Type_>, _out:stdgo.Slice<stdgo.reflect.Type_>, _variadic:Bool):stdgo.reflect.Type_
FuncOf returns the function type with the given argument and result types. For example if k represents int and e represents string, FuncOf([]Type{k}, []Type{e}, false) represents func(int) string.
The variadic argument controls whether the function is variadic. FuncOf panics if the in[len(in)-1] does not represent a slice and variadic is true.
function indirect
function indirect(_v:stdgo.reflect.Value):stdgo.reflect.Value
Indirect returns the value that v points to. If v is a nil pointer, Indirect returns a zero Value. If v is not a pointer, Indirect returns v.
function makeChan
function makeChan(_typ:stdgo.reflect.Type_, _buffer:stdgo.GoInt):stdgo.reflect.Value
MakeChan creates a new channel with the specified type and buffer size.
function makeFunc
function makeFunc(_typ:stdgo.reflect.Type_, _fn:(_args:stdgo.Slice<stdgo.reflect.Value>):stdgo.Slice<stdgo.reflect.Value>):stdgo.reflect.Value
MakeFunc returns a new function of the given Type that wraps the function fn. When called, that new function does the following:
- converts its arguments to a slice of Values.
- runs results := fn(args).
- returns the results as a slice of Values, one per formal result.
The implementation fn can assume that the argument Value slice has the number and type of arguments given by typ. If typ describes a variadic function, the final Value is itself a slice representing the variadic arguments, as in the body of a variadic function. The result Value slice returned by fn must have the number and type of results given by typ.
The Value.Call method allows the caller to invoke a typed function in terms of Values; in contrast, MakeFunc allows the caller to implement a typed function in terms of Values.
The Examples section of the documentation includes an illustration of how to use MakeFunc to build a swap function for different types.
function makeMap
function makeMap(_typ:stdgo.reflect.Type_):stdgo.reflect.Value
MakeMap creates a new map with the specified type.
function makeMapWithSize
function makeMapWithSize(_typ:stdgo.reflect.Type_, _n:stdgo.GoInt):stdgo.reflect.Value
MakeMapWithSize creates a new map with the specified type and initial space for approximately n elements.
function makeSlice
function makeSlice(_typ:stdgo.reflect.Type_, _len:stdgo.GoInt, _cap:stdgo.GoInt):stdgo.reflect.Value
MakeSlice creates a new zero-initialized slice value for the specified slice type, length, and capacity.
function mapOf
function mapOf(_key:stdgo.reflect.Type_, _elem:stdgo.reflect.Type_):stdgo.reflect.Type_
MapOf returns the map type with the given key and element types. For example, if k represents int and e represents string, MapOf(k, e) represents map[int]string.
If the key type is not a valid map key type (that is, if it does not implement Go's == operator), MapOf panics.
function newAt
function newAt(_typ:stdgo.reflect.Type_, _p:stdgo.unsafe.UnsafePointer):stdgo.reflect.Value
NewAt returns a Value representing a pointer to a value of the specified type, using p as that pointer.
function new_
function new_(_typ:stdgo.reflect.Type_):stdgo.reflect.Value
New returns a Value representing a pointer to a new zero value for the specified type. That is, the returned Value's Type is PointerTo(typ).
function pointerTo
function pointerTo(_t:stdgo.reflect.Type_):stdgo.reflect.Type_
PointerTo returns the pointer type with element t. For example, if t represents type Foo, PointerTo(t) represents *Foo.
function ptrTo
function ptrTo(_t:stdgo.reflect.Type_):stdgo.reflect.Type_
PtrTo returns the pointer type with element t. For example, if t represents type Foo, PtrTo(t) represents *Foo.
PtrTo is the old spelling of PointerTo. The two functions behave identically.
function select
function select(_cases:stdgo.Slice<stdgo.reflect.SelectCase>):{
_2:Bool;
_1:stdgo.reflect.Value;
_0:stdgo.GoInt;
}
Select executes a select operation described by the list of cases. Like the Go select statement, it blocks until at least one of the cases can proceed, makes a uniform pseudo-random choice, and then executes that case. It returns the index of the chosen case and, if that case was a receive operation, the value received and a boolean indicating whether the value corresponds to a send on the channel (as opposed to a zero value received because the channel is closed). Select supports a maximum of 65536 cases.
function sliceOf
function sliceOf(_t:stdgo.reflect.Type_):stdgo.reflect.Type_
SliceOf returns the slice type with element type t. For example, if t represents int, SliceOf(t) represents []int.
function structOf
function structOf(_fields:stdgo.Slice<stdgo.reflect.StructField>):stdgo.reflect.Type_
StructOf returns the struct type containing fields. The Offset and Index fields are ignored and computed as they would be by the compiler.
StructOf currently does not generate wrapper methods for embedded fields and panics if passed unexported StructFields. These limitations may be lifted in a future version.
function swapper
function swapper(_slice:stdgo.AnyInterface):(_i:stdgo.GoInt, _j:stdgo.GoInt):Void
Swapper returns a function that swaps the elements in the provided slice.
Swapper panics if the provided interface is not a slice.
function typeOf
function typeOf(_i:stdgo.AnyInterface):stdgo.reflect.Type_
TypeOf returns the reflection Type that represents the dynamic type of i. If i is a nil interface value, TypeOf returns nil.
function valueOf
function valueOf(_i:stdgo.AnyInterface):stdgo.reflect.Value
ValueOf returns a new Value initialized to the concrete value stored in the interface i. ValueOf(nil) returns the zero Value.
function visibleFields
function visibleFields(_t:stdgo.reflect.Type_):stdgo.Slice<stdgo.reflect.StructField>
VisibleFields returns all the visible fields in t, which must be a struct type. A field is defined as visible if it's accessible directly with a FieldByName call. The returned fields include fields inside anonymous struct members and unexported fields. They follow the same order found in the struct, with anonymous fields followed immediately by their promoted fields.
For each element e of the returned slice, the corresponding field can be retrieved from a value v of type t by calling v.FieldByIndex(e.Index).
function zero
function zero(_typ:stdgo.reflect.Type_):stdgo.reflect.Value
Zero returns a Value representing the zero value for the specified type. The result is different from the zero value of the Value struct, which represents no value at all. For example, Zero(TypeOf(42)) returns a Value with Kind Int and value 0. The returned value is neither addressable nor settable.
Classes
import stdgo.reflect.*
class MapIter
A MapIter is an iterator for ranging over a map. See Value.MapRange.
MapIter function new
function new(?map:haxe.IMap<Dynamic, Dynamic>, ?keys:Array<Dynamic>, ?values:Array<Dynamic>, ?t:stdgo.internal.reflect._Type, ?index:Int):Void
MapIter function key
function key():stdgo.reflect.Value
Key returns the key of iter's current map entry.
MapIter function next
function next():Bool
Next advances the map iterator and reports whether there is another entry. It returns false when iter is exhausted; subsequent calls to Key, Value, or Next will panic.
MapIter function reset
function reset( _v:stdgo.reflect.Value):Void
Reset modifies iter to iterate over v. It panics if v's Kind is not Map and v is not the zero Value. Reset(Value{}) causes iter to not to refer to any map, which may allow the previously iterated-over map to be garbage collected.
MapIter function value
function value():stdgo.reflect.Value
Value returns the value of iter's current map entry.
class Method
Method represents a single method.
var func:stdgo.reflect.Value
var index:stdgo.GoInt
var name:stdgo.GoString
Name is the method name.
var pkgPath:stdgo.GoString
PkgPath is the package path that qualifies a lower case (unexported) method name. It is empty for upper case (exported) method names. The combination of PkgPath and Name uniquely identifies a method in a method set. See https://golang.org/ref/spec#Uniqueness_of_identifiers
var type:stdgo.reflect.Type_
Method function new
function new(?name:stdgo.GoString, ?pkgPath:stdgo.GoString, ?type:Null<stdgo.reflect.Type_>, ?func:stdgo.reflect.Value, ?index:stdgo.GoInt):Void
Method function isExported
function isExported():Bool
IsExported reports whether the method is exported.
class SelectCase
A SelectCase describes a single case in a select operation. The kind of case depends on Dir, the communication direction.
If Dir is SelectDefault, the case represents a default case. Chan and Send must be zero Values.
If Dir is SelectSend, the case represents a send operation. Normally Chan's underlying value must be a channel, and Send's underlying value must be assignable to the channel's element type. As a special case, if Chan is a zero Value, then the case is ignored, and the field Send will also be ignored and may be either zero or non-zero.
If Dir is SelectRecv, the case represents a receive operation. Normally Chan's underlying value must be a channel and Send must be a zero Value. If Chan is a zero Value, then the case is ignored, but Send must still be a zero Value. When a receive operation is selected, the received Value is returned by Select.
var chan:stdgo.reflect.Value
var dir:stdgo.reflect.SelectDir
var send:stdgo.reflect.Value
SelectCase function new
function new(?dir:Null<stdgo.reflect.SelectDir>, ?chan:stdgo.reflect.Value, ?send:stdgo.reflect.Value):Void
class SliceHeader
SliceHeader is the runtime representation of a slice. It cannot be used safely or portably and its representation may change in a later release. Moreover, the Data field is not sufficient to guarantee the data it references will not be garbage collected, so programs must keep a separate, correctly typed pointer to the underlying data.
Deprecated: Use unsafe.Slice or unsafe.SliceData instead.
var cap:stdgo.GoInt
var data:stdgo.GoUIntptr
var len:stdgo.GoInt
SliceHeader function new
function new(?data:stdgo.GoUIntptr, ?len:stdgo.GoInt, ?cap:stdgo.GoInt):Void
class StringHeader
StringHeader is the runtime representation of a string. It cannot be used safely or portably and its representation may change in a later release. Moreover, the Data field is not sufficient to guarantee the data it references will not be garbage collected, so programs must keep a separate, correctly typed pointer to the underlying data.
Deprecated: Use unsafe.String or unsafe.StringData instead.
var data:stdgo.GoUIntptr
var len:stdgo.GoInt
StringHeader function new
function new(?data:stdgo.GoUIntptr, ?len:stdgo.GoInt):Void
class StructField
A StructField describes a single field in a struct.
var anonymous:Bool
var index:stdgo.Slice<stdgo.GoInt>
var name:stdgo.GoString
Name is the field name.
var offset:stdgo.GoUIntptr
var pkgPath:stdgo.GoString
PkgPath is the package path that qualifies a lower case (unexported) field name. It is empty for upper case (exported) field names. See https://golang.org/ref/spec#Uniqueness_of_identifiers
var tag:stdgo.reflect.StructTag
var type:stdgo.reflect.Type_
StructField function new
function new(?name:stdgo.GoString, ?pkgPath:stdgo.GoString, ?type:Null<stdgo.reflect.Type_>, ?tag:Null<stdgo.reflect.StructTag>, ?offset:stdgo.GoUIntptr, ?index:stdgo.Slice<stdgo.GoInt>, ?anonymous:Bool):Void
StructField function isExported
function isExported():Bool
IsExported reports whether the field is exported.
class Value
Value is the reflection interface to a Go value.
Not all methods apply to all kinds of values. Restrictions, if any, are noted in the documentation for each method. Use the Kind method to find out the kind of value before calling kind-specific methods. Calling a method inappropriate to the kind of type causes a run time panic.
The zero Value represents no value.
Its IsValid method returns false, its Kind method returns Invalid,
its String method returns "\
A Value can be used concurrently by multiple goroutines provided that the underlying Go value can be used concurrently for the equivalent direct operations.
To compare two Values, compare the results of the Interface method. Using == on two Values does not compare the underlying values they represent.
Value function new
function new(?value:stdgo.AnyInterface, ?underlyingValue:Dynamic, ?underlyingIndex:stdgo.GoInt, ?underlyingKey:Dynamic, ?canAddrBool:Bool, ?notSetBool:Bool, ?string:():stdgo.GoString):Void
Value function string
function string():stdgo.GoString
Value function addr
function addr():stdgo.reflect.Value
Addr returns a pointer value representing the address of v. It panics if CanAddr() returns false. Addr is typically used to obtain a pointer to a struct field or slice element in order to call a method that requires a pointer receiver.
Value function bool_
function bool_():Bool
Bool returns v's underlying value. It panics if v's kind is not Bool.
Value function bytes
function bytes():stdgo.Slice<stdgo.GoByte>
Bytes returns v's underlying value. It panics if v's underlying value is not a slice of bytes or an addressable array of bytes.
Value function call
function call( _in:stdgo.Slice<stdgo.reflect.Value>):stdgo.Slice<stdgo.reflect.Value>
Call calls the function v with the input arguments in. For example, if len(in) == 3, v.Call(in) represents the Go call v(in[0], in[1], in[2]). Call panics if v's Kind is not Func. It returns the output results as Values. As in Go, each input argument must be assignable to the type of the function's corresponding input parameter. If v is a variadic function, Call creates the variadic slice parameter itself, copying in the corresponding values.
Value function callSlice
function callSlice( _in:stdgo.Slice<stdgo.reflect.Value>):stdgo.Slice<stdgo.reflect.Value>
CallSlice calls the variadic function v with the input arguments in, assigning the slice in[len(in)-1] to v's final variadic argument. For example, if len(in) == 3, v.CallSlice(in) represents the Go call v(in[0], in[1], in[2]...). CallSlice panics if v's Kind is not Func or if v is not variadic. It returns the output results as Values. As in Go, each input argument must be assignable to the type of the function's corresponding input parameter.
Value function canAddr
function canAddr():Bool
CanAddr reports whether the value's address can be obtained with Addr. Such values are called addressable. A value is addressable if it is an element of a slice, an element of an addressable array, a field of an addressable struct, or the result of dereferencing a pointer. If CanAddr returns false, calling Addr will panic.
Value function canComplex
function canComplex():Bool
CanComplex reports whether Complex can be used without panicking.
Value function canConvert
function canConvert( _t:stdgo.reflect.Type_):Bool
CanConvert reports whether the value v can be converted to type t. If v.CanConvert(t) returns true then v.Convert(t) will not panic.
Value function canFloat
function canFloat():Bool
CanFloat reports whether Float can be used without panicking.
Value function canInt
function canInt():Bool
CanInt reports whether Int can be used without panicking.
Value function canInterface
function canInterface():Bool
CanInterface reports whether Interface can be used without panicking.
Value function canSet
function canSet():Bool
CanSet reports whether the value of v can be changed. A Value can be changed only if it is addressable and was not obtained by the use of unexported struct fields. If CanSet returns false, calling Set or any type-specific setter (e.g., SetBool, SetInt) will panic.
Value function canUint
function canUint():Bool
CanUint reports whether Uint can be used without panicking.
Value function cap
function cap():stdgo.GoInt
Cap returns v's capacity. It panics if v's Kind is not Array, Chan, Slice or pointer to Array.
Value function clear
function clear():Void
Clear clears the contents of a map or zeros the contents of a slice.
It panics if v's Kind is not Map or Slice.
Value function close
function close():Void
Close closes the channel v. It panics if v's Kind is not Chan.
Value function comparable
function comparable():Bool
Comparable reports whether the value v is comparable. If the type of v is an interface, this checks the dynamic type. If this reports true then v.Interface() == x will not panic for any x, nor will v.Equal(u) for any Value u.
Value function complex
function complex():stdgo.GoComplex128
Complex returns v's underlying value, as a complex128. It panics if v's Kind is not Complex64 or Complex128
Value function convert
function convert( _t:stdgo.reflect.Type_):stdgo.reflect.Value
Convert returns the value v converted to type t. If the usual Go conversion rules do not allow conversion of the value v to type t, or if converting v to type t panics, Convert panics.
Value function elem
function elem():stdgo.reflect.Value
Elem returns the value that the interface v contains or that the pointer v points to. It panics if v's Kind is not Interface or Pointer. It returns the zero Value if v is nil.
Value function equal
function equal( _u:stdgo.reflect.Value):Bool
Equal reports true if v is equal to u. For two invalid values, Equal will report true. For an interface value, Equal will compare the value within the interface. Otherwise, If the values have different types, Equal will report false. Otherwise, for arrays and structs Equal will compare each element in order, and report false if it finds non-equal elements. During all comparisons, if values of the same type are compared, and the type is not comparable, Equal will panic.
Value function field
function field( _i:stdgo.GoInt):stdgo.reflect.Value
Field returns the i'th field of the struct v. It panics if v's Kind is not Struct or i is out of range.
Value function fieldByIndex
function fieldByIndex( _index:stdgo.Slice<stdgo.GoInt>):stdgo.reflect.Value
FieldByIndex returns the nested field corresponding to index. It panics if evaluation requires stepping through a nil pointer or a field that is not a struct.
Value function fieldByIndexErr
function fieldByIndexErr( _index:stdgo.Slice<stdgo.GoInt>):{
_1:stdgo.Error;
_0:stdgo.reflect.Value;
}
FieldByIndexErr returns the nested field corresponding to index. It returns an error if evaluation requires stepping through a nil pointer, but panics if it must step through a field that is not a struct.
Value function fieldByName
function fieldByName( _name:stdgo.GoString):stdgo.reflect.Value
FieldByName returns the struct field with the given name. It returns the zero Value if no field was found. It panics if v's Kind is not struct.
Value function fieldByNameFunc
function fieldByNameFunc( _match:()):stdgo.reflect.Value
FieldByNameFunc returns the struct field with a name that satisfies the match function. It panics if v's Kind is not struct. It returns the zero Value if no field was found.
Value function float_
function float_():stdgo.GoFloat64
Float returns v's underlying value, as a float64. It panics if v's Kind is not Float32 or Float64
Value function grow
function grow( _n:stdgo.GoInt):Void
Grow increases the slice's capacity, if necessary, to guarantee space for another n elements. After Grow(n), at least n elements can be appended to the slice without another allocation.
It panics if v's Kind is not a Slice or if n is negative or too large to allocate the memory.
Value function index
function index( _i:stdgo.GoInt):stdgo.reflect.Value
Index returns v's i'th element. It panics if v's Kind is not Array, Slice, or String or i is out of range.
Value function int_
function int_():stdgo.GoInt64
Int returns v's underlying value, as an int64. It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64.
Value function interfaceData
function interfaceData():stdgo.GoArray<stdgo.GoUIntptr>
InterfaceData returns a pair of unspecified uintptr values. It panics if v's Kind is not Interface.
In earlier versions of Go, this function returned the interface's value as a uintptr pair. As of Go 1.4, the implementation of interface values precludes any defined use of InterfaceData.
Deprecated: The memory representation of interface values is not compatible with InterfaceData.
Value function interface_
function interface_():stdgo.AnyInterface
Interface returns v's current value as an interface{}. It is equivalent to:
var i interface{} = (v's underlying value)
It panics if the Value was obtained by accessing unexported struct fields.
Value function isNil
function isNil():Bool
IsNil reports whether its argument v is nil. The argument must be a chan, func, interface, map, pointer, or slice value; if it is not, IsNil panics. Note that IsNil is not always equivalent to a regular comparison with nil in Go. For example, if v was created by calling ValueOf with an uninitialized interface variable i, i==nil will be true but v.IsNil will panic as v will be the zero Value.
Value function isValid
function isValid():Bool
IsValid reports whether v represents a value. It returns false if v is the zero Value. If IsValid returns false, all other methods except String panic. Most functions and methods never return an invalid Value. If one does, its documentation states the conditions explicitly.
Value function isZero
function isZero():Bool
IsZero reports whether v is the zero value for its type. It panics if the argument is invalid.
Value function kind
function kind():stdgo.reflect.Kind
Kind returns v's Kind. If v is the zero Value (IsValid returns false), Kind returns Invalid.
Value function len
function len():stdgo.GoInt
Len returns v's length. It panics if v's Kind is not Array, Chan, Map, Slice, String, or pointer to Array.
Value function mapIndex
function mapIndex( _key:stdgo.reflect.Value):stdgo.reflect.Value
MapIndex returns the value associated with key in the map v. It panics if v's Kind is not Map. It returns the zero Value if key is not found in the map or if v represents a nil map. As in Go, the key's value must be assignable to the map's key type.
Value function mapKeys
function mapKeys():stdgo.Slice<stdgo.reflect.Value>
MapKeys returns a slice containing all the keys present in the map, in unspecified order. It panics if v's Kind is not Map. It returns an empty slice if v represents a nil map.
Value function mapRange
function mapRange():stdgo.Ref<stdgo.reflect.MapIter>
MapRange returns a range iterator for a map. It panics if v's Kind is not Map.
Call Next to advance the iterator, and Key/Value to access each entry. Next returns false when the iterator is exhausted. MapRange follows the same iteration semantics as a range statement.
Example:
iter := reflect.ValueOf(m).MapRange()
for iter.Next() {
k := iter.Key()
v := iter.Value()
...
}
Value function method
function method( _i:stdgo.GoInt):stdgo.reflect.Value
Method returns a function value corresponding to v's i'th method. The arguments to a Call on the returned function should not include a receiver; the returned function will always use v as the receiver. Method panics if i is out of range or if v is a nil interface value.
Value function methodByName
function methodByName( _name:stdgo.GoString):stdgo.reflect.Value
MethodByName returns a function value corresponding to the method of v with the given name. The arguments to a Call on the returned function should not include a receiver; the returned function will always use v as the receiver. It returns the zero Value if no method was found.
Value function numField
function numField():stdgo.GoInt
NumField returns the number of fields in the struct v. It panics if v's Kind is not Struct.
Value function numMethod
function numMethod():stdgo.GoInt
NumMethod returns the number of methods in the value's method set.
For a non-interface type, it returns the number of exported methods.
For an interface type, it returns the number of exported and unexported methods.
Value function overflowComplex
function overflowComplex( _x:stdgo.GoComplex128):Bool
OverflowComplex reports whether the complex128 x cannot be represented by v's type. It panics if v's Kind is not Complex64 or Complex128.
Value function overflowFloat
function overflowFloat( _x:stdgo.GoFloat64):Bool
OverflowFloat reports whether the float64 x cannot be represented by v's type. It panics if v's Kind is not Float32 or Float64.
Value function overflowInt
function overflowInt( _x:stdgo.GoInt64):Bool
OverflowInt reports whether the int64 x cannot be represented by v's type. It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64.
Value function overflowUint
function overflowUint( _x:stdgo.GoUInt64):Bool
OverflowUint reports whether the uint64 x cannot be represented by v's type. It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
Value function pointer
function pointer():stdgo.GoUIntptr
Pointer returns v's value as a uintptr. It panics if v's Kind is not Chan, Func, Map, Pointer, Slice, or UnsafePointer.
If v's Kind is Func, the returned pointer is an underlying code pointer, but not necessarily enough to identify a single function uniquely. The only guarantee is that the result is zero if and only if v is a nil func Value.
If v's Kind is Slice, the returned pointer is to the first element of the slice. If the slice is nil the returned value is 0. If the slice is empty but non-nil the return value is non-zero.
It's preferred to use uintptr(Value.UnsafePointer()) to get the equivalent result.
Value function recv
function recv():{
_1:Bool;
_0:stdgo.reflect.Value;
}
Recv receives and returns a value from the channel v. It panics if v's Kind is not Chan. The receive blocks until a value is ready. The boolean value ok is true if the value x corresponds to a send on the channel, false if it is a zero value received because the channel is closed.
Value function send
function send( _x:stdgo.reflect.Value):Void
Send sends x on the channel v. It panics if v's kind is not Chan or if x's type is not the same type as v's element type. As in Go, x's value must be assignable to the channel's element type.
Value function set
function set( _x:stdgo.reflect.Value):Void
Set assigns x to the value v. It panics if CanSet returns false. As in Go, x's value must be assignable to v's type and must not be derived from an unexported field.
Value function setBool
function setBool( _x:Bool):Void
SetBool sets v's underlying value. It panics if v's Kind is not Bool or if CanSet() is false.
Value function setBytes
function setBytes( _x:stdgo.Slice<stdgo.GoByte>):Void
SetBytes sets v's underlying value. It panics if v's underlying value is not a slice of bytes.
Value function setCap
function setCap( _n:stdgo.GoInt):Void
SetCap sets v's capacity to n. It panics if v's Kind is not Slice or if n is smaller than the length or greater than the capacity of the slice.
Value function setComplex
function setComplex( _x:stdgo.GoComplex128):Void
SetComplex sets v's underlying value to x. It panics if v's Kind is not Complex64 or Complex128, or if CanSet() is false.
Value function setFloat
function setFloat( _x:stdgo.GoFloat64):Void
SetFloat sets v's underlying value to x. It panics if v's Kind is not Float32 or Float64, or if CanSet() is false.
Value function setInt
function setInt( _x:stdgo.GoInt64):Void
SetInt sets v's underlying value to x. It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64, or if CanSet() is false.
Value function setIterKey
function setIterKey( _iter:stdgo.Ref<stdgo.reflect.MapIter>):Void
SetIterKey assigns to v the key of iter's current map entry. It is equivalent to v.Set(iter.Key()), but it avoids allocating a new Value. As in Go, the key must be assignable to v's type and must not be derived from an unexported field.
Value function setIterValue
function setIterValue( _iter:stdgo.Ref<stdgo.reflect.MapIter>):Void
SetIterValue assigns to v the value of iter's current map entry. It is equivalent to v.Set(iter.Value()), but it avoids allocating a new Value. As in Go, the value must be assignable to v's type and must not be derived from an unexported field.
Value function setLen
function setLen( _n:stdgo.GoInt):Void
SetLen sets v's length to n. It panics if v's Kind is not Slice or if n is negative or greater than the capacity of the slice.
Value function setMapIndex
function setMapIndex( _key:stdgo.reflect.Value, _elem:stdgo.reflect.Value):Void
SetMapIndex sets the element associated with key in the map v to elem. It panics if v's Kind is not Map. If elem is the zero Value, SetMapIndex deletes the key from the map. Otherwise if v holds a nil map, SetMapIndex will panic. As in Go, key's elem must be assignable to the map's key type, and elem's value must be assignable to the map's elem type.
Value function setPointer
function setPointer( _x:stdgo.unsafe.UnsafePointer):Void
SetPointer sets the [unsafe.Pointer] value v to x. It panics if v's Kind is not UnsafePointer.
Value function setString
function setString( _x:stdgo.GoString):Void
SetString sets v's underlying value to x. It panics if v's Kind is not String or if CanSet() is false.
Value function setUint
function setUint( _x:stdgo.GoUInt64):Void
SetUint sets v's underlying value to x. It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64, or if CanSet() is false.
Value function setZero
function setZero():Void
SetZero sets v to be the zero value of v's type. It panics if CanSet returns false.
Value function slice
function slice( _i:stdgo.GoInt, _j:stdgo.GoInt):stdgo.reflect.Value
Slice returns v[i:j]. It panics if v's Kind is not Array, Slice or String, or if v is an unaddressable array, or if the indexes are out of bounds.
Value function slice3
function slice3( _i:stdgo.GoInt, _j:stdgo.GoInt, _k:stdgo.GoInt):stdgo.reflect.Value
Slice3 is the 3-index form of the slice operation: it returns v[i:j:k]. It panics if v's Kind is not Array or Slice, or if v is an unaddressable array, or if the indexes are out of bounds.
Value function string
function string():stdgo.GoString
String returns the string v's underlying value, as a string.
String is a special case because of Go's String method convention.
Unlike the other getters, it does not panic if v's Kind is not String.
Instead, it returns a string of the form "\
Value function tryRecv
function tryRecv():{
_1:Bool;
_0:stdgo.reflect.Value;
}
TryRecv attempts to receive a value from the channel v but will not block. It panics if v's Kind is not Chan. If the receive delivers a value, x is the transferred value and ok is true. If the receive cannot finish without blocking, x is the zero Value and ok is false. If the channel is closed, x is the zero value for the channel's element type and ok is false.
Value function trySend
function trySend( _x:stdgo.reflect.Value):Bool
TrySend attempts to send x on the channel v but will not block. It panics if v's Kind is not Chan. It reports whether the value was sent. As in Go, x's value must be assignable to the channel's element type.
Value function type
function type():stdgo.reflect.Type_
Type returns v's type.
Value function uint
function uint():stdgo.GoUInt64
Uint returns v's underlying value, as a uint64. It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
Value function unsafeAddr
function unsafeAddr():stdgo.GoUIntptr
UnsafeAddr returns a pointer to v's data, as a uintptr. It panics if v is not addressable.
It's preferred to use uintptr(Value.Addr().UnsafePointer()) to get the equivalent result.
Value function unsafePointer
function unsafePointer():stdgo.unsafe.UnsafePointer
UnsafePointer returns v's value as a [unsafe.Pointer]. It panics if v's Kind is not Chan, Func, Map, Pointer, Slice, or UnsafePointer.
If v's Kind is Func, the returned pointer is an underlying code pointer, but not necessarily enough to identify a single function uniquely. The only guarantee is that the result is zero if and only if v is a nil func Value.
If v's Kind is Slice, the returned pointer is to the first element of the slice. If the slice is nil the returned value is nil. If the slice is empty but non-nil the return value is non-nil.
class ValueError
A ValueError occurs when a Value method is invoked on a Value that does not support it. Such cases are documented in the description of each method.
var kind:stdgo.reflect.Kind
var method:stdgo.GoString
ValueError function new
function new(?method:stdgo.GoString, ?kind:stdgo.reflect.Kind, ?toString:():String):Void
ValueError function toString
function toString():String
ValueError function error
function error():stdgo.GoString
Typedefs
import stdgo.reflect.*
typedef ChanDir
typedef ChanDir = stdgo.GoInt;
ChanDir represents a channel type's direction.
typedef Kind
typedef Kind = stdgo.GoUInt;
A Kind represents the specific kind of type that a Type represents. The zero Kind is not a valid kind.
typedef SelectDir
typedef SelectDir = stdgo.GoInt;
A SelectDir describes the communication direction of a select case.
typedef StructTag
typedef StructTag = stdgo.GoString;
A StructTag is the tag string in a struct field.
By convention, tag strings are a concatenation of optionally space-separated key:"value" pairs. Each key is a non-empty string consisting of non-control characters other than space (U+0020 ' '), quote (U+0022 '"'), and colon (U+003A ':'). Each value is quoted using U+0022 '"' characters and Go string literal syntax.
typedef Type_
typedef Type_ = {
public function string():stdgo.GoString; // String returns a string representation of the type. The string representation may use shortened package names (e.g., base64 instead of "encoding/base64") and is not guaranteed to be unique among types. To test for type identity, compare the Types directly.
public function size():stdgo.GoUIntptr; // Size returns the number of bytes needed to store a value of the given type; it is analogous to unsafe.Sizeof.
public function pkgPath():stdgo.GoString; // PkgPath returns a defined type's package path, that is, the import path that uniquely identifies the package, such as "encoding/base64". If the type was predeclared (string, error) or not defined (*T, struct{}, []int, or A where A is an alias for a non-defined type), the package path will be the empty string.
public function out(_i:stdgo.GoInt):stdgo.reflect.Type_; // Out returns the type of a function type's i'th output parameter. It panics if the type's Kind is not Func. It panics if i is not in the range [0, NumOut()).
public function numOut():stdgo.GoInt; // NumOut returns a function type's output parameter count. It panics if the type's Kind is not Func.
public function numMethod():stdgo.GoInt; // NumMethod returns the number of methods accessible using Method. For a non-interface type, it returns the number of exported methods. For an interface type, it returns the number of exported and unexported methods.
public function numIn():stdgo.GoInt; // NumIn returns a function type's input parameter count. It panics if the type's Kind is not Func.
public function numField():stdgo.GoInt; // NumField returns a struct type's field count. It panics if the type's Kind is not Struct.
public function name():stdgo.GoString; // Name returns the type's name within its package for a defined type. For other (non-defined) types it returns the empty string.
public function methodByName(_0:stdgo.GoString):{
_1:Bool;
_0:stdgo.reflect.Method;
}; // MethodByName returns the method with that name in the type's method set and a boolean indicating if the method was found. For a non-interface type T or *T, the returned Method's Type and Func fields describe a function whose first argument is the receiver. For an interface type, the returned Method's Type field gives the method signature, without a receiver, and the Func field is nil.
public function method(_0:stdgo.GoInt):stdgo.reflect.Method; // Method returns the i'th method in the type's method set. It panics if i is not in the range [0, NumMethod()). For a non-interface type T or *T, the returned Method's Type and Func fields describe a function whose first argument is the receiver, and only exported methods are accessible. For an interface type, the returned Method's Type field gives the method signature, without a receiver, and the Func field is nil. Methods are sorted in lexicographic order.
public function len():stdgo.GoInt; // Len returns an array type's length. It panics if the type's Kind is not Array.
public function kind():stdgo.reflect.Kind; // Kind returns the specific kind of this type.
public function key():stdgo.reflect.Type_; // Key returns a map type's key type. It panics if the type's Kind is not Map.
public function isVariadic():Bool; // IsVariadic reports whether a function type's final input parameter is a "..." parameter. If so, t.In(t.NumIn() - 1) returns the parameter's implicit actual type []T. For concreteness, if t represents func(x int, y ... float64), then t.NumIn() == 2 t.In(0) is the reflect.Type for "int" t.In(1) is the reflect.Type for "[]float64" t.IsVariadic() == true IsVariadic panics if the type's Kind is not Func.
public function in_(_i:stdgo.GoInt):stdgo.reflect.Type_; // In returns the type of a function type's i'th input parameter. It panics if the type's Kind is not Func. It panics if i is not in the range [0, NumIn()).
public function implements_(_u:stdgo.reflect.Type_):Bool; // Implements reports whether the type implements the interface type u.
public function fieldByNameFunc(_match:()):{
_1:Bool;
_0:stdgo.reflect.StructField;
}; // FieldByNameFunc returns the struct field with a name that satisfies the match function and a boolean indicating if the field was found. FieldByNameFunc considers the fields in the struct itself and then the fields in any embedded structs, in breadth first order, stopping at the shallowest nesting depth containing one or more fields satisfying the match function. If multiple fields at that depth satisfy the match function, they cancel each other and FieldByNameFunc returns no match. This behavior mirrors Go's handling of name lookup in structs containing embedded fields.
public function fieldByName(_name:stdgo.GoString):{
_1:Bool;
_0:stdgo.reflect.StructField;
}; // FieldByName returns the struct field with the given name and a boolean indicating if the field was found.
public function fieldByIndex(_index:stdgo.Slice<stdgo.GoInt>):stdgo.reflect.StructField; // FieldByIndex returns the nested field corresponding to the index sequence. It is equivalent to calling Field successively for each index i. It panics if the type's Kind is not Struct.
public function fieldAlign():stdgo.GoInt; // FieldAlign returns the alignment in bytes of a value of this type when used as a field in a struct.
public function field(_i:stdgo.GoInt):stdgo.reflect.StructField; // Field returns a struct type's i'th field. It panics if the type's Kind is not Struct. It panics if i is not in the range [0, NumField()).
public function elem():stdgo.reflect.Type_; // Elem returns a type's element type. It panics if the type's Kind is not Array, Chan, Map, Pointer, or Slice.
public function convertibleTo(_u:stdgo.reflect.Type_):Bool; // ConvertibleTo reports whether a value of the type is convertible to type u. Even if ConvertibleTo returns true, the conversion may still panic. For example, a slice of type []T is convertible to *[N]T, but the conversion will panic if its length is less than N.
public function comparable():Bool; // Comparable reports whether values of this type are comparable. Even if Comparable returns true, the comparison may still panic. For example, values of interface type are comparable, but the comparison will panic if their dynamic type is not comparable.
public function chanDir():stdgo.reflect.ChanDir; // ChanDir returns a channel type's direction. It panics if the type's Kind is not Chan.
public function bits():stdgo.GoInt; // Bits returns the size of the type in bits. It panics if the type's Kind is not one of the sized or unsized Int, Uint, Float, or Complex kinds.
public function assignableTo(_u:stdgo.reflect.Type_):Bool; // AssignableTo reports whether a value of the type is assignable to type u.
public function align():stdgo.GoInt; // Align returns the alignment in bytes of a value of this type when allocated in memory.
};
Type is the representation of a Go type.
Not all methods apply to all kinds of types. Restrictions, if any, are noted in the documentation for each method. Use the Kind method to find out the kind of type before calling kind-specific methods. Calling a method inappropriate to the kind of type causes a run-time panic.
Type values are comparable, such as with the == operator, so they can be used as map keys. Two Type values are equal if they represent identical types.