aboutsummaryrefslogtreecommitdiff
path: root/doc/docs/doc/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/docs/doc/README.md')
-rwxr-xr-xdoc/docs/doc/README.md781
1 files changed, 781 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