Expression

package
v0.0.0-...-fa94a0d Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

An expression can be made of any arithmetic operation, built-in math function call, method call of a passed instance, or built-in type construction call.

An example expression text using the built-in math functions could be sqrt(pow(3, 2) + pow(4, 2)).

In the following example we use a LineEdit node to write our expression and show the result.

package main

import (
	"fmt"

	"graphics.gd/classdb/Expression"
	"graphics.gd/classdb/LineEdit"
)

type ExampleExpression struct {
	LineEdit LineEdit.Instance

	expression Expression.Instance
}

func (e *ExampleExpression) Ready() {
	e.expression = Expression.New()
	e.LineEdit.OnTextSubmitted(func(new_text string) {
		var err = e.expression.Parse(new_text)
		if err != nil {
			fmt.Println(e.expression.GetErrorText())
			return
		}
		var result = e.expression.Execute()
		if !e.expression.HasExecuteFailed() {
			e.LineEdit.SetText(fmt.Sprint(result))
		}
	})
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsExpression() Instance
}

type Expanded

type Expanded = MoreArgs

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsExpression

func (self *Extension[T]) AsExpression() Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsRefCounted

func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.Expression

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsExpression

func (self Instance) AsExpression() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) Execute

func (self Instance) Execute() any

Executes the expression that was previously parsed by Parse and returns the result. Before you use the returned object, you should check if the method failed by calling HasExecuteFailed.

If you defined input variables in Parse, you can specify their values in the inputs array, in the same order.

func (Instance) GetErrorText

func (self Instance) GetErrorText() string

Returns the error text if Parse or Execute has failed.

func (Instance) HasExecuteFailed

func (self Instance) HasExecuteFailed() bool

Returns true if Execute has failed.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) MoreArgs

func (self Instance) MoreArgs() MoreArgs

MoreArgs enables certain functions to be called with additional 'optional' arguments.

func (Instance) Parse

func (self Instance) Parse(expression string) error

Parses the expression and returns an [Error] code.

You can optionally specify names of variables that may appear in the expression with 'input_names', so that you can bind them when it gets executed.

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type MoreArgs

type MoreArgs [1]gdclass.Expression

MoreArgs is a container for Instance functions with additional 'optional' arguments.

func (MoreArgs) Execute

func (self MoreArgs) Execute(inputs []any, base_instance Object.Instance, show_error bool, const_calls_only bool) any

Executes the expression that was previously parsed by Parse and returns the result. Before you use the returned object, you should check if the method failed by calling HasExecuteFailed.

If you defined input variables in Parse, you can specify their values in the inputs array, in the same order.

func (MoreArgs) Parse

func (self MoreArgs) Parse(expression string, input_names []string) error

Parses the expression and returns an [Error] code.

You can optionally specify names of variables that may appear in the expression with 'input_names', so that you can bind them when it gets executed.

Jump to

Keyboard shortcuts

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