Skip to main content

yue

Description:

  The Yuescript language library.

version

Type: Field.

Description:

  The Yuescript version.

Signature:

version: string

dirsep

Type: Field.

Description:

  The file separator for the current platform.

Signature:

dirsep: string

yue_compiled

Type: Field.

Description:

  The compiled module code cache.

Signature:

yue_compiled: {string: string}

to_lua

Type: Function.

Description:

  The Yuescript compiling function. It compiles the Yuescript code to Lua code.

Signature:

to_lua: function(code: string, config?: Config):
--[[codes]] string | nil,
--[[error]] string | nil,
--[[globals]] {{string, integer, integer}} | nil

Parameters:

ParameterTypeDescription
codestringThe Yuescript code.
configConfig[Optional] The compiler options.

Returns:

Return TypeDescription
string | nilThe compiled Lua code, or nil if the compilation failed.
string | nilThe error message, or nil if the compilation succeeded.
{{string, integer, integer}} | nilThe global variables appearing in the code (with name, row and column), or nil if the compiler option lint_global is false.

file_exist

Type: Function.

Description:

  The source file existence checking function. Can be overridden to customize the behavior.

Signature:

file_exist: function(filename: string): boolean

Parameters:

ParameterTypeDescription
filenamestringThe file name.

Returns:

Return TypeDescription
booleanWhether the file exists.

read_file

Type: Function.

Description:

  The source file reading function. Can be overridden to customize the behavior.

Signature:

read_file: function(filename: string): string

Parameters:

ParameterTypeDescription
filenamestringThe file name.

Returns:

Return TypeDescription
stringThe file content.

insert_loader

Type: Function.

Description:

  Insert the Yuescript loader to the package loaders (searchers).

Signature:

insert_loader: function(pos?: integer): boolean

Parameters:

ParameterTypeDescription
posinteger[Optional] The position to insert the loader. Default is 3.

Returns:

Return TypeDescription
booleanWhether the loader is inserted successfully. It will fail if the loader is already inserted.

remove_loader

Type: Function.

Description:

  Remove the Yuescript loader from the package loaders (searchers).

Signature:

remove_loader: function(): boolean

Returns:

Return TypeDescription
booleanWhether the loader is removed successfully. It will fail if the loader is not inserted.

loadstring

Type: Function.

Description:

  Loads Yuescript code from a string into a function.

Signature:

loadstring: function(input: string, chunkname: string, env: table, config?: Config):
--[[loaded function]] nil | function(...: any): (any...),
--[[error]] string | nil

Parameters:

ParameterTypeDescription
inputstringThe Yuescript code.
chunknamestringThe name of the code chunk.
envtableThe environment table.
configConfig[Optional] The compiler options.

Returns:

Return TypeDescription
function | nilThe loaded function, or nil if the loading failed.
string | nilThe error message, or nil if the loading succeeded.

loadstring

Type: Function.

Description:

  Loads Yuescript code from a string into a function.

Signature:

loadstring: function(input: string, chunkname: string, config?: Config):
--[[loaded function]] nil | function(...: any): (any...),
--[[error]] string | nil

Parameters:

ParameterTypeDescription
inputstringThe Yuescript code.
chunknamestringThe name of the code chunk.
configConfig[Optional] The compiler options.

Returns:

Return TypeDescription
function | nilThe loaded function, or nil if the loading failed.
string | nilThe error message, or nil if the loading succeeded.

loadstring

Type: Function.

Description:

  Loads Yuescript code from a string into a function.

Signature:

loadstring: function(input: string, config?: Config):
--[[loaded function]] nil | function(...: any): (any...),
--[[error]] string | nil

Parameters:

ParameterTypeDescription
inputstringThe Yuescript code.
configConfig[Optional] The compiler options.

Returns:

Return TypeDescription
function | nilThe loaded function, or nil if the loading failed.
string | nilThe error message, or nil if the loading succeeded.

loadfile

Type: Function.

Description:

  Loads Yuescript code from a file into a function.

Signature:

loadfile: function(filename: string, env: table, config?: Config):
nil | function(...: any): (any...),
string | nil

Parameters:

ParameterTypeDescription
filenamestringThe file name.
envtableThe environment table.
configConfig[Optional] The compiler options.

Returns:

Return TypeDescription
function | nilThe loaded function, or nil if the loading failed.
string | nilThe error message, or nil if the loading succeeded.

loadfile

Type: Function.

Description:

  Loads Yuescript code from a file into a function.

Signature:

loadfile: function(filename: string, config?: Config):
nil | function(...: any): (any...),
string | nil

Parameters:

ParameterTypeDescription
filenamestringThe file name.
configConfig[Optional] The compiler options.

Returns:

Return TypeDescription
function | nilThe loaded function, or nil if the loading failed.
string | nilThe error message, or nil if the loading succeeded.

dofile

Type: Function.

Description:

  Loads Yuescript code from a file into a function and executes it.

Signature:

dofile: function(filename: string, env: table, config?: Config): any...

Parameters:

ParameterTypeDescription
filenamestringThe file name.
envtableThe environment table.
configConfig[Optional] The compiler options.

Returns:

Return TypeDescription
any...The return values of the loaded function.

dofile

Type: Function.

Description:

  Loads Yuescript code from a file into a function and executes it.

Signature:

dofile: function(filename: string, config?: Config): any...

Parameters:

ParameterTypeDescription
filenamestringThe file name.
configConfig[Optional] The compiler options.

Returns:

Return TypeDescription
any...The return values of the loaded function.

find_modulepath

Type: Function.

Description:

  Resolves the Yuescript module name to the file path.

Signature:

find_modulepath: function(name: string): string

Parameters:

ParameterTypeDescription
namestringThe module name.

Returns:

Return TypeDescription
stringThe file path.

pcall

Type: Function.

Description:

  Calls a function in protected mode. Catches any errors and returns a status code and results or error object. Rewrites the error line number to the original line number in the Yuescript code when errors occur.

Signature:

pcall: function(f: function, ...: any): boolean, any...

Parameters:

ParameterTypeDescription
ffunctionThe function to call.
...anyArguments to pass to the function.

Returns:

Return TypeDescription
boolean, ...Status code and function results or error object.

require

Type: Function.

Description:

  Loads a given module. Can be either a Lua module or a Yuescript module. Rewrites the error line number to the original line number in the Yuescript code if the module is a Yuescript module and loading fails.

Signature:

require: function(name: string): any...

Parameters:

ParameterTypeDescription
modnamestringThe name of the module to load.

Returns:

Return TypeDescription
anyThe value stored at package.loaded[modname] if the module is already loaded.Otherwise, tries to find a loader and returns the final value of package.loaded[modname] and a loader data as a second result.

p

Type: Function.

Description:

  Inspects the structures of the passed values and prints string representations.

Signature:

p: function(...: any)

Parameters:

ParameterTypeDescription
...anyThe values to inspect.

options

Type: Field.

Description:

  The current compiler options.

Signature:

options: Config.Options

traceback

Type: Function.

Description:

  The traceback function that rewrites the stack trace line numbers to the original line numbers in the Yuescript code.

Signature:

traceback: function(message: string): string

Parameters:

ParameterTypeDescription
messagestringThe traceback message.

Returns:

Return TypeDescription
stringThe rewritten traceback message.

compile

Type: Function.

Description:

  Compiles the Yuescript code to Lua code in a thread.

Signature:

compile: function(
sourceFile: string,
targetFile: string,
searchPath: string,
compileCodesHandler: CompileCodeHandler,
callback: function(result: boolean)
)

Parameters:

ParameterTypeDescription
sourceFilestringThe source file name.
targetFilestringThe target file name.
searchPathstringThe extra module search path.
compileCodesHandlerCompileCodeHandlerThe callback function to handle the compiled codes.
callbackfunctionThe callback function to handle the result.

is_ast

Type: Function.

Description:

  Checks whether the code matches the specified AST.

Signature:

is_ast: function(astName: string, code: string): boolean

Parameters:

ParameterTypeDescription
astNamestringThe AST name.
codestringThe code.

Returns:

Return TypeDescription
booleanWhether the code matches the AST.

AST

Type: Field.

Description:

  The AST type definition with name, row, column and sub nodes.

Signature:

type AST = {string, integer, integer, any}

to_ast

Type: Function.

Description:

  Converts the code to the AST.

Signature:

to_ast: function(code: string, flattenLevel?: number, astName?: string):
--[[AST]] AST | nil,
--[[error]] nil | string

Parameters:

ParameterTypeDescription
codestringThe code.
flattenLevelinteger[Optional] The flatten level. Higher level means more flattening. Default is 0. Maximum is 2.
astNamestring[Optional] The AST name. Default is "File".

Returns:

Return TypeDescription
AST | nilThe AST, or nil if the conversion failed.
string | nilThe error message, or nil if the conversion succeeded.

checkAsync

Type: Function.

Description:

  Checks for the problems in the Yuescript code asynchronously. Should be called in a coroutine thread.

Signature:

checkAsync: function(yueCodes: string, searchPath: string):
--[[info]] {{
--[[type]] string,
--[[msg]] string,
--[[line]] integer,
--[[col]] integer
}},
--[[luaCodes]] string | nil

Parameters:

ParameterTypeDescription
yueCodesstringThe Yuescript code.
searchPathstringThe extra module search path.

Returns:

Return TypeDescription
{info}The problem information with type, message, line and column as an array.
string | nilThe Lua codes when no problem found, or nil if the checking failed.

clear

Type: Function.

Description:

  Clears the compiled macro functions in cache.

Signature:

clear: function()

__call

Type: Metamethod.

Description:

  Requires the Yuescript module. Rewrites the error line number to the original line number in the Yuescript code when loading fails.

Signature:

metamethod __call: function(self: yue, module: string): any...

Parameters:

ParameterTypeDescription
modulestringThe module name.

Returns:

Return TypeDescription
anyThe module value.