aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2024-08-10 22:04:38 +0800
committerLi Jin <dragon-fly@qq.com>2024-08-10 22:04:38 +0800
commita3bde93c37e59d8d0e47d61bfde9b28a95eded89 (patch)
treed849a74407b6dc082b644f58d4d5de164309b30f
parent0731d4fce42ba2f13c4d8f8ecba1680f79d48065 (diff)
downloadyuescript-a3bde93c37e59d8d0e47d61bfde9b28a95eded89.tar.gz
yuescript-a3bde93c37e59d8d0e47d61bfde9b28a95eded89.tar.bz2
yuescript-a3bde93c37e59d8d0e47d61bfde9b28a95eded89.zip
update docs.
-rwxr-xr-xdoc/docs/doc/README.md781
-rwxr-xr-xdoc/docs/zh/doc/README.md773
2 files changed, 1554 insertions, 0 deletions
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
3575</pre> 3575</pre>
3576</YueDisplay> 3576</YueDisplay>
3577 3577
3578## The Yuescript Library
3579
3580Access it by `require("yue")`.
3581
3582### yue
3583
3584**Description:**
3585
3586The Yuescript language library.
3587
3588#### version
3589
3590**Type:** Field.
3591
3592**Description:**
3593
3594The Yuescript version.
3595
3596**Signature:**
3597```lua
3598version: string
3599```
3600
3601#### dirsep
3602
3603**Type:** Field.
3604
3605**Description:**
3606
3607The file separator for the current platform.
3608
3609**Signature:**
3610```lua
3611dirsep: string
3612```
3613
3614#### yue_compiled
3615
3616**Type:** Field.
3617
3618**Description:**
3619
3620The compiled module code cache.
3621
3622**Signature:**
3623```lua
3624yue_compiled: {string: string}
3625```
3626
3627#### to_lua
3628
3629**Type:** Function.
3630
3631**Description:**
3632
3633The Yuescript compiling function. It compiles the Yuescript code to Lua code.
3634
3635**Signature:**
3636```lua
3637to_lua: function(code: string, config?: Config):
3638 --[[codes]] string | nil,
3639 --[[error]] string | nil,
3640 --[[globals]] {{string, integer, integer}} | nil
3641```
3642
3643**Parameters:**
3644
3645| Parameter | Type | Description |
3646| --- | --- | --- |
3647| code | string | The Yuescript code. |
3648| config | Config | [Optional] The compiler options. |
3649
3650**Returns:**
3651
3652| Return Type | Description |
3653| --- | --- |
3654| string \| nil | The compiled Lua code, or nil if the compilation failed. |
3655| string \| nil | The error message, or nil if the compilation succeeded. |
3656| \{\{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. |
3657
3658#### file_exist
3659
3660**Type:** Function.
3661
3662**Description:**
3663
3664The source file existence checking function. Can be overridden to customize the behavior.
3665
3666**Signature:**
3667```lua
3668file_exist: function(filename: string): boolean
3669```
3670
3671**Parameters:**
3672
3673| Parameter | Type | Description |
3674| --- | --- | --- |
3675| filename | string | The file name. |
3676
3677**Returns:**
3678
3679| Return Type | Description |
3680| --- | --- |
3681| boolean | Whether the file exists. |
3682
3683#### read_file
3684
3685**Type:** Function.
3686
3687**Description:**
3688
3689The source file reading function. Can be overridden to customize the behavior.
3690
3691**Signature:**
3692```lua
3693read_file: function(filename: string): string
3694```
3695
3696**Parameters:**
3697
3698| Parameter | Type | Description |
3699| --- | --- | --- |
3700| filename | string | The file name. |
3701
3702**Returns:**
3703
3704| Return Type | Description |
3705| --- | --- |
3706| string | The file content. |
3707
3708#### insert_loader
3709
3710**Type:** Function.
3711
3712**Description:**
3713
3714Insert the Yuescript loader to the package loaders (searchers).
3715
3716**Signature:**
3717```lua
3718insert_loader: function(pos?: integer): boolean
3719```
3720
3721**Parameters:**
3722
3723| Parameter | Type | Description |
3724| --- | --- | --- |
3725| pos | integer | [Optional] The position to insert the loader. Default is 3. |
3726
3727**Returns:**
3728
3729| Return Type | Description |
3730| --- | --- |
3731| boolean | Whether the loader is inserted successfully. It will fail if the loader is already inserted. |
3732
3733#### remove_loader
3734
3735**Type:** Function.
3736
3737**Description:**
3738
3739Remove the Yuescript loader from the package loaders (searchers).
3740
3741**Signature:**
3742```lua
3743remove_loader: function(): boolean
3744```
3745
3746**Returns:**
3747
3748| Return Type | Description |
3749| --- | --- |
3750| boolean | Whether the loader is removed successfully. It will fail if the loader is not inserted. |
3751
3752#### loadstring
3753
3754**Type:** Function.
3755
3756**Description:**
3757
3758Loads Yuescript code from a string into a function.
3759
3760**Signature:**
3761```lua
3762loadstring: function(input: string, chunkname: string, env: table, config?: Config):
3763 --[[loaded function]] nil | function(...: any): (any...),
3764 --[[error]] string | nil
3765```
3766
3767**Parameters:**
3768
3769| Parameter | Type | Description |
3770| --- | --- | --- |
3771| input | string | The Yuescript code. |
3772| chunkname | string | The name of the code chunk. |
3773| env | table | The environment table. |
3774| config | Config | [Optional] The compiler options. |
3775
3776**Returns:**
3777
3778| Return Type | Description |
3779| --- | --- |
3780| function \| nil | The loaded function, or nil if the loading failed. |
3781| string \| nil | The error message, or nil if the loading succeeded. |
3782
3783#### loadstring
3784
3785**Type:** Function.
3786
3787**Description:**
3788
3789Loads Yuescript code from a string into a function.
3790
3791**Signature:**
3792```lua
3793loadstring: function(input: string, chunkname: string, config?: Config):
3794 --[[loaded function]] nil | function(...: any): (any...),
3795 --[[error]] string | nil
3796```
3797
3798**Parameters:**
3799
3800| Parameter | Type | Description |
3801| --- | --- | --- |
3802| input | string | The Yuescript code. |
3803| chunkname | string | The name of the code chunk. |
3804| config | Config | [Optional] The compiler options. |
3805
3806**Returns:**
3807
3808| Return Type | Description |
3809| --- | --- |
3810| function \| nil | The loaded function, or nil if the loading failed. |
3811| string \| nil | The error message, or nil if the loading succeeded. |
3812
3813#### loadstring
3814
3815**Type:** Function.
3816
3817**Description:**
3818
3819Loads Yuescript code from a string into a function.
3820
3821**Signature:**
3822```lua
3823loadstring: function(input: string, config?: Config):
3824 --[[loaded function]] nil | function(...: any): (any...),
3825 --[[error]] string | nil
3826```
3827
3828**Parameters:**
3829
3830| Parameter | Type | Description |
3831| --- | --- | --- |
3832| input | string | The Yuescript code. |
3833| config | Config | [Optional] The compiler options. |
3834
3835**Returns:**
3836
3837| Return Type | Description |
3838| --- | --- |
3839| function \| nil | The loaded function, or nil if the loading failed. |
3840| string \| nil | The error message, or nil if the loading succeeded. |
3841
3842#### loadfile
3843
3844**Type:** Function.
3845
3846**Description:**
3847
3848Loads Yuescript code from a file into a function.
3849
3850**Signature:**
3851```lua
3852loadfile: function(filename: string, env: table, config?: Config):
3853 nil | function(...: any): (any...),
3854 string | nil
3855```
3856
3857**Parameters:**
3858
3859| Parameter | Type | Description |
3860| --- | --- | --- |
3861| filename | string | The file name. |
3862| env | table | The environment table. |
3863| config | Config | [Optional] The compiler options. |
3864
3865**Returns:**
3866
3867| Return Type | Description |
3868| --- | --- |
3869| function \| nil | The loaded function, or nil if the loading failed. |
3870| string \| nil | The error message, or nil if the loading succeeded. |
3871
3872#### loadfile
3873
3874**Type:** Function.
3875
3876**Description:**
3877
3878Loads Yuescript code from a file into a function.
3879
3880**Signature:**
3881```lua
3882loadfile: function(filename: string, config?: Config):
3883 nil | function(...: any): (any...),
3884 string | nil
3885```
3886
3887**Parameters:**
3888
3889| Parameter | Type | Description |
3890| --- | --- | --- |
3891| filename | string | The file name. |
3892| config | Config | [Optional] The compiler options. |
3893
3894**Returns:**
3895
3896| Return Type | Description |
3897| --- | --- |
3898| function \| nil | The loaded function, or nil if the loading failed. |
3899| string \| nil | The error message, or nil if the loading succeeded. |
3900
3901#### dofile
3902
3903**Type:** Function.
3904
3905**Description:**
3906
3907Loads Yuescript code from a file into a function and executes it.
3908
3909**Signature:**
3910```lua
3911dofile: function(filename: string, env: table, config?: Config): any...
3912```
3913
3914**Parameters:**
3915
3916| Parameter | Type | Description |
3917| --- | --- | --- |
3918| filename | string | The file name. |
3919| env | table | The environment table. |
3920| config | Config | [Optional] The compiler options. |
3921
3922**Returns:**
3923
3924| Return Type | Description |
3925| --- | --- |
3926| any... | The return values of the loaded function. |
3927
3928#### dofile
3929
3930**Type:** Function.
3931
3932**Description:**
3933
3934Loads Yuescript code from a file into a function and executes it.
3935
3936**Signature:**
3937```lua
3938dofile: function(filename: string, config?: Config): any...
3939```
3940
3941**Parameters:**
3942
3943| Parameter | Type | Description |
3944| --- | --- | --- |
3945| filename | string | The file name. |
3946| config | Config | [Optional] The compiler options. |
3947
3948**Returns:**
3949
3950| Return Type | Description |
3951| --- | --- |
3952| any... | The return values of the loaded function. |
3953
3954#### find_modulepath
3955
3956**Type:** Function.
3957
3958**Description:**
3959
3960Resolves the Yuescript module name to the file path.
3961
3962**Signature:**
3963```lua
3964find_modulepath: function(name: string): string
3965```
3966
3967**Parameters:**
3968
3969| Parameter | Type | Description |
3970| --- | --- | --- |
3971| name | string | The module name. |
3972
3973**Returns:**
3974
3975| Return Type | Description |
3976| --- | --- |
3977| string | The file path. |
3978
3979#### pcall
3980
3981**Type:** Function.
3982
3983**Description:**
3984
3985Calls a function in protected mode.
3986Catches any errors and returns a status code and results or error object.
3987Rewrites the error line number to the original line number in the Yuescript code when errors occur.
3988
3989**Signature:**
3990```lua
3991pcall: function(f: function, ...: any): boolean, any...
3992```
3993
3994**Parameters:**
3995
3996| Parameter | Type | Description |
3997| --- | --- | --- |
3998| f | function | The function to call. |
3999| ... | any | Arguments to pass to the function. |
4000
4001**Returns:**
4002
4003| Return Type | Description |
4004| --- | --- |
4005| boolean, ... | Status code and function results or error object. |
4006
4007#### require
4008
4009**Type:** Function.
4010
4011**Description:**
4012
4013Loads a given module. Can be either a Lua module or a Yuescript module.
4014Rewrites the error line number to the original line number in the Yuescript code if the module is a Yuescript module and loading fails.
4015
4016**Signature:**
4017```lua
4018require: function(name: string): any...
4019```
4020
4021**Parameters:**
4022
4023| Parameter | Type | Description |
4024| --- | --- | --- |
4025| modname | string | The name of the module to load. |
4026
4027**Returns:**
4028
4029| Return Type | Description |
4030| --- | --- |
4031| 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. |
4032
4033#### p
4034
4035**Type:** Function.
4036
4037**Description:**
4038
4039Inspects the structures of the passed values and prints string representations.
4040
4041**Signature:**
4042```lua
4043p: function(...: any)
4044```
4045
4046**Parameters:**
4047
4048| Parameter | Type | Description |
4049| --- | --- | --- |
4050| ... | any | The values to inspect. |
4051
4052#### options
4053
4054**Type:** Field.
4055
4056**Description:**
4057
4058The current compiler options.
4059
4060**Signature:**
4061```lua
4062options: Config.Options
4063```
4064
4065#### traceback
4066
4067**Type:** Function.
4068
4069**Description:**
4070
4071The traceback function that rewrites the stack trace line numbers to the original line numbers in the Yuescript code.
4072
4073**Signature:**
4074```lua
4075traceback: function(message: string): string
4076```
4077
4078**Parameters:**
4079
4080| Parameter | Type | Description |
4081| --- | --- | --- |
4082| message | string | The traceback message. |
4083
4084**Returns:**
4085
4086| Return Type | Description |
4087| --- | --- |
4088| string | The rewritten traceback message. |
4089
4090#### is_ast
4091
4092**Type:** Function.
4093
4094**Description:**
4095
4096Checks whether the code matches the specified AST.
4097
4098**Signature:**
4099```lua
4100is_ast: function(astName: string, code: string): boolean
4101```
4102
4103**Parameters:**
4104
4105| Parameter | Type | Description |
4106| --- | --- | --- |
4107| astName | string | The AST name. |
4108| code | string | The code. |
4109
4110**Returns:**
4111
4112| Return Type | Description |
4113| --- | --- |
4114| boolean | Whether the code matches the AST. |
4115
4116#### AST
4117
4118**Type:** Field.
4119
4120**Description:**
4121
4122The AST type definition with name, row, column and sub nodes.
4123
4124**Signature:**
4125```lua
4126type AST = {string, integer, integer, any}
4127```
4128
4129#### to_ast
4130
4131**Type:** Function.
4132
4133**Description:**
4134
4135Converts the code to the AST.
4136
4137**Signature:**
4138```lua
4139to_ast: function(code: string, flattenLevel?: number, astName?: string):
4140 --[[AST]] AST | nil,
4141 --[[error]] nil | string
4142```
4143
4144**Parameters:**
4145
4146| Parameter | Type | Description |
4147| --- | --- | --- |
4148| code | string | The code. |
4149| flattenLevel | integer | [Optional] The flatten level. Higher level means more flattening. Default is 0. Maximum is 2. |
4150| astName | string | [Optional] The AST name. Default is "File". |
4151
4152**Returns:**
4153
4154| Return Type | Description |
4155| --- | --- |
4156| AST \| nil | The AST, or nil if the conversion failed. |
4157| string \| nil | The error message, or nil if the conversion succeeded. |
4158
4159#### __call
4160
4161**Type:** Metamethod.
4162
4163**Description:**
4164
4165Requires the Yuescript module.
4166Rewrites the error line number to the original line number in the Yuescript code when loading fails.
4167
4168**Signature:**
4169```lua
4170metamethod __call: function(self: yue, module: string): any...
4171```
4172
4173**Parameters:**
4174
4175| Parameter | Type | Description |
4176| --- | --- | --- |
4177| module | string | The module name. |
4178
4179**Returns:**
4180
4181| Return Type | Description |
4182| --- | --- |
4183| any | The module value. |
4184
4185### Config
4186
4187**Description:**
4188
4189The compiler compile options.
4190
4191#### lint_global
4192
4193**Type:** Field.
4194
4195**Description:**
4196
4197Whether the compiler should collect the global variables appearing in the code.
4198
4199**Signature:**
4200```lua
4201lint_global: boolean
4202```
4203
4204#### implicit_return_root
4205
4206**Type:** Field.
4207
4208**Description:**
4209
4210Whether the compiler should do an implicit return for the root code block.
4211
4212**Signature:**
4213```lua
4214implicit_return_root: boolean
4215```
4216
4217#### reserve_line_number
4218
4219**Type:** Field.
4220
4221**Description:**
4222
4223Whether the compiler should reserve the original line number in the compiled code.
4224
4225**Signature:**
4226```lua
4227reserve_line_number: boolean
4228```
4229
4230#### space_over_tab
4231
4232**Type:** Field.
4233
4234**Description:**
4235
4236Whether the compiler should use the space character instead of the tab character in the compiled code.
4237
4238**Signature:**
4239```lua
4240space_over_tab: boolean
4241```
4242
4243#### same_module
4244
4245**Type:** Field.
4246
4247**Description:**
4248
4249Whether the compiler should treat the code to be compiled as the same currently being compiled module. For internal use only.
4250
4251**Signature:**
4252```lua
4253same_module: boolean
4254```
4255
4256#### line_offset
4257
4258**Type:** Field.
4259
4260**Description:**
4261
4262Whether the compiler error message should include the line number offset. For internal use only.
4263
4264**Signature:**
4265```lua
4266line_offset: integer
4267```
4268
4269#### yue.Config.LuaTarget
4270
4271**Type:** Enumeration.
4272
4273**Description:**
4274
4275The target Lua version enumeration.
4276
4277**Signature:**
4278```lua
4279enum LuaTarget
4280 "5.1"
4281 "5.2"
4282 "5.3"
4283 "5.4"
4284 "5.5"
4285end
4286```
4287
4288#### options
4289
4290**Type:** Field.
4291
4292**Description:**
4293
4294The extra options to be passed to the compilation function.
4295
4296**Signature:**
4297```lua
4298options: Options
4299```
4300
4301### Options
4302
4303**Description:**
4304
4305The extra compiler options definition.
4306
4307#### target
4308
4309**Type:** Field.
4310
4311**Description:**
4312
4313The target Lua version for the compilation.
4314
4315**Signature:**
4316```lua
4317target: LuaTarget
4318```
4319
4320#### path
4321
4322**Type:** Field.
4323
4324**Description:**
4325
4326The extra module search path.
4327
4328**Signature:**
4329```lua
4330path: string
4331```
4332
4333#### dump_locals
4334
4335**Type:** Field.
4336
4337**Description:**
4338
4339Whether to dump the local variables in the traceback error message. Default is false.
4340
4341**Signature:**
4342```lua
4343dump_locals: boolean
4344```
4345
4346#### simplified
4347
4348**Type:** Field.
4349
4350**Description:**
4351
4352Whether to simplify the error message. Default is true.
4353
4354**Signature:**
4355```lua
4356simplified: boolean
4357```
4358
3578## Licence: MIT 4359## Licence: MIT
3579 4360
3580Copyright (c) 2024 Li Jin 4361Copyright (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 -- 这些已经被更新
3531</pre> 3531</pre>
3532</YueDisplay> 3532</YueDisplay>
3533 3533
3534## 月之脚本语言库
3535
3536使用`require("yue")`来访问。
3537
3538### yue
3539
3540**描述:**
3541
3542月之脚本语言库。
3543
3544#### version
3545
3546**类型:** 成员变量。
3547
3548**描述:**
3549
3550月之脚本版本。
3551
3552**签名:**
3553```tl
3554version: string
3555```
3556
3557#### dirsep
3558
3559**类型:** 成员变量。
3560
3561**描述:**
3562
3563当前平台的文件分隔符。
3564
3565**签名:**
3566```tl
3567dirsep: string
3568```
3569
3570#### yue_compiled
3571
3572**类型:** 成员变量。
3573
3574**描述:**
3575
3576编译模块代码缓存。
3577
3578**签名:**
3579```tl
3580yue_compiled: {string: string}
3581```
3582
3583#### to_lua
3584
3585**类型:** 函数。
3586
3587**描述:**
3588
3589月之脚本的编译函数。它将 Yuescript 代码编译为 Lua 代码。
3590
3591**签名:**
3592```tl
3593to_lua: function(code: string, config?: Config):
3594 --[[codes]] string | nil,
3595 --[[error]] string | nil,
3596 --[[globals]] {{string, integer, integer}} | nil
3597```
3598
3599**参数:**
3600
3601| 参数名 | 类型 | 描述 |
3602| --- | --- | --- |
3603| code | string | Yuescript 代码。 |
3604| config | Config | [可选] 编译器选项。 |
3605
3606**返回值:**
3607
3608| 返回类型 | 描述 |
3609| --- | --- |
3610| string \| nil | 编译后的 Lua 代码,如果编译失败则为 nil。 |
3611| string \| nil | 错误消息,如果编译成功则为 nil。 |
3612| \{\{string, integer, integer}} \| nil | 代码中出现的全局变量(带有名称、行和列),如果编译器选项 `lint_global` 为 false 则为 nil。 |
3613
3614#### file_exist
3615
3616**类型:** 函数。
3617
3618**描述:**
3619
3620检查源文件是否存在的函数。可以覆盖该函数以自定义行为。
3621
3622**签名:**
3623```tl
3624file_exist: function(filename: string): boolean
3625```
3626
3627**参数:**
3628
3629| 参数名 | 类型 | 描述 |
3630| --- | --- | --- |
3631| filename | string | 文件名。 |
3632
3633**返回值:**
3634
3635| 返回类型 | 描述 |
3636| --- | --- |
3637| boolean | 文件是否存在。 |
3638
3639#### read_file
3640
3641**类型:** 函数。
3642
3643**描述:**
3644
3645读取源文件的函数。可以覆盖该函数以自定义行为。
3646
3647**签名:**
3648```tl
3649read_file: function(filename: string): string
3650```
3651
3652**参数:**
3653
3654| 参数名 | 类型 | 描述 |
3655| --- | --- | --- |
3656| filename | string | 文件名。 |
3657
3658**返回值:**
3659
3660| 返回类型 | 描述 |
3661| --- | --- |
3662| string | 文件内容。 |
3663
3664#### insert_loader
3665
3666**类型:** 函数。
3667
3668**描述:**
3669
3670将 Yuescript 加载器插入到 Lua 包加载器(搜索器)中。
3671
3672**签名:**
3673```tl
3674insert_loader: function(pos?: integer): boolean
3675```
3676
3677**参数:**
3678
3679| 参数名 | 类型 | 描述 |
3680| --- | --- | --- |
3681| pos | integer | [可选] 要插入加载器的位置。默认为 3。 |
3682
3683**返回值:**
3684
3685| 返回类型 | 描述 |
3686| --- | --- |
3687| boolean | 是否成功插入加载器。如果加载器已经插入,则返回失败。 |
3688
3689#### remove_loader
3690
3691**类型:** 函数。
3692
3693**描述:**
3694
3695从 Lua 包加载器(搜索器)中移除 Yuescript 加载器。
3696
3697**签名:**
3698```tl
3699remove_loader: function(): boolean
3700```
3701
3702**返回值:**
3703
3704| 返回类型 | 描述 |
3705| --- | --- |
3706| boolean | 是否成功移除加载器。如果加载器未插入,则返回失败。 |
3707
3708#### loadstring
3709
3710**类型:** 函数。
3711
3712**描述:**
3713
3714将 Yuescript 代码字符串加载为一个函数。
3715
3716**签名:**
3717```tl
3718loadstring: function(input: string, chunkname: string, env: table, config?: Config):
3719 --[[loaded function]] nil | function(...: any): (any...),
3720 --[[error]] string | nil
3721```
3722
3723**参数:**
3724
3725| 参数名 | 类型 | 描述 |
3726| --- | --- | --- |
3727| input | string | Yuescript 代码。 |
3728| chunkname | string | 代码块的名称。 |
3729| env | table | 环境表。 |
3730| config | Config | [可选] 编译器选项。 |
3731
3732**返回值:**
3733
3734| 返回类型 | 描述 |
3735| --- | --- |
3736| function \| nil | 加载的函数,如果加载失败则为 nil。 |
3737| string \| nil | 错误消息,如果加载成功则为 nil。 |
3738
3739#### loadstring
3740
3741**类型:** 函数。
3742
3743**描述:**
3744
3745将 Yuescript 代码字符串加载为一个函数。
3746
3747**签名:**
3748```tl
3749loadstring: function(input: string, chunkname: string, config?: Config):
3750 --[[loaded function]] nil | function(...: any): (any...),
3751 --[[error]] string | nil
3752```
3753
3754**参数:**
3755
3756| 参数名 | 类型 | 描述 |
3757| --- | --- | --- |
3758| input | string | Yuescript 代码。 |
3759| chunkname | string | 代码块的名称。 |
3760| config | Config | [可选] 编译器选项。 |
3761
3762**返回值:**
3763
3764| 返回类型 | 描述 |
3765| --- | --- |
3766| function \| nil | 加载的函数,如果加载失败则为 nil。 |
3767| string \| nil | 错误消息,如果加载成功则为 nil。 |
3768
3769#### loadstring
3770
3771**类型:** 函数。
3772
3773**描述:**
3774
3775将 Yuescript 代码字符串加载为一个函数。
3776
3777**签名:**
3778```tl
3779loadstring: function(input: string, config?: Config):
3780 --[[loaded function]] nil | function(...: any): (any...),
3781 --[[error]] string | nil
3782```
3783
3784**参数:**
3785
3786| 参数名 | 类型 | 描述 |
3787| --- | --- | --- |
3788| input | string | Yuescript 代码。 |
3789| config | Config | [可选] 编译器选项。 |
3790
3791**返回值:**
3792
3793| 返回类型 | 描述 |
3794| --- | --- |
3795| function \| nil | 加载的函数,如果加载失败则为 nil。 |
3796| string \| nil | 错误消息,如果加载成功则为 nil。 |
3797
3798#### loadfile
3799
3800**类型:** 函数。
3801
3802**描述:**
3803
3804将 Yuescript 代码文件加载为一个函数。
3805
3806**签名:**
3807```tl
3808loadfile: function(filename: string, env: table, config?: Config):
3809 nil | function(...: any): (any...),
3810 string | nil
3811```
3812
3813**参数:**
3814
3815| 参数名 | 类型 | 描述 |
3816| --- | --- | --- |
3817| filename | string | 文件名。 |
3818| env | table | 环境表。 |
3819| config | Config | [可选] 编译器选项。 |
3820
3821**返回值:**
3822
3823| 返回类型 | 描述 |
3824| --- | --- |
3825| function \| nil | 加载的函数,如果加载失败则为 nil。 |
3826| string \| nil | 错误消息,如果加载成功则为 nil。 |
3827
3828#### loadfile
3829
3830**类型:** 函数。
3831
3832**描述:**
3833
3834将 Yuescript 代码文件加载为一个函数。
3835
3836**签名:**
3837```tl
3838loadfile: function(filename: string, config?: Config):
3839 nil | function(...: any): (any...),
3840 string | nil
3841```
3842
3843**参数:**
3844
3845| 参数名 | 类型 | 描述 |
3846| --- | --- | --- |
3847| filename | string | 文件名。 |
3848| config | Config | [可选] 编译器选项。 |
3849
3850**返回值:**
3851
3852| 返回类型 | 描述 |
3853| --- | --- |
3854| function \| nil | 加载的函数,如果加载失败则为 nil。 |
3855| string \| nil | 错误消息,如果加载成功则为 nil。 |
3856
3857#### dofile
3858
3859**类型:** 函数。
3860
3861**描述:**
3862
3863将 Yuescript 代码文件加载为一个函数并执行。
3864
3865**签名:**
3866```tl
3867dofile: function(filename: string, env: table, config?: Config): any...
3868```
3869
3870**参数:**
3871
3872| 参数名 | 类型 | 描述 |
3873| --- | --- | --- |
3874| filename | string | 文件名。 |
3875| env | table | 环境表。 |
3876| config | Config | [可选] 编译器选项。 |
3877
3878**返回值:**
3879
3880| 返回类型 | 描述 |
3881| --- | --- |
3882| any... | 加载的函数执行后的返回值。 |
3883
3884#### dofile
3885
3886**类型:** 函数。
3887
3888**描述:**
3889
3890将 Yuescript 代码文件加载为一个函数并执行。
3891
3892**签名:**
3893```tl
3894dofile: function(filename: string, config?: Config): any...
3895```
3896
3897**参数:**
3898
3899| 参数名 | 类型 | 描述 |
3900| --- | --- | --- |
3901| filename | string | 文件名。 |
3902| config | Config | [可选] 编译器选项。 |
3903
3904**返回值:**
3905
3906| 返回类型 | 描述 |
3907| --- | --- |
3908| any... | 加载的函数执行后的返回值。 |
3909
3910#### find_modulepath
3911
3912**类型:** 函数。
3913
3914**描述:**
3915
3916将 Yuescript 模块名解析为文件路径。
3917
3918**签名:**
3919```tl
3920find_modulepath: function(name: string): string
3921```
3922
3923**参数:**
3924
3925| 参数名 | 类型 | 描述 |
3926| --- | --- | --- |
3927| name | string | 模块名。 |
3928
3929**返回值:**
3930
3931| 返回类型 | 描述 |
3932| --- | --- |
3933| string | 文件路径。 |
3934
3935#### pcall
3936
3937**类型:** 函数。
3938
3939**描述:**
3940
3941在保护模式下调用一个函数。
3942会捕获任何错误,执行成功则返回成功状态和结果,否则为失败状态和错误信息。
3943当发生错误时,将错误信息中的代码行号重写为 Yuescript 代码中的原始行号。
3944
3945**签名:**
3946```tl
3947pcall: function(f: function, ...: any): boolean, any...
3948```
3949
3950**参数:**
3951
3952| 参数名 | 类型 | 描述 |
3953| --- | --- | --- |
3954| f | function | 要调用的函数。 |
3955| ... | any | 要传递给函数的参数。 |
3956
3957**返回值:**
3958
3959| 返回类型 | 描述 |
3960| --- | --- |
3961| boolean, ... | 状态码和函数结果或错误信息。 |
3962
3963#### require
3964
3965**类型:** 函数。
3966
3967**描述:**
3968
3969加载给定的模块。可以是 Lua 模块或 Yuescript 模块。
3970如果模块是 Yuescript 模块且加载失败,则将错误信息中的代码行号重写为 Yuescript 代码中的原始行号。
3971
3972**签名:**
3973```tl
3974require: function(name: string): any...
3975```
3976
3977**参数:**
3978
3979| 参数名 | 类型 | 描述 |
3980| --- | --- | --- |
3981| modname | string | 要加载的模块名。 |
3982
3983**返回值:**
3984
3985| 返回类型 | 描述 |
3986| --- | --- |
3987| any | 如果模块已经加载,则返回 package.loaded[modname] 中存储的值。否则,尝试查找加载器并返回 package.loaded[modname] 的最终值和加载器数据作为第二个结果。 |
3988
3989#### p
3990
3991**类型:** 函数。
3992
3993**描述:**
3994
3995检查传递的值的内部结构,并打印值出它的字符串表示。
3996
3997**签名:**
3998```tl
3999p: function(...: any)
4000```
4001
4002**参数:**
4003
4004| 参数名 | 类型 | 描述 |
4005| --- | --- | --- |
4006| ... | any | 要检查的值。 |
4007
4008#### options
4009
4010**类型:** 成员变量。
4011
4012**描述:**
4013
4014当前编译器选项。
4015
4016**签名:**
4017```tl
4018options: Config.Options
4019```
4020
4021#### traceback
4022
4023**类型:** 函数。
4024
4025**描述:**
4026
4027重写堆栈跟踪中的行号为 Yuescript 代码中的原始行号的 traceback 函数。
4028
4029**签名:**
4030```tl
4031traceback: function(message: string): string
4032```
4033
4034**参数:**
4035
4036| 参数名 | 类型 | 描述 |
4037| --- | --- | --- |
4038| message | string | 堆栈跟踪消息。 |
4039
4040**返回值:**
4041
4042| 返回类型 | 描述 |
4043| --- | --- |
4044| string | 重写后的堆栈跟踪消息。 |
4045
4046#### is_ast
4047
4048**类型:** 函数。
4049
4050**描述:**
4051
4052检查代码是否匹配指定的 AST。
4053
4054**签名:**
4055```tl
4056is_ast: function(astName: string, code: string): boolean
4057```
4058
4059**参数:**
4060
4061| 参数名 | 类型 | 描述 |
4062| --- | --- | --- |
4063| astName | string | AST 名称。 |
4064| code | string | 代码。 |
4065
4066**返回值:**
4067
4068| 返回类型 | 描述 |
4069| --- | --- |
4070| boolean | 代码是否匹配 AST。 |
4071
4072#### AST
4073
4074**类型:** 成员变量。
4075
4076**描述:**
4077
4078AST 类型定义,带有名称、行、列和子节点。
4079
4080**签名:**
4081```tl
4082type AST = {string, integer, integer, any}
4083```
4084
4085#### to_ast
4086
4087**类型:** 函数。
4088
4089**描述:**
4090
4091将代码转换为 AST。
4092
4093**签名:**
4094```tl
4095to_ast: function(code: string, flattenLevel?: number, astName?: string):
4096 --[[AST]] AST | nil,
4097 --[[error]] nil | string
4098```
4099
4100**参数:**
4101
4102| 参数名 | 类型 | 描述 |
4103| --- | --- | --- |
4104| code | string | 代码。 |
4105| flattenLevel | integer | [可选] 扁平化级别。级别越高,会消除更多的 AST 结构的嵌套。默认为 0。最大为 2。 |
4106
4107#### __call
4108
4109**类型:** 元方法。
4110
4111**描述:**
4112
4113导入 Yuescript 模块。
4114如果发生加载失败,则将错误信息中的代码行号重写为 Yuescript 代码中的原始行号。
4115
4116**签名:**
4117```tl
4118metamethod __call: function(self: yue, module: string): any...
4119```
4120
4121**参数:**
4122
4123| 参数名 | 类型 | 描述 |
4124| --- | --- | --- |
4125| module | string | 模块名。 |
4126
4127**返回值:**
4128
4129| 返回类型 | 描述 |
4130| --- | --- |
4131| any | 模块值。 |
4132
4133### Config
4134
4135**描述:**
4136
4137编译器编译选项。
4138
4139#### lint_global
4140
4141**类型:** 成员变量。
4142
4143**描述:**
4144
4145编译器是否应该收集代码中出现的全局变量。
4146
4147**签名:**
4148```tl
4149lint_global: boolean
4150```
4151
4152#### implicit_return_root
4153
4154**类型:** 成员变量。
4155
4156**描述:**
4157
4158编译器是否应该对根层级的代码块进行隐式的表达式返回。
4159
4160**签名:**
4161```tl
4162implicit_return_root: boolean
4163```
4164
4165#### reserve_line_number
4166
4167**类型:** 成员变量。
4168
4169**描述:**
4170
4171编译器是否应该在编译后的代码中保留原始行号。
4172
4173**签名:**
4174```tl
4175reserve_line_number: boolean
4176```
4177
4178#### space_over_tab
4179
4180**类型:** 成员变量。
4181
4182**描述:**
4183
4184编译器是否应该在编译后的代码中使用空格字符而不是制表符字符。
4185
4186**签名:**
4187```tl
4188space_over_tab: boolean
4189```
4190
4191#### same_module
4192
4193**类型:** 成员变量。
4194
4195**描述:**
4196
4197编译器是否应该将要编译的代码视为当前正在编译的模块。仅供编译器内部使用。
4198
4199**签名:**
4200```tl
4201same_module: boolean
4202```
4203
4204#### line_offset
4205
4206**类型:** 成员变量。
4207
4208**描述:**
4209
4210编译器错误消息是否应该包含行号偏移量。仅供编译器内部使用。
4211
4212**签名:**
4213```tl
4214line_offset: integer
4215```
4216
4217#### yue.Config.LuaTarget
4218
4219**类型:** 枚举。
4220
4221**描述:**
4222
4223目标 Lua 版本枚举。
4224
4225**签名:**
4226```tl
4227enum LuaTarget
4228 "5.1"
4229 "5.2"
4230 "5.3"
4231 "5.4"
4232 "5.5"
4233end
4234```
4235
4236#### options
4237
4238**类型:** 成员变量。
4239
4240**描述:**
4241
4242要传递给编译函数的额外选项。
4243
4244**签名:**
4245```tl
4246options: Options
4247```
4248
4249### Options
4250
4251**描述:**
4252
4253额外编译器选项定义。
4254
4255#### target
4256
4257**类型:** 成员变量。
4258
4259**描述:**
4260
4261编译目标 Lua 版本。
4262
4263**签名:**
4264```tl
4265target: LuaTarget
4266```
4267
4268#### path
4269
4270**类型:** 成员变量。
4271
4272**描述:**
4273
4274额外模块搜索路径。
4275
4276**签名:**
4277```tl
4278path: string
4279```
4280
4281#### dump_locals
4282
4283**类型:** 成员变量。
4284
4285**描述:**
4286
4287是否在回溯错误消息中输出代码块的局部变量。默认为 false。
4288
4289**签名:**
4290```tl
4291dump_locals: boolean
4292```
4293
4294#### simplified
4295
4296**类型:** 成员变量。
4297
4298**描述:**
4299
4300是否简化输出的错误消息。默认为 true。
4301
4302**签名:**
4303```tl
4304simplified: boolean
4305```
4306
3534## MIT 许可证 4307## MIT 许可证
3535 4308
3536版权 (c) 2024 李瑾 4309版权 (c) 2024 李瑾