Documentation ¶
Overview ¶
Package rt defines the runtime interfaces used to interact with the game world. We use interfaces rather than concrete implementations to decouple package dependencies.
Index ¶
- Variables
- func IsNilRecord(e error) bool
- func IsUnknown(e error) bool
- func UnknownField(target, field string) error
- func UnknownName(name string) error
- func UnknownObject(o string) error
- func UnknownResponse(v string) error
- func UnknownVariable(v string) error
- type Address
- type Aspect
- type Assignment
- type BoolEval
- type Cursor
- type Dotted
- type Execute
- type Field
- type Jump
- type Kind
- func (k *Kind) Ancestors() []string
- func (k *Kind) Aspect(i int) (ret Aspect)
- func (k *Kind) AspectIndex(aspect string) (ret int)
- func (k *Kind) Field(i int) (ret Field)
- func (k *Kind) FieldCount() int
- func (k *Kind) FieldIndex(n string) (ret int)
- func (k *Kind) FindAspectByTrait(trait string) int
- func (k *Kind) Implements(name string) bool
- func (k *Kind) Name() (ret string)
- type Kinds
- type NilRecord
- type Notifier
- type NumEval
- type NumListEval
- type PanicValue
- func (n PanicValue) Affinity() affine.Affinity
- func (n PanicValue) Any() any
- func (n PanicValue) Appends(Value) error
- func (n PanicValue) Bool() bool
- func (n PanicValue) FieldByName(string) (Value, error)
- func (n PanicValue) Float() float64
- func (Floats PanicValue) Floats() []float64
- func (n PanicValue) Index(int) Value
- func (n PanicValue) Int() int
- func (n PanicValue) Len() int
- func (n PanicValue) Record() *Record
- func (n PanicValue) Records() []*Record
- func (n PanicValue) SetFieldByName(string, Value) error
- func (n PanicValue) SetIndex(int, Value) error
- func (n PanicValue) Slice(i, j int) (Value, error)
- func (n PanicValue) Splice(start, end int, add Value, cutList *Value) error
- func (n PanicValue) String() string
- func (n PanicValue) Strings() []string
- func (n PanicValue) Type() string
- type Record
- func (d *Record) GetIndexedField(i int) (ret Value, err error)
- func (d *Record) GetNamedField(field string) (ret Value, err error)
- func (d *Record) HasValue(i int) (okay bool)
- func (d *Record) SetIndexedField(i int, val Value) (err error)
- func (d *Record) SetNamedField(field string, val Value) (err error)
- type RecordEval
- type RecordListEval
- type Reference
- type Rule
- type Runtime
- type Scope
- type Signal
- type TextEval
- type TextListEval
- type Unknown
- type Value
- func BoolFrom(v bool, subtype string) Value
- func BoolOf(v bool) Value
- func CopyValue(val Value) (ret Value)
- func FloatFrom(v float64, subtype string) Value
- func FloatOf(v float64) Value
- func FloatsFrom(vs []float64, subtype string) (ret Value)
- func FloatsOf(vs []float64) Value
- func IntFrom(v int, subtype string) Value
- func IntOf(v int) Value
- func RecordOf(v *Record) Value
- func RecordsFrom(vs []*Record, subtype string) (ret Value)
- func StringFrom(v string, subtype string) Value
- func StringOf(v string) Value
- func StringsFrom(vs []string, subtype string) (ret Value)
- func StringsOf(vs []string) Value
- func ZeroField(aff affine.Affinity, cls string, idx int) (ret Value, err error)
- func ZeroValue(aff affine.Affinity) (ret Value, err error)
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func IsNilRecord ¶
func UnknownField ¶
func UnknownName ¶
func UnknownObject ¶
func UnknownResponse ¶
func UnknownVariable ¶
Types ¶
type Aspect ¶
the traits of any aspects behave like separate boolean fields; ex. if the list of fields contains a "colour" aspect with traits "red", "blue", "green" then the returned kind will respond to "colour", "red", "blue", and "green".
func MakeAspects ¶
given a set of fields which may contain aspects generate a list of traits. relies on the passed kinds database having types which inherit from kindOf.Aspect the fields of those types are the traits.
type Assignment ¶
Assignment accesses values in a generic way.
func AssignValue ¶ added in v0.24.7
func AssignValue(v Value) Assignment
wrap an existing value as an assigned value
type Cursor ¶ added in v0.24.6
type Cursor interface { CurrentValue() Value SetAtIndex(int, Value) error GetAtIndex(int) (Cursor, error) SetAtField(string, Value) error GetAtField(string) (Cursor, error) }
a value within an object, record, or list.
type Dotted ¶ added in v0.24.6
type Dotted interface { // read a value from the contents of the passed target. Peek(target Cursor) (Cursor, error) // write into the contents of the passed target. Poke(target Cursor, newValue Value) error }
a "pointer" into the contents of some as yet unspecified target: for example, a field for use with objects or records, or an index for use in lists.
type Field ¶
type Field struct { Name string // name of the field, unique within the kind Affinity affine.Affinity // one of the built in data types Type string `json:",omitempty"` // subtype; ex. kind for text types Init Assignment `json:",omitempty"` // default initialization }
member of a kind.
type Kind ¶
type Kind struct { // indicates ancestry, the name of this kind at the start, parent kinds to the right. // can be nil if anonymous Path []string // holds the accumulated fields of all ancestors. // parent fields to the *left*, more derived fields to the right. ( the reverse of path. ) // descendant kinds can have different initial assignments for the same named field. Fields []Field `json:",omitempty"` // a subset of fields for those containing traits // see MakeAspects. Aspects []Aspect `json:",omitempty"` // contains filtered or unexported fields }
used for tapestry objects and records a kind is a collection of fields with optional inheritance.
func (*Kind) Ancestors ¶
ancestors of this kind, the name of this kind at the head of the list. the slice isn't a copy; it should be treated as read-only. nil for anonymous kinds.
func (*Kind) AspectIndex ¶
func (*Kind) FieldCount ¶ added in v0.24.6
number of fields contained by this ( and all parent kinds )
func (*Kind) FieldIndex ¶
returns the index of the matching field; for traits, that's the index of its aspect. returns -1 if no matching field was found.
func (*Kind) FindAspectByTrait ¶
return the index of the aspect containing the passed trait
func (*Kind) Implements ¶
true if the kind has the named ancestor. ( this is a shortcut for testing the passed name in Path() )
type NilRecord ¶
type NilRecord struct { Class string // name of the record type that the field wants Field int // index of the field in its parent record }
returned when trying to generate the zero value of a field containing a record record fields are nil by default so that types are able to refer to themselves in go, types can use pointers for self references ( ex. struct LinkedList { Link *LinkedList } )
type Notifier ¶ added in v0.24.7
type Notifier struct { StartedScene func(domains []string) EndedScene func(domains []string) ChangedState func(noun, aspect, oldState, newState string) ChangedRelative func(a, b, rel string) }
Callbacks to listen for system level changes
type NumListEval ¶
NumListEval represents the computation of a series of numeric values.
type PanicValue ¶
type PanicValue struct{}
PanicValue is a PanicValue where every method panics except type and affinity.
func (PanicValue) Affinity ¶
func (n PanicValue) Affinity() affine.Affinity
Affinity returns a blank string.
func (PanicValue) Any ¶
func (n PanicValue) Any() any
func (PanicValue) FieldByName ¶
func (n PanicValue) FieldByName(string) (Value, error)
FieldByName panics
func (PanicValue) SetFieldByName ¶
func (n PanicValue) SetFieldByName(string, Value) error
SetFieldByName panics
type Record ¶
type Record struct { *Kind // contains filtered or unexported fields }
Record - provides access to named field/values pairs. The fields of a record are defined by its kind. Fields that are themselves records ( ie. sub-records ) start uninitialized. Trying to Get() an uninitialized record will result in a "NilRecord" error. safe.EnsureField() can use the Kinds database to create sub-records on demand.
func (*Record) GetIndexedField ¶
GetIndexedField panics if out of range. note: traits are never indexed fields ( although their aspect is ) Can return a NilRecord error for uninitialized record fields.
func (*Record) GetNamedField ¶
GetNamedField picks a value or trait from this record. Can return a NilRecord error for uninitialized record fields.
func (*Record) HasValue ¶
limited change detection ( a hack, basically, for determining whether patterns have written results )
func (*Record) SetIndexedField ¶
SetIndexedField - note this doesn't handle trait translation. Unlike the Value interface, this doesn't panic and it doesn't copy values. As a special case, passing a nil value will reset the field to its default.
type RecordEval ¶
RecordEval yields access to a set of fields and their values.
type RecordListEval ¶
RecordListEval represents the computation of a series of a set of fields.
type Reference ¶ added in v0.24.6
type Reference interface { // set the value at the current cursor. SetValue(newValue Value) (err error) // read the value of the current cursor. GetValue() (ret Value, err error) // peeks into the current cursor at the requested field or index. Dot(next Dotted) (ret Reference, err error) }
a value that might contain other values.
type Rule ¶
type Rule struct { Name string // controls the style of transition: // when true, stops processing of any other rules; otherwise moves to the next phase. // a stop before the main rule is considered a canceled action; // and the result of the action in that case is false. Stop bool // controls when a transitions happens Jump Jump // whether the rule needs to be updated // before jumping to the next phase ( ex. for counters ) Updates bool // a chain of if-else statements is considered an "optional" rule; // otherwise its considered a mandatory rule. // mandatory rules block other rules from running ( based on stop/stop ) // optional rules only block other rules if some part of the if chain tested true. Exe []Execute }
Rule triggers a named series of statements when its filters and phase are satisfied. stopping before the action happens is considered a cancel.
type Runtime ¶
type Runtime interface { // ActivateDomain - objects are grouped into potentially hierarchical "domains". // de/activating makes those groups hidden/visible to the runtime. // Domain hierarchy is defined at assembly time. ActivateDomain(name string) error // GetKindByName - type description GetKindByName(name string) (*Kind, error) // Call - run the pattern defined by the passed record. // passes the expected return because patterns can be called in ambiguous context ( ex. template expressions ) Call(name string, expectedReturn affine.Affinity, keys []string, vals []Value) (Value, error) // RelativesOf - returns a list, even for one-to-one relationships. RelativesOf(a, relation string) (Value, error) // ReciprocalsOf - returns a list, even for one-to-one relationships. ReciprocalsOf(b, relation string) (Value, error) // RelateTo - establish a new relation between nouns and and b. RelateTo(a, b, relation string) error // PushScope - modifies the behavior of Get/SetField meta.Variable // by adding a set of variables to the current namespace. // ex. loops add iterators PushScope(Scope) // PopScope - remove the most recently added set of variables from the internal stack. PopScope() // GetField - various runtime objects (ex. nouns, kinds, etc.) store data addressed by name. // the objects and their fields depend on implementation and context. // see package meta for a variety of common objects. GetField(object, field string) (Value, error) // SetField - store, or at least attempt to store, a *copy* of the value into the field of the named object. // it can return an error: // if the value is not of a compatible type, // if the field is considered to read-only, // or if there is no object or field of the indicated names. SetField(object, field string, value Value) error // PluralOf - turn single words into their plural variants, and vice-versa. // each plural word maps to a unique singular. // for example, if the singular of "people" is "person", it cant also be "personage". PluralOf(single string) string // note: one plural word can map to multiple single words. // in that case the returned singular word is arbitrary ( if theoretically consistent ) // for example, "person" can have the plural "people" or "persons" and this could return either. SingularOf(plural string) string // Random - return a pseudo-random number. Random(inclusiveMin, exclusiveMax int) int // Writer which prints text to the player. // It's tempting to have this be Write() -- so callers can print directly to the runtime. // That doesn't work in practice because go interfaces aren't virtual functions. // Any runtime wrapper can get stripped off, and wind up writing to an unexpected implementation. Writer() io.Writer // SetWriter - Override the current writer. SetWriter(io.Writer) (prev io.Writer) }
Runtime environment for an in-progress game.
type Scope ¶
type Scope interface { // return g.Unknown if the named field/variable doesn't exist. FieldByName(field string) (Value, error) // set without copying SetFieldByName(field string, val Value) error }
Scope - establishes a pool of local variables. Scopes are usually accessed via the runtime Set/GetField.
type Signal ¶ added in v0.24.8
type Signal int
error code for system commands used by play/step to switch take some action as a side-effect a command
type TextListEval ¶
TextListEval represents the computation of a series of strings.
type Unknown ¶
type Unknown struct {
Target, Field string
}
error for GetField, SetField
func (Unknown) IsUnknownField ¶
type Value ¶
type Value interface { // identifies how the passed value is represented internally. // ex. a number can be represented as float or as an int, // a record might be one of several different kinds, // text might represent an object id of a specific kind, an aspect, trait, or other value. Type() string // identifies the general category of the value. Affinity() affine.Affinity // return this value as a bool, or panic if the value isn't a bool. Bool() bool // return this value as a float, or panic if the value isn't a number. Float() float64 // return this value as an int, or panic if the value isn't a number. Int() int // return this value as a string; it doesn't panic. // for non-string values, similar to package reflect, it returns a string of the form "<type value>". String() string // return this value as a record, or panic if the value isn't a record. Record() *Record // return this value as a slice of floats, or panic if this isn't a float slice. // note: while primitive values support both ints and floats, slices can only be floats. Floats() []float64 // return this value as a slice of strings, or panic if this isn't a string slice. Strings() []string // return this value as a slice of records, or panic if not a record slice. // note: every value in the returned slice is expected to be record of this value's Type(). Records() []*Record // return a value representing a field inside this record. // if the field holds a record or a slice, the returned value shares its memory with the named field. // errors if note a record, or the field doesn't exist. FieldByName(string) (Value, error) // writes a *copy* of the passed value into a record. // errors if not a record, the field doesn't exist, or if its affinity cant support the passed value. SetFieldByName(string, Value) error // the number of elements in the value. // panics if this cant have a length: isnt a slice or a string. Len() int // return the nth element of this value, where 0 is the first value. // panics if this isn't a slice. Index(int) Value // writes a *copy* of the passed value into a slice // panics if this isn't a slice, if the index is out of range, or if the affinities are mismatched. // errors if the types are mismatched SetIndex(int, Value) error // adds a *copy* of a value, or a copy of a slice of values, to the end of this slice. // panics if this value isn't an appropriate kind of slice; errors on subtype. // In golang, this is a package level function, presumably to mirror the built-in append() Appends(Value) error // return a *copy* of this slice and its values containing the first index up to (and not including) the second index. // panics if this value isn't a slice. Slice(i, j int) (Value, error) // cut elements out of this slice from start to end, // and add copies of the passed additional element(s) at the start of the cut point. // returns the cut element if cutList if non-nil. // errors if the start and end indices are bad. // panics if this value isn't a slice, or if additional element(s) are of an incompatible affinity. // 'add' can be a single value, a list of values, or nil. Splice(start, end int, add Value, cutList *Value) error }
Value represents any one of Tapestry's built in types.
func CopyValue ¶
CopyValue: create a new value from a snapshot of the passed value panics on error because it assumes all values should be copyable
func FloatsFrom ¶
func RecordsFrom ¶
func StringFrom ¶
func StringsFrom ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
package kindsOf defines a handful of built-in base types for tapestry kinds.
|
package kindsOf defines a handful of built-in base types for tapestry kinds. |
Package meta provides string constants for rt.Runtime Get/SetField.
|
Package meta provides string constants for rt.Runtime Get/SetField. |
Package pattern provides tools for creating and executing functions with guards.
|
Package pattern provides tools for creating and executing functions with guards. |
Package print provides low level routines for styling output.
|
Package print provides low level routines for styling output. |