vm

package
v3.4.4 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package vm is responsible for the interop between legacy NoxScript VM and new NS runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetRuntime

func SetRuntime(r Implementation)

SetRuntime is used by the script host to bind runtime for the script package. Scripts must not call this functions.

Types

type Func

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

Func is a reference to a legacy NoxScript function.

func FuncPtr

func FuncPtr(fnc string) *Func

FuncPtr returns a function reference to a legacy NoxScript function.

func (*Func) Call

func (f *Func) Call(args ...any) Value

Call a specified function from legacy NoxScript.

func (*Func) Local

func (f *Func) Local(vari int) Var

Local returns a reference to a local function variable in legacy NoxScript.

Local function variables are static in NoxScript, they are not reset after the call. Because of this, they are frequently used to keep state between the calls.

Accessing these variables is similar to Global: var0 in function Foo can be accessed with vm.FuncPtr("Foo").Local(0).

type Game

type Game interface {
	// NoxScriptVM returns implementation of NoxScript VM.
	NoxScriptVM() Implementation
}

Game is an optional interface for the engine that exposes NoxScript runtime.

type Implementation

type Implementation interface {
	NewString(s string) uint32
	GetString(val uint32) string

	GetFuncInd(fnc string) int
	GetFuncVar(fnc int, vari int) uint32
	SetFuncVar(fnc int, vari int, val uint32)

	CallFunc(fnc int, args []uint32) uint32
}

Implementation of the script VM. Only used in the engine itself.

func Runtime

func Runtime() Implementation

Runtime returns implementation of all the accessible functions as an interface.

type Value

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

Value is an untyped value, as stored in NoxScript runtime.

func (Value) Float

func (v Value) Float() float32

Float returns NoxScript value as float.

func (Value) Int

func (v Value) Int() int

Int returns NoxScript value as int.

func (Value) Object

func (v Value) Object() ns3.ObjectID

Object returns NoxScript value as object.

func (Value) ObjectGroup

func (v Value) ObjectGroup() ns3.ObjectGroupID

ObjectGroup returns NoxScript value as object group.

func (Value) String

func (v Value) String() string

String returns NoxScript value as string.

func (Value) Wall

func (v Value) Wall() ns3.WallID

Wall returns NoxScript value as wall.

func (Value) WallGroup

func (v Value) WallGroup() ns3.WallGroupID

WallGroup returns NoxScript value as wall group.

func (Value) Waypoint

func (v Value) Waypoint() ns3.WaypointID

Waypoint returns NoxScript value as waypoint.

func (Value) WaypointGroup

func (v Value) WaypointGroup() ns3.WaypointGroupID

WaypointGroup returns NoxScript value as waypoint group.

type Var

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

Var is a reference to a legacy NoxScript variable.

func FuncVar

func FuncVar(fnc string, vari int) Var

FuncVar returns a reference to a local function variable in legacy NoxScript.

It's a shortcut for vm.FuncPtr(fnc).Local(vari). See Func.Local for details.

func Global

func Global(gvar int) Var

Global returns a reference to a global variable in legacy NoxScript.

Variables in NoxScript do not have a name, thus they are referred to by an index.

For example, gvar0 in the editor corresponds to index 0 and can be accessed with vm.Global(0).

func (Var) Get

func (vr Var) Get() Value

Get a variable value from legacy NoxScript.

func (Var) Set

func (vr Var) Set(val any)

Set a variable value in legacy NoxScript.

Jump to

Keyboard shortcuts

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