From a3bde93c37e59d8d0e47d61bfde9b28a95eded89 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Sat, 10 Aug 2024 22:04:38 +0800 Subject: update docs. --- doc/docs/doc/README.md | 781 ++++++++++++++++++++++++++++++++++++++++++++++ doc/docs/zh/doc/README.md | 773 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1554 insertions(+) diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 378e0f4..f6aebfc 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md @@ -3575,6 +3575,787 @@ print i, k -- these have been updated +## The Yuescript Library + +Access it by `require("yue")`. + +### yue + +**Description:** + +The Yuescript language library. + +#### version + +**Type:** Field. + +**Description:** + +The Yuescript version. + +**Signature:** +```lua +version: string +``` + +#### dirsep + +**Type:** Field. + +**Description:** + +The file separator for the current platform. + +**Signature:** +```lua +dirsep: string +``` + +#### yue_compiled + +**Type:** Field. + +**Description:** + +The compiled module code cache. + +**Signature:** +```lua +yue_compiled: {string: string} +``` + +#### to_lua + +**Type:** Function. + +**Description:** + +The Yuescript compiling function. It compiles the Yuescript code to Lua code. + +**Signature:** +```lua +to_lua: function(code: string, config?: Config): + --[[codes]] string | nil, + --[[error]] string | nil, + --[[globals]] {{string, integer, integer}} | nil +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| code | string | The Yuescript code. | +| config | Config | [Optional] The compiler options. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| string \| nil | The compiled Lua code, or nil if the compilation failed. | +| string \| nil | The error message, or nil if the compilation succeeded. | +| \{\{string, integer, integer}} \| nil | The 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:** +```lua +file_exist: function(filename: string): boolean +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| filename | string | The file name. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| boolean | Whether the file exists. | + +#### read_file + +**Type:** Function. + +**Description:** + +The source file reading function. Can be overridden to customize the behavior. + +**Signature:** +```lua +read_file: function(filename: string): string +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| filename | string | The file name. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| string | The file content. | + +#### insert_loader + +**Type:** Function. + +**Description:** + +Insert the Yuescript loader to the package loaders (searchers). + +**Signature:** +```lua +insert_loader: function(pos?: integer): boolean +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| pos | integer | [Optional] The position to insert the loader. Default is 3. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| boolean | Whether 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:** +```lua +remove_loader: function(): boolean +``` + +**Returns:** + +| Return Type | Description | +| --- | --- | +| boolean | Whether 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:** +```lua +loadstring: function(input: string, chunkname: string, env: table, config?: Config): + --[[loaded function]] nil | function(...: any): (any...), + --[[error]] string | nil +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| input | string | The Yuescript code. | +| chunkname | string | The name of the code chunk. | +| env | table | The environment table. | +| config | Config | [Optional] The compiler options. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| function \| nil | The loaded function, or nil if the loading failed. | +| string \| nil | The error message, or nil if the loading succeeded. | + +#### loadstring + +**Type:** Function. + +**Description:** + +Loads Yuescript code from a string into a function. + +**Signature:** +```lua +loadstring: function(input: string, chunkname: string, config?: Config): + --[[loaded function]] nil | function(...: any): (any...), + --[[error]] string | nil +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| input | string | The Yuescript code. | +| chunkname | string | The name of the code chunk. | +| config | Config | [Optional] The compiler options. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| function \| nil | The loaded function, or nil if the loading failed. | +| string \| nil | The error message, or nil if the loading succeeded. | + +#### loadstring + +**Type:** Function. + +**Description:** + +Loads Yuescript code from a string into a function. + +**Signature:** +```lua +loadstring: function(input: string, config?: Config): + --[[loaded function]] nil | function(...: any): (any...), + --[[error]] string | nil +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| input | string | The Yuescript code. | +| config | Config | [Optional] The compiler options. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| function \| nil | The loaded function, or nil if the loading failed. | +| string \| nil | The error message, or nil if the loading succeeded. | + +#### loadfile + +**Type:** Function. + +**Description:** + +Loads Yuescript code from a file into a function. + +**Signature:** +```lua +loadfile: function(filename: string, env: table, config?: Config): + nil | function(...: any): (any...), + string | nil +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| filename | string | The file name. | +| env | table | The environment table. | +| config | Config | [Optional] The compiler options. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| function \| nil | The loaded function, or nil if the loading failed. | +| string \| nil | The error message, or nil if the loading succeeded. | + +#### loadfile + +**Type:** Function. + +**Description:** + +Loads Yuescript code from a file into a function. + +**Signature:** +```lua +loadfile: function(filename: string, config?: Config): + nil | function(...: any): (any...), + string | nil +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| filename | string | The file name. | +| config | Config | [Optional] The compiler options. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| function \| nil | The loaded function, or nil if the loading failed. | +| string \| nil | The 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:** +```lua +dofile: function(filename: string, env: table, config?: Config): any... +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| filename | string | The file name. | +| env | table | The environment table. | +| config | Config | [Optional] The compiler options. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| 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:** +```lua +dofile: function(filename: string, config?: Config): any... +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| filename | string | The file name. | +| config | Config | [Optional] The compiler options. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| any... | The return values of the loaded function. | + +#### find_modulepath + +**Type:** Function. + +**Description:** + +Resolves the Yuescript module name to the file path. + +**Signature:** +```lua +find_modulepath: function(name: string): string +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| name | string | The module name. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| string | The 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:** +```lua +pcall: function(f: function, ...: any): boolean, any... +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| f | function | The function to call. | +| ... | any | Arguments to pass to the function. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| 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:** +```lua +require: function(name: string): any... +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| modname | string | The name of the module to load. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| any | The 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:** +```lua +p: function(...: any) +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| ... | any | The values to inspect. | + +#### options + +**Type:** Field. + +**Description:** + +The current compiler options. + +**Signature:** +```lua +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:** +```lua +traceback: function(message: string): string +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| message | string | The traceback message. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| string | The rewritten traceback message. | + +#### is_ast + +**Type:** Function. + +**Description:** + +Checks whether the code matches the specified AST. + +**Signature:** +```lua +is_ast: function(astName: string, code: string): boolean +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| astName | string | The AST name. | +| code | string | The code. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| boolean | Whether the code matches the AST. | + +#### AST + +**Type:** Field. + +**Description:** + +The AST type definition with name, row, column and sub nodes. + +**Signature:** +```lua +type AST = {string, integer, integer, any} +``` + +#### to_ast + +**Type:** Function. + +**Description:** + +Converts the code to the AST. + +**Signature:** +```lua +to_ast: function(code: string, flattenLevel?: number, astName?: string): + --[[AST]] AST | nil, + --[[error]] nil | string +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| code | string | The code. | +| flattenLevel | integer | [Optional] The flatten level. Higher level means more flattening. Default is 0. Maximum is 2. | +| astName | string | [Optional] The AST name. Default is "File". | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| AST \| nil | The AST, or nil if the conversion failed. | +| string \| nil | The error message, or nil if the conversion succeeded. | + +#### __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:** +```lua +metamethod __call: function(self: yue, module: string): any... +``` + +**Parameters:** + +| Parameter | Type | Description | +| --- | --- | --- | +| module | string | The module name. | + +**Returns:** + +| Return Type | Description | +| --- | --- | +| any | The module value. | + +### Config + +**Description:** + +The compiler compile options. + +#### lint_global + +**Type:** Field. + +**Description:** + +Whether the compiler should collect the global variables appearing in the code. + +**Signature:** +```lua +lint_global: boolean +``` + +#### implicit_return_root + +**Type:** Field. + +**Description:** + +Whether the compiler should do an implicit return for the root code block. + +**Signature:** +```lua +implicit_return_root: boolean +``` + +#### reserve_line_number + +**Type:** Field. + +**Description:** + +Whether the compiler should reserve the original line number in the compiled code. + +**Signature:** +```lua +reserve_line_number: boolean +``` + +#### space_over_tab + +**Type:** Field. + +**Description:** + +Whether the compiler should use the space character instead of the tab character in the compiled code. + +**Signature:** +```lua +space_over_tab: boolean +``` + +#### same_module + +**Type:** Field. + +**Description:** + +Whether the compiler should treat the code to be compiled as the same currently being compiled module. For internal use only. + +**Signature:** +```lua +same_module: boolean +``` + +#### line_offset + +**Type:** Field. + +**Description:** + +Whether the compiler error message should include the line number offset. For internal use only. + +**Signature:** +```lua +line_offset: integer +``` + +#### yue.Config.LuaTarget + +**Type:** Enumeration. + +**Description:** + +The target Lua version enumeration. + +**Signature:** +```lua +enum LuaTarget + "5.1" + "5.2" + "5.3" + "5.4" + "5.5" +end +``` + +#### options + +**Type:** Field. + +**Description:** + +The extra options to be passed to the compilation function. + +**Signature:** +```lua +options: Options +``` + +### Options + +**Description:** + +The extra compiler options definition. + +#### target + +**Type:** Field. + +**Description:** + +The target Lua version for the compilation. + +**Signature:** +```lua +target: LuaTarget +``` + +#### path + +**Type:** Field. + +**Description:** + +The extra module search path. + +**Signature:** +```lua +path: string +``` + +#### dump_locals + +**Type:** Field. + +**Description:** + +Whether to dump the local variables in the traceback error message. Default is false. + +**Signature:** +```lua +dump_locals: boolean +``` + +#### simplified + +**Type:** Field. + +**Description:** + +Whether to simplify the error message. Default is true. + +**Signature:** +```lua +simplified: boolean +``` + ## Licence: MIT Copyright (c) 2024 Li Jin diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md index 90d1820..871edd2 100755 --- a/doc/docs/zh/doc/README.md +++ b/doc/docs/zh/doc/README.md @@ -3531,6 +3531,779 @@ print i, k -- 这些已经被更新 +## 月之脚本语言库 + +使用`require("yue")`来访问。 + +### yue + +**描述:** + +月之脚本语言库。 + +#### version + +**类型:** 成员变量。 + +**描述:** + +月之脚本版本。 + +**签名:** +```tl +version: string +``` + +#### dirsep + +**类型:** 成员变量。 + +**描述:** + +当前平台的文件分隔符。 + +**签名:** +```tl +dirsep: string +``` + +#### yue_compiled + +**类型:** 成员变量。 + +**描述:** + +编译模块代码缓存。 + +**签名:** +```tl +yue_compiled: {string: string} +``` + +#### to_lua + +**类型:** 函数。 + +**描述:** + +月之脚本的编译函数。它将 Yuescript 代码编译为 Lua 代码。 + +**签名:** +```tl +to_lua: function(code: string, config?: Config): + --[[codes]] string | nil, + --[[error]] string | nil, + --[[globals]] {{string, integer, integer}} | nil +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| code | string | Yuescript 代码。 | +| config | Config | [可选] 编译器选项。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| string \| nil | 编译后的 Lua 代码,如果编译失败则为 nil。 | +| string \| nil | 错误消息,如果编译成功则为 nil。 | +| \{\{string, integer, integer}} \| nil | 代码中出现的全局变量(带有名称、行和列),如果编译器选项 `lint_global` 为 false 则为 nil。 | + +#### file_exist + +**类型:** 函数。 + +**描述:** + +检查源文件是否存在的函数。可以覆盖该函数以自定义行为。 + +**签名:** +```tl +file_exist: function(filename: string): boolean +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| filename | string | 文件名。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| boolean | 文件是否存在。 | + +#### read_file + +**类型:** 函数。 + +**描述:** + +读取源文件的函数。可以覆盖该函数以自定义行为。 + +**签名:** +```tl +read_file: function(filename: string): string +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| filename | string | 文件名。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| string | 文件内容。 | + +#### insert_loader + +**类型:** 函数。 + +**描述:** + +将 Yuescript 加载器插入到 Lua 包加载器(搜索器)中。 + +**签名:** +```tl +insert_loader: function(pos?: integer): boolean +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| pos | integer | [可选] 要插入加载器的位置。默认为 3。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| boolean | 是否成功插入加载器。如果加载器已经插入,则返回失败。 | + +#### remove_loader + +**类型:** 函数。 + +**描述:** + +从 Lua 包加载器(搜索器)中移除 Yuescript 加载器。 + +**签名:** +```tl +remove_loader: function(): boolean +``` + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| boolean | 是否成功移除加载器。如果加载器未插入,则返回失败。 | + +#### loadstring + +**类型:** 函数。 + +**描述:** + +将 Yuescript 代码字符串加载为一个函数。 + +**签名:** +```tl +loadstring: function(input: string, chunkname: string, env: table, config?: Config): + --[[loaded function]] nil | function(...: any): (any...), + --[[error]] string | nil +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| input | string | Yuescript 代码。 | +| chunkname | string | 代码块的名称。 | +| env | table | 环境表。 | +| config | Config | [可选] 编译器选项。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| function \| nil | 加载的函数,如果加载失败则为 nil。 | +| string \| nil | 错误消息,如果加载成功则为 nil。 | + +#### loadstring + +**类型:** 函数。 + +**描述:** + +将 Yuescript 代码字符串加载为一个函数。 + +**签名:** +```tl +loadstring: function(input: string, chunkname: string, config?: Config): + --[[loaded function]] nil | function(...: any): (any...), + --[[error]] string | nil +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| input | string | Yuescript 代码。 | +| chunkname | string | 代码块的名称。 | +| config | Config | [可选] 编译器选项。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| function \| nil | 加载的函数,如果加载失败则为 nil。 | +| string \| nil | 错误消息,如果加载成功则为 nil。 | + +#### loadstring + +**类型:** 函数。 + +**描述:** + +将 Yuescript 代码字符串加载为一个函数。 + +**签名:** +```tl +loadstring: function(input: string, config?: Config): + --[[loaded function]] nil | function(...: any): (any...), + --[[error]] string | nil +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| input | string | Yuescript 代码。 | +| config | Config | [可选] 编译器选项。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| function \| nil | 加载的函数,如果加载失败则为 nil。 | +| string \| nil | 错误消息,如果加载成功则为 nil。 | + +#### loadfile + +**类型:** 函数。 + +**描述:** + +将 Yuescript 代码文件加载为一个函数。 + +**签名:** +```tl +loadfile: function(filename: string, env: table, config?: Config): + nil | function(...: any): (any...), + string | nil +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| filename | string | 文件名。 | +| env | table | 环境表。 | +| config | Config | [可选] 编译器选项。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| function \| nil | 加载的函数,如果加载失败则为 nil。 | +| string \| nil | 错误消息,如果加载成功则为 nil。 | + +#### loadfile + +**类型:** 函数。 + +**描述:** + +将 Yuescript 代码文件加载为一个函数。 + +**签名:** +```tl +loadfile: function(filename: string, config?: Config): + nil | function(...: any): (any...), + string | nil +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| filename | string | 文件名。 | +| config | Config | [可选] 编译器选项。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| function \| nil | 加载的函数,如果加载失败则为 nil。 | +| string \| nil | 错误消息,如果加载成功则为 nil。 | + +#### dofile + +**类型:** 函数。 + +**描述:** + +将 Yuescript 代码文件加载为一个函数并执行。 + +**签名:** +```tl +dofile: function(filename: string, env: table, config?: Config): any... +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| filename | string | 文件名。 | +| env | table | 环境表。 | +| config | Config | [可选] 编译器选项。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| any... | 加载的函数执行后的返回值。 | + +#### dofile + +**类型:** 函数。 + +**描述:** + +将 Yuescript 代码文件加载为一个函数并执行。 + +**签名:** +```tl +dofile: function(filename: string, config?: Config): any... +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| filename | string | 文件名。 | +| config | Config | [可选] 编译器选项。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| any... | 加载的函数执行后的返回值。 | + +#### find_modulepath + +**类型:** 函数。 + +**描述:** + +将 Yuescript 模块名解析为文件路径。 + +**签名:** +```tl +find_modulepath: function(name: string): string +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| name | string | 模块名。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| string | 文件路径。 | + +#### pcall + +**类型:** 函数。 + +**描述:** + +在保护模式下调用一个函数。 +会捕获任何错误,执行成功则返回成功状态和结果,否则为失败状态和错误信息。 +当发生错误时,将错误信息中的代码行号重写为 Yuescript 代码中的原始行号。 + +**签名:** +```tl +pcall: function(f: function, ...: any): boolean, any... +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| f | function | 要调用的函数。 | +| ... | any | 要传递给函数的参数。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| boolean, ... | 状态码和函数结果或错误信息。 | + +#### require + +**类型:** 函数。 + +**描述:** + +加载给定的模块。可以是 Lua 模块或 Yuescript 模块。 +如果模块是 Yuescript 模块且加载失败,则将错误信息中的代码行号重写为 Yuescript 代码中的原始行号。 + +**签名:** +```tl +require: function(name: string): any... +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| modname | string | 要加载的模块名。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| any | 如果模块已经加载,则返回 package.loaded[modname] 中存储的值。否则,尝试查找加载器并返回 package.loaded[modname] 的最终值和加载器数据作为第二个结果。 | + +#### p + +**类型:** 函数。 + +**描述:** + +检查传递的值的内部结构,并打印值出它的字符串表示。 + +**签名:** +```tl +p: function(...: any) +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| ... | any | 要检查的值。 | + +#### options + +**类型:** 成员变量。 + +**描述:** + +当前编译器选项。 + +**签名:** +```tl +options: Config.Options +``` + +#### traceback + +**类型:** 函数。 + +**描述:** + +重写堆栈跟踪中的行号为 Yuescript 代码中的原始行号的 traceback 函数。 + +**签名:** +```tl +traceback: function(message: string): string +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| message | string | 堆栈跟踪消息。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| string | 重写后的堆栈跟踪消息。 | + +#### is_ast + +**类型:** 函数。 + +**描述:** + +检查代码是否匹配指定的 AST。 + +**签名:** +```tl +is_ast: function(astName: string, code: string): boolean +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| astName | string | AST 名称。 | +| code | string | 代码。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| boolean | 代码是否匹配 AST。 | + +#### AST + +**类型:** 成员变量。 + +**描述:** + +AST 类型定义,带有名称、行、列和子节点。 + +**签名:** +```tl +type AST = {string, integer, integer, any} +``` + +#### to_ast + +**类型:** 函数。 + +**描述:** + +将代码转换为 AST。 + +**签名:** +```tl +to_ast: function(code: string, flattenLevel?: number, astName?: string): + --[[AST]] AST | nil, + --[[error]] nil | string +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| code | string | 代码。 | +| flattenLevel | integer | [可选] 扁平化级别。级别越高,会消除更多的 AST 结构的嵌套。默认为 0。最大为 2。 | + +#### __call + +**类型:** 元方法。 + +**描述:** + +导入 Yuescript 模块。 +如果发生加载失败,则将错误信息中的代码行号重写为 Yuescript 代码中的原始行号。 + +**签名:** +```tl +metamethod __call: function(self: yue, module: string): any... +``` + +**参数:** + +| 参数名 | 类型 | 描述 | +| --- | --- | --- | +| module | string | 模块名。 | + +**返回值:** + +| 返回类型 | 描述 | +| --- | --- | +| any | 模块值。 | + +### Config + +**描述:** + +编译器编译选项。 + +#### lint_global + +**类型:** 成员变量。 + +**描述:** + +编译器是否应该收集代码中出现的全局变量。 + +**签名:** +```tl +lint_global: boolean +``` + +#### implicit_return_root + +**类型:** 成员变量。 + +**描述:** + +编译器是否应该对根层级的代码块进行隐式的表达式返回。 + +**签名:** +```tl +implicit_return_root: boolean +``` + +#### reserve_line_number + +**类型:** 成员变量。 + +**描述:** + +编译器是否应该在编译后的代码中保留原始行号。 + +**签名:** +```tl +reserve_line_number: boolean +``` + +#### space_over_tab + +**类型:** 成员变量。 + +**描述:** + +编译器是否应该在编译后的代码中使用空格字符而不是制表符字符。 + +**签名:** +```tl +space_over_tab: boolean +``` + +#### same_module + +**类型:** 成员变量。 + +**描述:** + +编译器是否应该将要编译的代码视为当前正在编译的模块。仅供编译器内部使用。 + +**签名:** +```tl +same_module: boolean +``` + +#### line_offset + +**类型:** 成员变量。 + +**描述:** + +编译器错误消息是否应该包含行号偏移量。仅供编译器内部使用。 + +**签名:** +```tl +line_offset: integer +``` + +#### yue.Config.LuaTarget + +**类型:** 枚举。 + +**描述:** + +目标 Lua 版本枚举。 + +**签名:** +```tl +enum LuaTarget + "5.1" + "5.2" + "5.3" + "5.4" + "5.5" +end +``` + +#### options + +**类型:** 成员变量。 + +**描述:** + +要传递给编译函数的额外选项。 + +**签名:** +```tl +options: Options +``` + +### Options + +**描述:** + +额外编译器选项定义。 + +#### target + +**类型:** 成员变量。 + +**描述:** + +编译目标 Lua 版本。 + +**签名:** +```tl +target: LuaTarget +``` + +#### path + +**类型:** 成员变量。 + +**描述:** + +额外模块搜索路径。 + +**签名:** +```tl +path: string +``` + +#### dump_locals + +**类型:** 成员变量。 + +**描述:** + +是否在回溯错误消息中输出代码块的局部变量。默认为 false。 + +**签名:** +```tl +dump_locals: boolean +``` + +#### simplified + +**类型:** 成员变量。 + +**描述:** + +是否简化输出的错误消息。默认为 true。 + +**签名:** +```tl +simplified: boolean +``` + ## MIT 许可证 版权 (c) 2024 李瑾 -- cgit v1.2.3-55-g6feb