types

package
v0.0.0-...-d095abb Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: Unlicense Imports: 8 Imported by: 2

Documentation

Overview

package types holds type definitions used for interfacing with the Litecode VM.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeArgs

func DecodeArgs[T ProgramArgs](encoded []byte) (args T, err error)

func DecodeRets

func DecodeRets[T ProgramRets](encoded []byte) (args T, err error)

Types

type Buffer

type Buffer []byte

Buffer represents a Luau byte buffer. Luau type`buffer` As buffers are compared by reference, this type must always be used as a pointer.

type Compiler

type Compiler struct {
	Cache map[[32]byte]internal.Deserpath
	O     uint8
}

Compiler allows programs to be compiled and deserialised with a cache and given optimisation level.

type Coroutine

type Coroutine struct {
	Function
	Env
	Filepath, Dbgpath string   // actually does well here
	RequireHistory    []string // prevents cyclic module dependencies
	YieldChan         chan internal.Yield
	ResumeChan        chan []Val
	Dbg               debugging
	Compiler          // for require()
	internal.Status
	ProgramArgs // idk how
}

Coroutine represents a Luau coroutine, including the main coroutine. Luau type `thread` As coroutines are compared by reference, this type must always be used as a pointer.

func (*Coroutine) Error

func (co *Coroutine) Error(err error)

Error yields an error to the coroutine, killing it shortly after.

func (*Coroutine) Resume

func (co *Coroutine) Resume(args ...Val) (r []Val, err error)

Resume executes the coroutine with the provided arguments, starting it with the given arguments if it is not already started, otherwise resuming it and passing the argument values back to the yielded function.

type Env

type Env map[string]Val

Env represents a global Luau environment.

func (*Env) AddFn

func (e *Env) AddFn(f Function)

AddFn adds a function to the environment.

type Function

type Function struct {
	// Run is the native body of the function. Its coroutine argument is used to run the function in a coroutine.
	Run  *func(*Coroutine, ...Val) ([]Val, error)
	Name string
	Co   *Coroutine // if in a different coroutine
}

Function represents a native or wrapped Luau function. Luau type `function`

type ProgramArgs

type ProgramArgs interface {
	Type() ProgramType
	Encode() []byte
}

ProgramArgs represents the arguments passed to a program.

type ProgramRets

type ProgramRets interface {
	// Equal(ProgramRets) error
	Type() ProgramType
	Encode() []byte
}

ProgramRets represents the response returned from a program.

type ProgramType

type ProgramType uint8

ProgramType represents the type of a program.

const (
	// TestProgramType represents the type of a test program.
	// Test programs are to be used for debugging and testing purposes only.
	TestProgramType ProgramType = iota
	// WebProgramType represents the type of a web program.
	WebProgramType
)

type Table

type Table struct {
	List     []Val
	Hash     map[Val]Val
	Readonly bool
}

Table represents a Luau table, with resizeable list and hash parts. Luau type `table` As tables are compared by reference, this type must always be used as a pointer.

func (*Table) Get

func (t *Table) Get(k Val) Val

Get returns a value at a key in the table.

func (*Table) GetFloat

func (t *Table) GetFloat(k float64) Val

GetFloat returns a value at a float key in the table.

func (*Table) GetHash

func (t *Table) GetHash(k Val) (v Val)

GetHash returns a value at a key, only searching the hash part of the table.

func (*Table) GetInt

func (t *Table) GetInt(k int) Val

GetFloat returns a value at a float key in the table.

func (*Table) Iter

func (t *Table) Iter() iter.Seq2[Val, Val]

Iter returns an iterator over the table, yielding key-value pairs in a deterministic order.

func (*Table) Len

func (t *Table) Len() int

Len returns the length of the list part of the table (the length of the list up until the first nil).

func (*Table) Set

func (t *Table) Set(k Val, v Val)

Set sets a table value at a key. Make sure to check if the table is readonly beforehand.

func (*Table) SetInt

func (t *Table) SetInt(i int, v Val)

SetInt sets a value at an integer index, placing it into the List part or the Hash part and resizing each as appropriate.

type TestArgs

type TestArgs struct{}

TestArgs stores the arguments passed to a test program.

func (TestArgs) Encode

func (TestArgs) Encode() []byte

func (TestArgs) Type

func (TestArgs) Type() ProgramType

Type returns TestProgramType.

type TestRets

type TestRets struct{}

TestRets stores the response returned from a test program.

func (TestRets) Encode

func (TestRets) Encode() []byte

func (TestRets) Equal

func (TestRets) Equal(TestRets) error

func (TestRets) Type

func (TestRets) Type() ProgramType

Type returns TestProgramType.

type Val

type Val = internal.Val

Val represents any possible Luau value. Luau type `any`

type Vector

type Vector [4]float32

Vector represents a 3-wide or 4-wide vector value. Luau type `vector`

type WebArgs

type WebArgs struct {
	Url     WebArgsUrl        `json:"url"`
	Method  string            `json:"method"`
	Headers map[string]string `json:"headers"`
	Body    []byte            `json:"body"`
}

WebArgs stores the arguments passed to a web program.

func (WebArgs) Encode

func (args WebArgs) Encode() []byte

func (WebArgs) Type

func (WebArgs) Type() ProgramType

Type returns WebProgramType.

type WebArgsUrl

type WebArgsUrl struct {
	Rawpath  string              `json:"rawpath"`
	Path     string              `json:"path"`
	Rawquery string              `json:"rawquery"`
	Query    map[string][]string `json:"query"`
}

WebArgsUrl represents a parsed URL and its properties.

type WebRets

type WebRets struct {
	StatusCode int `json:"statuscode"`
	// StatusMessage string            `json:"statusmessage"` // removed 3 now
	Headers map[string]string `json:"headers"`
	Body    []byte            `json:"body"`
}

WebRets stores the response returned from a web program.

func (WebRets) Encode

func (rets WebRets) Encode() []byte

func (WebRets) Equal

func (r1 WebRets) Equal(r2 WebRets) (err error)

func (WebRets) Type

func (WebRets) Type() ProgramType

Type returns WebProgramType.

Jump to

Keyboard shortcuts

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