rbxmk

package module
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: MIT Imports: 20 Imported by: 0

README

rbxmk logo

rbxmk is a command-line tool for manipulating Roblox files.

rbxmk is useful for development workflows that involve the combination of many separate files. If your project is organized as Lua files for scripting and model files for assets, rbxmk makes it simple to combine them into a final product, be it a game, plugin, model, module, and so on. rbxmk is also suitable for more simple actions, such as downloading models or publishing games.

Download

The current version of rbxmk is v0.9.1. The following builds are available for download:

Windows Mac Linux
Windows 64-bit macOS Linux 64-bit
Windows 32-bit Linux 32-bit

See the Release page for more information on the current version.

rbxmk is fully featured, but thorough testing of all features is still a work in progress. Please practice redundancy and use backups to reduce the risk of data loss. Be sure to report issues as you encounter them!

Usage

rbxmk is a command-line tool, and so requires a command-line interface to use.

rbxmk primarily uses Lua scripts to produce and retrieve data, transform it, and send it off to a variety of sources. The main subcommand is run, which executes a script:

echo 'print("Hello world!")' > hello-world.lua
rbxmk run hello-world.lua
# Hello world!

The Documentation page provides a complete reference on how rbxmk is used, as well as the API of the Lua environment provided by rbxmk.

Examples

The examples directory contains examples of rbxmk scripts.

Installation

In addition to prebuilt releases, rbxmk can be installed manually.

  1. Install Go
  2. Install Git
  3. Using a shell with Git (such as Git Bash), run the following command:
go install github.com/anaminus/rbxmk/rbxmk@latest

If you installed Go correctly, this will install the latest version of rbxmk to $GOPATH/bin, which will allow you run it directly from a shell.

A specific version of rbxmk may be installed by replacing latest with a version number (e.g. v0.9.1).

Development

To compile and install the bleeding-edge version, the best way is to clone the repository:

git clone https://github.com/anaminus/rbxmk
cd rbxmk/rbxmk
go install

More information is available in the INSTALL document.

An effort is made to ensure that the latest commit will at least compile. However, it is not guaranteed that everything will be in a production-ready state.

License

The source code for rbxmk is available under the MIT license.

Documentation

Index

Constants

View Source
const UserAgent = "RobloxStudio/WinInet rbxmk/0.0"

UserAgent is the User-Agent header string sent with HTTP requests made by rbxmk. It includes components that ensure the client will operate with Roblox website APIs.

Variables

This section is empty.

Functions

func CookiesFrom added in v0.6.0

func CookiesFrom(location string) (cookies rtypes.Cookies, err error)

CookiesFrom retrieves cookies from a known location. location is case-insensitive. The following locations are implemented:

  • studio: Returns the cookies used for authentication when logging into Roblox Studio.

func DecodeCookies added in v0.6.0

func DecodeCookies(r io.Reader) (cookies rtypes.Cookies, err error)

DecodeCookies parses cookies from r and returns a list of cookies. Cookies are parsed as a number of "Set-Cookie" HTTP headers. Returns an empty list if the reader is empty.

func DoHTTPRequest added in v0.6.0

func DoHTTPRequest(w *World, options rtypes.HTTPOptions) (resp *rtypes.HTTPResponse, err error)

DoHTTPRequest begins and resolves an HTTPRequest. Returns an error if the reponse did not return a successful status.

func EncodeCookies added in v0.6.0

func EncodeCookies(w io.Writer, cookies rtypes.Cookies) (err error)

EncodeCookies formats a list of cookies as a number of "Set-Cookie" HTTP headers and writes them to w.

Types

type Client added in v0.4.0

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

Client wraps an http.Client to handle various additional behavior.

func NewClient added in v0.4.0

func NewClient(client *http.Client) *Client

NewClient returns an initialized Client. If *client* is nil, then http.DefaultClient is used.

func (*Client) Do added in v0.4.0

func (c *Client) Do(req *http.Request) (resp *http.Response, err error)

Do sends a request, with the following additional behaviors:

  • Includes a configured user agent header with the request, if the header is unset.
  • Handles CSRF token validation.

type Constructor added in v0.3.0

type Constructor struct {
	Func func(s State) int
	// Dump returns a description of constructor's API. Each function describes
	// one possible signature of the constructor.
	Dump func() dump.MultiFunction
}

Constructor creates a new value of a Reflector. The function can receive arguments from s.L, and must push a new value to s.L.

type Constructors added in v0.3.0

type Constructors map[string]Constructor

Constructors is a set of constructor functions keyed by name.

type Context added in v0.9.0

type Context struct {
	*World
	// contains filtered or unexported fields
}

Context provides a context for reflecting values.

func (Context) Context added in v0.9.0

func (c Context) Context() Context

Context returns a Context derived from the World.

func (Context) CreateTable added in v0.9.0

func (c Context) CreateTable(acap, hcap int) *lua.LTable

CreateTable returns a new table according to the context's LState.

func (*Context) CycleClear added in v0.9.0

func (c *Context) CycleClear()

CycleClear clears the cycle guard on the state. Panics if the state has no guard.

func (*Context) CycleGuard added in v0.9.0

func (c *Context) CycleGuard() bool

CycleGuard begins a guard against reference cycles when reflecting with the state. Returns false if a guard was already set up for the state. If true is returned, the guard must be cleared via CycleClear. For example:

if c.CycleGuard() {
    defer c.CycleClear()
}

func (Context) CycleMark added in v0.9.0

func (c Context) CycleMark(t interface{}) bool

CycleMark marks t as visited, and returns whether t was already visited. Panics if the state has no guard.

func (Context) GetMetaField added in v0.9.0

func (c Context) GetMetaField(obj lua.LValue, event string) lua.LValue

GetMetaField gets the value of the event field from the metatable of obj. Returns LNil if obj has no metatable, or the metatable has no such field.

func (Context) GetTypeMetatable added in v0.9.0

func (c Context) GetTypeMetatable(typ string) lua.LValue

GetTypeMetatable returns the typ metatable registered with the context's LState.

func (Context) NewUserData added in v0.9.0

func (c Context) NewUserData(value interface{}) *lua.LUserData

NewUserData returns a new userdata according to the context's LState.

func (Context) ReflectorError added in v0.9.0

func (c Context) ReflectorError()

ReflectorError panics, indicating that a reflector pushed or pulled an unexpected type. Under normal circumstances, this should be unreachable.

func (Context) SetMetatable added in v0.9.0

func (c Context) SetMetatable(obj, mt lua.LValue)

SetMetatable sets the metatable of obj to mt according to the context's LState.

type FileEntry added in v0.6.0

type FileEntry struct {
	Path string
	os.FileInfo
}

FileEntry describes a file, including the full path. An empty Path indicates stdin.

type Format

type Format struct {
	// Name is the name that identifies the format. The name matches a file
	// extension.
	Name string

	// EncodeTypes is an optional list of types that Encode can receive. These
	// are called with State.PullAnyOf to reflect the value to a type known by
	// the encoder. If empty, then the value is pulled as Variant.
	EncodeTypes []string

	// MediaTypes is a list of media types that are associated with the format,
	// to be used by sources as needed.
	MediaTypes []string

	// Options maps a field name to a number of value types. A FormatOptions
	// received by Encode or Decode will have only these fields. The value of a
	// field, if it exists, will be one of the specified type.
	Options map[string][]string

	// CanDecode returns whether the format decodes into the given type.
	CanDecode func(g Global, opt FormatOptions, typeName string) bool

	// Encode receives a value of one of a number of types and encodes it as a
	// sequence of bytes written to w.
	Encode func(g Global, opt FormatOptions, w io.Writer, v types.Value) error

	// Decode receives a sequence of bytes read from r, and decodes it into a
	// value of a single type.
	Decode func(g Global, opt FormatOptions, r io.Reader) (types.Value, error)

	// Dump returns a description of the format.
	Dump func() dump.Format
}

Format defines a format for encoding between a sequence of bytes and a types.Value. The format can be registered with a World.

type FormatOptions added in v0.3.0

type FormatOptions interface {
	// ValueOf returns the value of field. Returns nil if the value does not
	// exist.
	ValueOf(field string) types.Value
}

FormatOptions contains options to be passed to a Format.

type FrameType added in v0.6.0

type FrameType uint8

FrameType indicates the kind of frame for a State.

const (
	// Frame is a regular function.
	FunctionFrame FrameType = iota
	// Frame is a method; exclude first argument.
	MethodFrame
	// Frame is an operator, avoid displaying arguments.
	OperatorFrame
)

type Global added in v0.6.0

type Global struct {
	Desc       *rtypes.RootDesc
	AttrConfig *rtypes.AttrConfig
}

Global contains values that available across an entire World.

type HTTPRequest added in v0.6.0

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

HTTPRequest performs and HTTP request with a promise-like API.

func BeginHTTPRequest added in v0.6.0

func BeginHTTPRequest(w *World, options rtypes.HTTPOptions) (request *HTTPRequest, err error)

BeginHTTPRequest begins an HTTP request according to the given options, in the context of the given world.

The request starts immediately, and can either be resolved or canceled.

func (*HTTPRequest) Cancel added in v0.6.0

func (r *HTTPRequest) Cancel()

Cancel cancels the request.

func (*HTTPRequest) Resolve added in v0.6.0

func (r *HTTPRequest) Resolve() (*rtypes.HTTPResponse, error)

Resolve blocks until the request resolves.

func (*HTTPRequest) Type added in v0.6.0

func (*HTTPRequest) Type() string

Type returns a string identifying the type of the value.

type Library added in v0.3.0

type Library struct {
	// Name is a name that identifies the library.
	Name string
	// ImportedAs is the name that the library is imported as. Empty indicates
	// that the contents of the library are merged into the global environment.
	ImportedAs string
	// Open returns a table with the contents of the library.
	Open func(s State) *lua.LTable
	// Dump returns a description of the library's API.
	Dump func(s State) dump.Library
	// Types returns a list of type reflector expected by the library. Before
	// opening the library, each reflector is registered.
	Types []func() Reflector
}

Library represents a Lua library.

type Metamethod added in v0.3.0

type Metamethod func(s State) int

Metamethod is called when a metamethod is invoked.

type Metatable added in v0.3.0

type Metatable map[string]Metamethod

Metatable defines the metamethods of a custom type.

type Method added in v0.6.0

type Method struct {
	// Func is the body of the method. The first argument will be the same value
	// as v.
	Func func(s State, v types.Value) int
	// Dump returns a description of the member's API.
	Dump func() dump.Function
}

Method defines a member of a custom type.

type Methods added in v0.7.0

type Methods map[string]Method

Methods is a set of methods keyed by name.

type Properties added in v0.7.0

type Properties map[string]Property

Properties is a set of properties keyed by name.

type Property added in v0.7.0

type Property struct {
	// Get gets the value of a member from v and pushes it onto s. The index is
	// the 2nd argument in s.
	Get func(s State, v types.Value) int
	// Set gets a value from s and sets it to a member of v. The index and value
	// are the 2nd and 3rd arguments in s. Set is optional, if nil, the property
	// will be treated as read-only.
	Set func(s State, v types.Value)
	// Dump returns a description of the member's API.
	Dump func() dump.Property
}

Property defines a property of a custom type.

type Puller added in v0.9.0

type Puller func(c Context, lv lua.LValue) (v types.Value, err error)

Puller converts a Lua value to a types.Value. lv must be non-nil.

func PullTypeFrom added in v0.3.0

func PullTypeFrom(t string) Puller

PullTypeFrom returns a Puller that converts v from a userdata set with a type metatable registered as type t.

type Pusher added in v0.9.0

type Pusher func(c Context, v types.Value) (lv lua.LValue, err error)

Pusher converts a types.Value to a Lua value. If err is nil, then lv must not be nil.

func PushPtrTypeTo added in v0.6.0

func PushPtrTypeTo(t string) Pusher

PushPtrTypeTo returns a Pusher that converts v to a userdata set with a type metatable registered as type t. The same value will push the same userdata, making the value usable as a table key.

func PushTypeTo added in v0.3.0

func PushTypeTo(t string) Pusher

PushTypeTo returns a Pusher that converts v to a userdata set with a type metatable registered as type t. Each push always produces a new userdata. This results in better performance, but makes the value unsuitable as a table key.

type Reflector added in v0.3.0

type Reflector struct {
	// Name is the name of the type.
	Name string

	Flags ReflectorFlags

	// PushTo converts v to a Lua value. l must be used only for the conversion
	// of values as needed. If err is nil, then lv must not be nil.
	PushTo Pusher

	// PullFrom converts a Lua value to v. l must be used only for the
	// conversion of values as needed. lv must be non-nil.
	PullFrom Puller

	// SetTo sets reflector type v to the value pointed to by p. p must be a
	// pointer to a value that v can be set to. Returns an error if p is not a
	// known type.
	SetTo Setter

	// Metatable defines the metamethods of a custom type. If Metatable is
	// non-nil, then a metatable is constructed and registered as a type
	// metatable under Name.
	Metatable Metatable

	// Properties defines the properties of a custom type. If the __index and
	// __newindex metamethods are not defined by Metatable, then Properties
	// defines them according to the given properties. In case of name
	// conflicts, methods are prioritized over properties.
	Properties Properties

	// Symbols defines the symbols of a custom type. If the __index and
	// __newindex metamethods are not defined by Metatable, then Symbols defines
	// them according to the given properties.
	Symbols Symbols

	// Methods defines the methods of a custom type. If the __index and
	// __newindex metamethods are not defined by Metatable, then Methods defines
	// them according to the given members. In case of name conflicts, methods
	// are prioritized over properties.
	Methods Methods

	// Constructors defines functions that construct the type. If non-nil, a
	// table containing each constructor is created and set as a global
	// referenced by Name.
	Constructors Constructors

	// Environment is called after the type is registered to provide additional
	// setup.
	Environment func(s State)

	// ConvertFrom receives an arbitrary value and attempts to convert it to the
	// reflector's type. Returns nil if the value could not be converted.
	ConvertFrom func(v types.Value) types.Value

	// Enums lists Enum values that related to the type. These are registered
	// along with the reflector.
	Enums []*rtypes.Enum

	// Types is a list of additional type reflectors that this reflector depends
	// on.
	Types []func() Reflector

	// Dump returns an additional description of the API of the reflector's
	// type. Member and constructor APIs should be described by their respective
	// fields.
	Dump func() dump.TypeDef
}

Reflector defines reflection behavior for a type. It defines how to convert a types.Value between a Lua value, and behaviors when the type is a userdata. It also defines functions for constructing values of the type. A Reflector can be registered with a World.

func (Reflector) DumpAll added in v0.6.0

func (r Reflector) DumpAll() dump.TypeDef

DumpAll returns a full description of the API of the reflector's type by merging the result of Dump, Members, and Constructors.

type ReflectorFlags added in v0.3.0

type ReflectorFlags uint8
const (
	Exprim ReflectorFlags // Whether the type is an explicit primitive.
)

type Setter added in v0.9.0

type Setter func(p interface{}, v types.Value) (err error)

Setter sets known type v to p. p must be a pointer to a known type. Returns an error if v cannot be set to p.

type State added in v0.3.0

type State struct {
	*World

	L *lua.LState

	// FrameType provides a hint to how errors should be produced.
	FrameType FrameType
}

State facilitates the reflection of values to a particular Lua state.

func (State) ArgError added in v0.6.0

func (s State) ArgError(n int, msg string, v ...interface{}) int

ArgError raises an argument error depending on the state's frame type.

func (State) CheckAny added in v0.6.0

func (s State) CheckAny(n int) lua.LValue

CheckAny returns the nth argument, which can be any type as long as the argument exists.

func (State) CheckBool added in v0.6.0

func (s State) CheckBool(n int) bool

CheckBool returns the nth argument, expecting a boolean.

func (State) CheckFunction added in v0.6.0

func (s State) CheckFunction(n int) *lua.LFunction

CheckFunction returns the nth argument, expecting a function.

func (State) CheckInt added in v0.6.0

func (s State) CheckInt(n int) int

CheckInt returns the nth argument as an int, expecting a number.

func (State) CheckInt64 added in v0.6.0

func (s State) CheckInt64(n int) int64

CheckInt64 returns the nth argument as an int64, expecting a number.

func (State) CheckNumber added in v0.6.0

func (s State) CheckNumber(n int) lua.LNumber

CheckNumber returns the nth argument, expecting a number.

func (State) CheckString added in v0.3.0

func (s State) CheckString(n int) string

CheckString returns the nth argument, expecting a string. Unlike LState.CheckString, it does not try to convert non-string values into a string.

func (State) CheckTable added in v0.6.0

func (s State) CheckTable(n int) *lua.LTable

CheckTable returns the nth argument, expecting a table.

func (State) CheckThread added in v0.6.0

func (s State) CheckThread(n int) *lua.LState

CheckThread returns the nth argument, expecting a thread.

func (State) CheckUserData added in v0.6.0

func (s State) CheckUserData(n int) *lua.LUserData

CheckUserData returns the nth argument, expecting a userdata.

func (State) Count added in v0.3.0

func (s State) Count() int

Count returns the number of arguments in the stack frame.

func (State) OptBool added in v0.6.0

func (s State) OptBool(n int, d bool) bool

OptBool returns the nth argument as a bool, or d if the argument is nil.

func (State) OptFunction added in v0.6.0

func (s State) OptFunction(n int, d *lua.LFunction) *lua.LFunction

OptFunction returns the nth argument as a function, or d if the argument is nil.

func (State) OptInt added in v0.6.0

func (s State) OptInt(n int, d int) int

OptInt returns the nth argument as an int, or d if the argument is nil.

func (State) OptInt64 added in v0.6.0

func (s State) OptInt64(n int, d int64) int64

OptInt64 returns the nth argument as an int64, or d if the argument is nil.

func (State) OptNumber added in v0.6.0

func (s State) OptNumber(n int, d lua.LNumber) lua.LNumber

OptNumber returns the nth argument as a number, or d if the argument is nil.

func (State) OptString added in v0.6.0

func (s State) OptString(n int, d string) string

OptString returns the nth argument as a string, or d if the argument is nil.

func (State) OptTable added in v0.6.0

func (s State) OptTable(n int, d *lua.LTable) *lua.LTable

OptTable returns the nth argument as a table, or d if the argument is nil.

func (State) OptUserData added in v0.6.0

func (s State) OptUserData(n int, d *lua.LUserData) *lua.LUserData

OptUserData returns the nth argument as a userdata, or d if the argument is nil.

func (State) Pull added in v0.3.0

func (s State) Pull(n int, t string) (v types.Value)

Pull gets from s.L the values starting from n, and reflects a value from them according to type t registered with s.World.

func (State) PullAnyFromArray added in v0.9.0

func (s State) PullAnyFromArray(table *lua.LTable, index int, t ...string) (v types.Value)

PullAnyFromArray is like PullAnyFromTable, but receives an int as the index of the table.

func (State) PullAnyFromArrayOpt added in v0.9.0

func (s State) PullAnyFromArrayOpt(table *lua.LTable, index int, d types.Value, t ...string) (v types.Value)

PullAnyFromArrayOpt is like PullAnyFromTableOpt, but receives an int as the index of the table.

func (State) PullAnyFromDictionary added in v0.9.0

func (s State) PullAnyFromDictionary(table *lua.LTable, key string, t ...string) (v types.Value)

PullAnyFromDictionary is like PullAnyFromTable, but receives a string as the key of the table.

func (State) PullAnyFromDictionaryOpt added in v0.9.0

func (s State) PullAnyFromDictionaryOpt(table *lua.LTable, key string, d types.Value, t ...string) (v types.Value)

PullAnyFromDictionaryOpt is like PullAnyFromTableOpt, but receives a string as the key of the table.

func (State) PullAnyFromTable added in v0.9.0

func (s State) PullAnyFromTable(table *lua.LTable, field lua.LValue, t ...string) (v types.Value)

PullAnyFromTable gets a value from table[field], and reflects a value from it according to the first successful type from t registered with s.World.

func (State) PullAnyFromTableOpt added in v0.9.0

func (s State) PullAnyFromTableOpt(table *lua.LTable, field lua.LValue, d types.Value, t ...string) (v types.Value)

PullAnyFromTableOpt gets a value from table[field], and reflects a value from it according to the first successful type from t registered with s.World. If the field is nil, then d is returned instead.

func (State) PullAnyOf added in v0.3.0

func (s State) PullAnyOf(n int, t ...string) (v types.Value)

PullAnyOf gets from s.L the values starting from n, and reflects a value from them according to any of the types in t registered with s.World. Returns the first successful reflection among the types in t. If no types succeeded, then a type error is thrown.

func (State) PullAnyOfOpt added in v0.7.0

func (s State) PullAnyOfOpt(n int, d types.Value, t ...string) (v types.Value)

PullAnyOfOpt gets from s.L the values starting from n, and reflects a value from them according to any of the types in t registered with s.World. Returns the first successful reflection among the types in t. If no types succeeded, then nil is returned.

func (State) PullArrayOf added in v0.5.0

func (s State) PullArrayOf(n int, t string) (v rtypes.Array)

PullArrayOf pulls an rtypes.Array from n, ensuring that each element is reflected according to t.

func (State) PullDictionaryOf added in v0.5.0

func (s State) PullDictionaryOf(n int, t string) (v rtypes.Dictionary)

PullDictionaryOf pulls an rtypes.Dictionary from n, ensuring that each field is reflected according to t.

func (State) PullEncoded added in v0.9.0

func (s State) PullEncoded(n int, fs rtypes.FormatSelector) (v types.Value)

PullEncoded pulls a value to be encoded according to a FormatSelector. The referred format is determined, then Format.EncodeTypes is used to pull the value from n. If fs.Format is empty, or if EncodeTypes is empty, then the value is pulled as a Variant.

func (State) PullEncodedFormat added in v0.9.0

func (s State) PullEncodedFormat(n int, f Format) (v types.Value)

PullEncodedFormat pulls a value to be encoded according to a Format. Format.EncodeTypes is used to pull the value from n. If EncodeTypes is empty, then the value is pulled as a Variant.

func (State) PullFromArray added in v0.9.0

func (s State) PullFromArray(table *lua.LTable, index int, t string) (v types.Value)

PullFromArray is like PullFromTable, but receives an int as the index of the table.

func (State) PullFromArrayOpt added in v0.9.0

func (s State) PullFromArrayOpt(table *lua.LTable, index int, d types.Value, t string) (v types.Value)

PullFromArrayOpt is like PullFromTableOpt, but receives an int as the index of the table.

func (State) PullFromDictionary added in v0.9.0

func (s State) PullFromDictionary(table *lua.LTable, key string, t string) (v types.Value)

PullFromDictionary is like PullFromTable, but receives a string as the key of the table.

func (State) PullFromDictionaryOpt added in v0.9.0

func (s State) PullFromDictionaryOpt(table *lua.LTable, key string, d types.Value, t string) (v types.Value)

PullFromDictionaryOpt is like PullFromTableOpt, but receives a string as the key of the table.

func (State) PullFromTable added in v0.4.0

func (s State) PullFromTable(table *lua.LTable, field lua.LValue, t string) (v types.Value)

PullFromTable gets a value from table[field], and reflects a value from it to type t registered with s.World.

func (State) PullFromTableOpt added in v0.4.0

func (s State) PullFromTableOpt(table *lua.LTable, field lua.LValue, d types.Value, t string) (v types.Value)

PullFromTableOpt gets a value from table[field], and reflects a value from it to type t registered with s.World. If the value is nil, d is returned instead.

func (State) PullOpt added in v0.3.0

func (s State) PullOpt(n int, d types.Value, t string) (v types.Value)

PullOpt gets from s.L the value at n, and reflects a value from it according to type t registered with s.World. If the value is nil, d is returned instead.

func (State) PullTuple added in v0.9.0

func (s State) PullTuple(n int) rtypes.Tuple

PullTuple pulls each value starting from n as a Variant.

func (State) Push added in v0.3.0

func (s State) Push(v types.Value) int

Push reflects v according to its type as registered with s.World, then pushes the results to s.L.

func (State) PushArrayOf added in v0.5.0

func (s State) PushArrayOf(v rtypes.Array, t string) int

PushArrayOf pushes an rtypes.Array, ensuring that each element is reflected according to t.

func (State) PushDictionaryOf added in v0.5.0

func (s State) PushDictionaryOf(v rtypes.Dictionary, t string) int

PushDictionaryOf pushes an rtypes.Dictionary, ensuring that each field is reflected according to t.

func (State) PushToArray added in v0.9.0

func (s State) PushToArray(table *lua.LTable, index int, v types.Value)

PushToArray is like PushToTable, but receives an int as the index of the table.

func (State) PushToDictionary added in v0.9.0

func (s State) PushToDictionary(table *lua.LTable, key string, v types.Value)

PushToDictionary is like PushToTable, but receives a string as the key of the table.

func (State) PushToTable added in v0.4.0

func (s State) PushToTable(table *lua.LTable, field lua.LValue, v types.Value)

PushToTable reflects v according to its type as registered with s.World, then sets the result to table[field]. The type must be single-value. Does nothing if v is nil.

func (State) PushTuple added in v0.9.0

func (s State) PushTuple(values ...types.Value) int

PushTuple pushes each value.

func (State) RaiseError added in v0.3.0

func (s State) RaiseError(format string, args ...interface{}) int

RaiseError is a shortcut for LState.RaiseError that returns 0.

func (State) ReflectorError added in v0.6.0

func (s State) ReflectorError(n int) int

ReflectorError raises an error indicating that a reflector pushed or pulled an unexpected type. Under normal circumstances, this error should be unreachable.

func (State) TypeError added in v0.6.0

func (s State) TypeError(n int, want, got string) int

TypeError raises an argument type error depending on the state's frame type.

func (State) Typeof added in v0.9.0

func (s State) Typeof(n int) string

TypeOf returns the result of World.Typeof with the given argument.

type Symbols added in v0.7.0

type Symbols map[rtypes.Symbol]Property

Symbols is a set of properties keyed by symbol.

type TypeError added in v0.3.0

type TypeError struct {
	Want string
	Got  string
}

typeError is an error where a type was received where another was expected.

func (TypeError) Error added in v0.6.0

func (err TypeError) Error() string

Error implements the error interface.

type World added in v0.3.0

type World struct {
	Global

	Client *Client
	FS     sfs.FS
	// contains filtered or unexported fields
}

World contains the entire state of a Lua environment, including a Lua state, and registered Reflectors, Formats, and Sources.

func NewWorld added in v0.3.0

func NewWorld(l *lua.LState) *World

NewWorld returns a World initialized with the given Lua state.

func (*World) Context added in v0.9.0

func (w *World) Context() Context

Context returns a Context derived from the World.

func (*World) DoFile added in v0.3.0

func (w *World) DoFile(fileName string, args int) error

DoFile executes the contents of the file at fileName as Lua. args is the number of arguments currently on the stack that should be passed in. The file is marked as actively running, and is unmarked when the file returns.

func (*World) DoFileHandle added in v0.3.0

func (w *World) DoFileHandle(f fs.File, name string, args int) error

DoFile executes the contents of file f as Lua. args is the number of arguments currently on the stack that should be passed in. The file is marked as actively running, and is unmarked when the file returns.

func (*World) DoString added in v0.3.0

func (w *World) DoString(s, name string, args int) (err error)

DoString executes string s as Lua. args is the number of arguments currently on the stack that should be passed in.

func (*World) Enum added in v0.9.0

func (w *World) Enum(name string) *rtypes.Enum

Enum returns the Enum registered with the given name. If the name is not registered, then nil is returned.

func (*World) Enums added in v0.9.0

func (w *World) Enums() *rtypes.Enums

Enums returns a list of registered enums.

func (*World) Expand added in v0.6.0

func (w *World) Expand(path string) string

Expand expands a string containing predefined variables.

func (*World) Ext added in v0.3.0

func (w *World) Ext(filename string) (ext string)

Ext returns the extension of filename that most closely matches the name of a registered format. Returns an empty string if no format was found.

func (*World) Format added in v0.3.0

func (w *World) Format(name string) Format

Format returns the Format registered with the given name. If the name is not registered, then Format.Name will be an empty string.

func (*World) Formats added in v0.3.0

func (w *World) Formats() []Format

Formats returns a list of registered formats.

func (*World) Libraries added in v0.9.0

func (w *World) Libraries() []Library

Libraries returns a list of registered libraries.

func (*World) Library added in v0.9.0

func (w *World) Library(name string) Library

Library returns the Library registered with the given name. If the name is not registered, then Library.Name will be an empty string.

func (*World) ListTypes added in v0.9.0

func (w *World) ListTypes(types []string) string

ListTypes returns each type listed in a natural sentence.

func (*World) LuaState added in v0.9.0

func (w *World) LuaState() *lua.LState

LuaState returns the underlying Lua state.

func (*World) MergeTables added in v0.3.0

func (w *World) MergeTables(dst, src *lua.LTable, name string) error

MargeTables merges src into dst according to name. If name is empty, then each key in src is set in dst. If dst[name] is a table, then each key in src is set in that table. If dst[name] is nil, then it is set directly to src. Does nothing if src or dst is nil. Returns an error if the tables could not be merged.

func (*World) MustEnum added in v0.9.0

func (w *World) MustEnum(name string) *rtypes.Enum

MustEnum returns the Enum registered with the given name. If the name is not registered, then MustEnum panics.

func (*World) MustReflector added in v0.6.0

func (w *World) MustReflector(name string) Reflector

MustReflector returns the Reflector registered with the given name. If the name is not registered, then MustReflector panics.

func (*World) Open added in v0.3.0

func (w *World) Open(lib Library) error

Open opens lib, then merges the result into the world's global table using the ImportedAs field as the name. If the name is already present and is a table, then the table of lib is merged into it, preferring the values of lib. If the name is an empty string, then lib is merged into the global table itself.

The library is registered with the world under the Name of the library. An error is returned if the merged value is not a table, or if the name was already registered.

func (*World) PeekFile added in v0.3.0

func (w *World) PeekFile() (entry FileEntry, ok bool)

PeekFile returns the info of the currently running file. Returns false if there is no running file.

func (*World) PopFile added in v0.3.0

func (w *World) PopFile()

PopFile unmarks the currently running file. If the last file on the stack is popped, the file's directory is removed as a root from w.FS.

func (*World) Pull added in v0.3.0

func (w *World) Pull(lv lua.LValue, t string) (v types.Value, err error)

Pull reflects lv to v using registered type t.

func (*World) PullAnyFromArray added in v0.9.0

func (w *World) PullAnyFromArray(table *lua.LTable, index int, t ...string) (v types.Value, err error)

PullAnyFromArray is like PullAnyFromTable, but receives an int as the index of the table.

func (*World) PullAnyFromArrayOpt added in v0.9.0

func (w *World) PullAnyFromArrayOpt(table *lua.LTable, index int, d types.Value, t ...string) (v types.Value, err error)

PullAnyFromArrayOpt is like PullAnyFromTableOpt, but receives an int as the index of the table.

func (*World) PullAnyFromDictionary added in v0.9.0

func (w *World) PullAnyFromDictionary(table *lua.LTable, key string, t ...string) (v types.Value, err error)

PullAnyFromDictionary is like PullAnyFromTable, but receives a string as the key of the table.

func (*World) PullAnyFromDictionaryOpt added in v0.9.0

func (w *World) PullAnyFromDictionaryOpt(table *lua.LTable, key string, d types.Value, t ...string) (v types.Value, err error)

PullAnyFromDictionaryOpt is like PullAnyFromTableOpt, but receives a string as the key of the table.

func (*World) PullAnyFromTable added in v0.9.0

func (w *World) PullAnyFromTable(table *lua.LTable, field lua.LValue, t ...string) (v types.Value, err error)

PullAnyFromTable gets a value from table[field], and reflects a value from it according to the first successful type from t registered with s.World.

func (*World) PullAnyFromTableOpt added in v0.9.0

func (w *World) PullAnyFromTableOpt(table *lua.LTable, field lua.LValue, d types.Value, t ...string) (v types.Value, err error)

PullAnyFromTableOpt gets a value from table[field], and reflects a value from it according to the first successful type from t registered with s.World. If the field is nil, then d is returned instead.

func (*World) PullAnyOf added in v0.3.0

func (w *World) PullAnyOf(lv lua.LValue, t ...string) (v types.Value, err error)

PullAnyOf reflects lv to the first successful type from t. Returns an error if none of the types were successful.

func (*World) PullAnyOfOpt added in v0.9.0

func (w *World) PullAnyOfOpt(lv lua.LValue, d types.Value, t ...string) (v types.Value)

PullAnyOfOpt reflects lv to the first successful type from t. Returns d if none of the types were successful.

func (*World) PullArrayOf added in v0.9.0

func (w *World) PullArrayOf(lv lua.LValue, t string) (v rtypes.Array, err error)

PullArrayOf reflects lv to v, ensuring that lv is a table, and that each element is reflected according to t.

func (*World) PullDictionaryOf added in v0.9.0

func (w *World) PullDictionaryOf(lv lua.LValue, t string) (v rtypes.Dictionary, err error)

PullDictionaryOf reflects lv to v, ensuring that lv is a table, and that each string field is reflected according to t.

func (*World) PullEncoded added in v0.9.0

func (w *World) PullEncoded(lv lua.LValue, fs rtypes.FormatSelector) (v types.Value, err error)

PullEncoded pulls a value to be encoded according to a FormatSelector. The referred format is acquired, then Format.EncodeTypes is used to reflect the value from lv. If fs.Format is empty, or if EncodeTypes is empty, then the value is pulled as a Variant.

func (*World) PullEncodedFormat added in v0.9.0

func (w *World) PullEncodedFormat(lv lua.LValue, f Format) (v types.Value, err error)

PullEncodedFormat pulls a value to be encoded according to f. Format.EncodeTypes is used to reflect the value from lv. If EncodeTypes is empty, then the value is pulled as a Variant.

func (*World) PullEncodedFromDict added in v0.9.0

func (w *World) PullEncodedFromDict(table *lua.LTable, field string, format rtypes.FormatSelector) (v types.Value, err error)

PullEncodedFromDict is like PullEncoded, but the value is pulled from a Dictionary.

func (*World) PullFromArray added in v0.9.0

func (w *World) PullFromArray(table *lua.LTable, index int, t string) (v types.Value, err error)

PullFromArray is like PullFromTable, but receives an int as the index of the table.

func (*World) PullFromArrayOpt added in v0.9.0

func (w *World) PullFromArrayOpt(table *lua.LTable, index int, d types.Value, t string) (v types.Value, err error)

PullFromArrayOpt is like PullFromTableOpt, but receives an int as the index of the table.

func (*World) PullFromDictionary added in v0.9.0

func (w *World) PullFromDictionary(table *lua.LTable, key string, t string) (v types.Value, err error)

PullFromDictionary is like PullFromTable, but receives a string as the key of the table.

func (*World) PullFromDictionaryOpt added in v0.9.0

func (w *World) PullFromDictionaryOpt(table *lua.LTable, key string, d types.Value, t string) (v types.Value, err error)

PullFromDictionaryOpt is like PullFromTableOpt, but receives a string as the key of the table.

func (*World) PullFromTable added in v0.9.0

func (w *World) PullFromTable(table *lua.LTable, field lua.LValue, t string) (v types.Value, err error)

PullFromTable gets a value from table[field], and reflects a value from it to type t registered with s.World.

func (*World) PullFromTableOpt added in v0.9.0

func (w *World) PullFromTableOpt(table *lua.LTable, field lua.LValue, d types.Value, t string) (v types.Value, err error)

PullFromTableOpt gets a value from table[field], and reflects a value from it to type t registered with s.World. If the value is nil, d is returned instead.

func (*World) PullOpt added in v0.3.0

func (w *World) PullOpt(lv lua.LValue, d types.Value, t string) (v types.Value, err error)

PullOpt reflects lv to v using registered type t. If lv is nil, then d is returned instead.

func (*World) PullerOf added in v0.9.0

func (w *World) PullerOf(name string) (p Puller, err error)

PullerOf returns the PullFrom field for the Reflector registered as name. Returns an error if the name is not registered, or if the reflector does not define PullFrom.

func (*World) Push added in v0.3.0

func (w *World) Push(v types.Value) (lv lua.LValue, err error)

Push reflects v to lv.

func (*World) PushArrayOf added in v0.9.0

func (w *World) PushArrayOf(v rtypes.Array, t string) (lv *lua.LTable, err error)

PushArrayOf reflect v to lv, ensuring that each element is reflected according to t.

func (*World) PushDictionaryOf added in v0.9.0

func (w *World) PushDictionaryOf(v rtypes.Dictionary, t string) (lv *lua.LTable, err error)

PushDictionaryOf reflect v to lv, ensuring that each field is reflected according to t.

func (*World) PushFile added in v0.3.0

func (w *World) PushFile(entry FileEntry) error

PushFile marks a file as the currently running file. Returns an error if the file is already running. If the file is the first file pushed, its directory is added as a root to w.FS.

func (*World) PushToArray added in v0.9.0

func (w *World) PushToArray(table *lua.LTable, index int, v types.Value) (err error)

PushToArray is like PushToTable, but receives an int as the index of the table.

func (*World) PushToDictionary added in v0.9.0

func (w *World) PushToDictionary(table *lua.LTable, key string, v types.Value) (err error)

PushToDictionary is like PushToTable, but receives a string as the key of the table.

func (*World) PushToTable added in v0.9.0

func (w *World) PushToTable(table *lua.LTable, field lua.LValue, v types.Value) (err error)

PushToTable reflects v according to its type as registered with s.World, then sets the result to table[field]. The type must be single-value. Does nothing if v is nil.

func (*World) PusherOf added in v0.9.0

func (w *World) PusherOf(name string) (p Pusher, err error)

PusherOf returns the PushTo field for the Reflector registered as name. Returns an error if the name is not registered, or if the reflector does not define PushTo.

func (*World) Reflector added in v0.3.0

func (w *World) Reflector(name string) Reflector

Reflector returns the Reflector registered with the given name. If the name is not registered, then Reflector.Name will be an empty string.

func (*World) Reflectors added in v0.3.0

func (w *World) Reflectors(flags ReflectorFlags) []Reflector

Reflectors returns a list of reflectors that have all of the given flags set.

func (*World) RegisterEnums added in v0.9.0

func (w *World) RegisterEnums(enums ...*rtypes.Enum)

RegisterEnums registers a number of Enum values. Panics if multiple different enums are registered with the same name.

func (*World) RegisterFormat added in v0.3.0

func (w *World) RegisterFormat(f Format)

RegisterFormat registers a format. Panics if the format is already registered.

func (*World) RegisterReflector added in v0.3.0

func (w *World) RegisterReflector(r Reflector)

RegisterReflector registers a reflector. If the reflector produces a metatable, then it is added as a type metatable to the world's state. Panics if the reflector is already registered.

func (*World) RootDir added in v0.5.0

func (w *World) RootDir() string

RootDir returns the directory of the first file pushed onto the running file stack. Returns an empty string if there are no files on the stack, or the absolute path of the file could not be determined.

func (*World) SetEnumGlobal added in v0.9.0

func (w *World) SetEnumGlobal()

SetEnumGlobal sets the "Enum" global to the generated enum types from w.Global.Desc. Does nothing if Desc is nil, the Enums type is not registered, or if the Enums reflector returns an error.

func (*World) SetterOf added in v0.9.0

func (w *World) SetterOf(name string) (s Setter, err error)

SetterOf returns the SetTo field for the Reflector registered as name. Returns an error if the name is not registered, or if the reflector does not define SetTo.

func (*World) Split added in v0.6.0

func (w *World) Split(path string, components ...string) ([]string, error)

Split returns the components of a file path.

func (*World) State added in v0.3.0

func (w *World) State() State

State returns a State derived from the World.

func (*World) TempDir added in v0.5.0

func (w *World) TempDir() string

TempDir returns a directory used for temporary files, which is unique per world. Returns an empty string if a temporary directory could not be found.

func (*World) Typeof added in v0.6.0

func (w *World) Typeof(v lua.LValue) string

Typeof returns the type of the given Lua value. If it is a userdata, Typeof attempts to get the type according to the value's metatable. Panics if v is nil (not if nil Lua value).

func (*World) UserDataCacheLen added in v0.3.0

func (w *World) UserDataCacheLen() int

UserDataCacheLen return the number of userdata values in the cache.

func (*World) UserDataOf added in v0.3.0

func (w *World) UserDataOf(v types.Value, t string) *lua.LUserData

UserDataOf returns the userdata value associated with v. If there is no such userdata, then a new one is created, with the metatable set to the type corresponding to t.

v must be comparable.

func (*World) WrapFunc added in v0.3.0

func (w *World) WrapFunc(f func(State) int) *lua.LFunction

WrapFunc wraps a function that receives a State into a Lua function.

func (*World) WrapMethod added in v0.6.0

func (w *World) WrapMethod(f func(State) int) *lua.LFunction

WrapMethod is like WrapFunc, but marks the state as being a method.

func (*World) WrapOperator added in v0.6.0

func (w *World) WrapOperator(f func(State) int) *lua.LFunction

WrapOperator is like WrapFunc, but marks the state as being an operator.

Directories

Path Synopsis
Tool to increment the version number, read and write rbxmk/version.go, then create and tag a commit.
Tool to increment the version number, read and write rbxmk/version.go, then create and tag a commit.
The dump package describes Lua APIs.
The dump package describes Lua APIs.
dt
The dt package describes the types of Lua API items.
The dt package describes the types of Lua API items.
The fragments package contains translations of documentation fragments.
The fragments package contains translations of documentation fragments.
htmldrill
The htmldrill package implements a drill/filesys.Handler for the HTML format.
The htmldrill package implements a drill/filesys.Handler for the HTML format.
term
The term package implements rendering HTML content for the terminal.
The term package implements rendering HTML content for the terminal.
The sfs package providing a secure file system, with access limitations.
The sfs package providing a secure file system, with access limitations.

Jump to

Keyboard shortcuts

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