variable

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

CRC: crc-VariableStore.md Spec: protocol.md, data-models.md

Package variable implements the Variable Protocol System. CRC: crc-Variable.md, crc-VariableStore.md, crc-WatchManager.md Spec: protocol.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetObjectReferenceID

func GetObjectReferenceID(value json.RawMessage) (int64, bool)

GetObjectReferenceID extracts the object ID from an object reference.

func IsObjectReference

func IsObjectReference(value json.RawMessage) bool

IsObjectReference checks if a JSON value is an object reference.

Types

type CreateOptions

type CreateOptions struct {
	ID         int64 // If non-zero, use this ID instead of generating one
	ParentID   int64
	Value      json.RawMessage
	Properties map[string]string
	NoWatch    bool
	Unbound    bool
}

CreateOptions holds options for creating a variable.

type ObjectReference

type ObjectReference struct {
	Obj int64 `json:"obj"`
}

ObjectReference represents a reference to another object.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store manages all variables and their relationships.

func NewStore

func NewStore(cfg *config.Config) *Store

NewStore creates a new variable store.

func (*Store) Count

func (s *Store) Count() int

Count returns the number of variables.

func (*Store) Create

func (s *Store) Create(opts CreateOptions) (int64, error)

Create creates a new variable and returns its ID.

func (*Store) Destroy

func (s *Store) Destroy(id int64) error

Destroy removes a variable and all its children recursively.

func (*Store) Get

func (s *Store) Get(id int64) (*Variable, bool)

Get retrieves a variable by ID.

func (*Store) GetAll

func (s *Store) GetAll() []*Variable

GetAll returns all variables (for debugging/testing).

func (*Store) GetByName

func (s *Store) GetByName(name string) (*Variable, bool)

GetByName retrieves a standard variable by @NAME.

func (*Store) GetChildren

func (s *Store) GetChildren(parentID int64) []*Variable

GetChildren returns all variables with the given parent ID.

func (*Store) Log

func (s *Store) Log(level int, format string, args ...interface{})

Log logs a message via the config.

func (*Store) RegisterStandardVariable

func (s *Store) RegisterStandardVariable(name string, id int64) error

RegisterStandardVariable associates @NAME with a variable ID.

func (*Store) ResolveObjectReference

func (s *Store) ResolveObjectReference(ref json.RawMessage) (json.RawMessage, error)

ResolveObjectReference gets object data for {obj: ID} references.

func (*Store) Update

func (s *Store) Update(id int64, value json.RawMessage, properties map[string]string) error

Update updates a variable's value and/or properties.

func (*Store) WatchProperty

func (s *Store) WatchProperty(varID int64, property string, callback func(value interface{}))

WatchProperty registers a callback for when a property changes on a variable. This implements the VariableUpdater interface for Lua runtime integration.

type Variable

type Variable struct {
	ID              int64             `json:"id"`
	ParentID        int64             `json:"parentId,omitempty"`
	Value           interface{}       `json:"value,omitempty"` // Raw value from path resolution
	MonitoredValue  interface{}       `json:"-"`               // For change detection (shallow copy for arrays)
	StoredValue     interface{}       `json:"-"`               // Can be the wrapper instance itself
	WrapperInstance interface{}       `json:"-"`               // Internal wrapper object (if wrapper property set)
	Properties      map[string]string `json:"properties,omitempty"`
	Unbound         bool              `json:"unbound,omitempty"`
	// contains filtered or unexported fields
}

Variable represents a single variable in the variable tree. Supports dual value architecture: monitored value for change detection, stored value for frontend (which can be a wrapper instance).

func NewVariable

func NewVariable(id int64) *Variable

NewVariable creates a new Variable with the given ID.

func (*Variable) GetID

func (v *Variable) GetID() int64

GetID returns the variable's unique identifier. Implements WrapperVariable interface.

func (*Variable) GetProperties

func (v *Variable) GetProperties() map[string]string

GetProperties returns a copy of all properties.

func (*Variable) GetProperty

func (v *Variable) GetProperty(name string) string

GetProperty returns a property value (empty string if unset).

func (*Variable) GetStoredValue

func (v *Variable) GetStoredValue() interface{}

GetStoredValue returns the stored value (sent to frontend). This is the wrapper instance if it exists, or the raw value otherwise.

func (*Variable) GetValue

func (v *Variable) GetValue() interface{}

GetValue returns the current value.

func (*Variable) GetWrapperInstance

func (v *Variable) GetWrapperInstance() interface{}

GetWrapperInstance returns the internal wrapper instance (nil if none).

func (*Variable) GetWrapperTypeName

func (v *Variable) GetWrapperTypeName() string

GetWrapperTypeName returns the wrapper type name from properties (empty string if unset).

func (*Variable) HasWrapper

func (v *Variable) HasWrapper() bool

HasWrapper checks if a wrapper instance is stored internally.

func (*Variable) IsObjectReference

func (v *Variable) IsObjectReference() bool

IsObjectReference checks if the value is {obj: ID} form.

func (*Variable) IsStandardVariable

func (v *Variable) IsStandardVariable() bool

IsStandardVariable checks if this is registered with @NAME pattern.

func (*Variable) IsUnbound

func (v *Variable) IsUnbound() bool

IsUnbound checks if storage is in UI server (not external backend).

func (*Variable) SetProperties

func (v *Variable) SetProperties(props map[string]string)

SetProperties sets multiple properties at once, handling priority suffixes.

func (*Variable) SetProperty

func (v *Variable) SetProperty(name, value string)

SetProperty sets a property value. Empty string removes the property.

func (*Variable) SetStoredValue

func (v *Variable) SetStoredValue(value interface{})

SetStoredValue sets the stored value.

func (*Variable) SetValue

func (v *Variable) SetValue(value interface{})

SetValue updates the value.

func (*Variable) SetWrapperInstance

func (v *Variable) SetWrapperInstance(wrapper interface{})

SetWrapperInstance stores the wrapper instance internally. Called during variable creation when wrapper property is set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL