aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2024-10-19 00:35:11 +0800
committerLi Jin <dragon-fly@qq.com>2024-10-19 00:35:11 +0800
commit1334c0ae67fdf4cb1377e0e7a3ef291f5cf694c0 (patch)
tree8bd3fbeb396fd2fce6e5b34c3ee10f4923feca72 /doc
parent05da3cbfa3689e6c229c41156d0dd08ab554cd77 (diff)
downloadyuescript-1334c0ae67fdf4cb1377e0e7a3ef291f5cf694c0.tar.gz
yuescript-1334c0ae67fdf4cb1377e0e7a3ef291f5cf694c0.tar.bz2
yuescript-1334c0ae67fdf4cb1377e0e7a3ef291f5cf694c0.zip
Fixed issue #174.
Diffstat (limited to 'doc')
-rwxr-xr-xdoc/docs/doc/README.md16
-rwxr-xr-xdoc/docs/zh/doc/README.md90
2 files changed, 69 insertions, 37 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md
index f6aebfc..83d351f 100755
--- a/doc/docs/doc/README.md
+++ b/doc/docs/doc/README.md
@@ -1313,6 +1313,22 @@ print "OK"
1313</pre> 1313</pre>
1314</YueDisplay> 1314</YueDisplay>
1315 1315
1316### While Assignment
1317
1318You can also use if assignment in a while loop to get the value as the loop condition.
1319```moonscript
1320while byte := stream\read_one!
1321 -- do something with the byte
1322 print byte
1323```
1324<YueDisplay>
1325<pre>
1326while byte := stream\read_one!
1327 -- do something with the byte
1328 print byte
1329</pre>
1330</YueDisplay>
1331
1316## Varargs Assignment 1332## Varargs Assignment
1317 1333
1318You can assign the results returned from a function to a varargs symbol `...`. And then access its content using the Lua way. 1334You can assign the results returned from a function to a varargs symbol `...`. And then access its content using the Lua way.
diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md
index 871edd2..bc53075 100755
--- a/doc/docs/zh/doc/README.md
+++ b/doc/docs/zh/doc/README.md
@@ -1310,6 +1310,22 @@ print "好的"
1310</pre> 1310</pre>
1311</YueDisplay> 1311</YueDisplay>
1312 1312
1313### While 赋值
1314
1315您可以在 while 循环中同样使用赋值来获取循环条件的值。
1316```moonscript
1317while byte := stream\read_one!
1318 -- 对 byte 做一些操作
1319 print byte
1320```
1321<YueDisplay>
1322<pre>
1323while byte := stream\read_one!
1324 -- 对 byte 做一些操作
1325 print byte
1326</pre>
1327</YueDisplay>
1328
1313## 可变参数赋值 1329## 可变参数赋值
1314 1330
1315您可以将函数返回的结果赋值给一个可变参数符号 `...`。然后使用Lua的方式访问其内容。 1331您可以将函数返回的结果赋值给一个可变参数符号 `...`。然后使用Lua的方式访问其内容。
@@ -3550,7 +3566,7 @@ print i, k -- 这些已经被更新
3550月之脚本版本。 3566月之脚本版本。
3551 3567
3552**签名:** 3568**签名:**
3553```tl 3569```lua
3554version: string 3570version: string
3555``` 3571```
3556 3572
@@ -3563,7 +3579,7 @@ version: string
3563当前平台的文件分隔符。 3579当前平台的文件分隔符。
3564 3580
3565**签名:** 3581**签名:**
3566```tl 3582```lua
3567dirsep: string 3583dirsep: string
3568``` 3584```
3569 3585
@@ -3576,7 +3592,7 @@ dirsep: string
3576编译模块代码缓存。 3592编译模块代码缓存。
3577 3593
3578**签名:** 3594**签名:**
3579```tl 3595```lua
3580yue_compiled: {string: string} 3596yue_compiled: {string: string}
3581``` 3597```
3582 3598
@@ -3589,7 +3605,7 @@ yue_compiled: {string: string}
3589月之脚本的编译函数。它将 Yuescript 代码编译为 Lua 代码。 3605月之脚本的编译函数。它将 Yuescript 代码编译为 Lua 代码。
3590 3606
3591**签名:** 3607**签名:**
3592```tl 3608```lua
3593to_lua: function(code: string, config?: Config): 3609to_lua: function(code: string, config?: Config):
3594 --[[codes]] string | nil, 3610 --[[codes]] string | nil,
3595 --[[error]] string | nil, 3611 --[[error]] string | nil,
@@ -3620,7 +3636,7 @@ to_lua: function(code: string, config?: Config):
3620检查源文件是否存在的函数。可以覆盖该函数以自定义行为。 3636检查源文件是否存在的函数。可以覆盖该函数以自定义行为。
3621 3637
3622**签名:** 3638**签名:**
3623```tl 3639```lua
3624file_exist: function(filename: string): boolean 3640file_exist: function(filename: string): boolean
3625``` 3641```
3626 3642
@@ -3645,7 +3661,7 @@ file_exist: function(filename: string): boolean
3645读取源文件的函数。可以覆盖该函数以自定义行为。 3661读取源文件的函数。可以覆盖该函数以自定义行为。
3646 3662
3647**签名:** 3663**签名:**
3648```tl 3664```lua
3649read_file: function(filename: string): string 3665read_file: function(filename: string): string
3650``` 3666```
3651 3667
@@ -3670,7 +3686,7 @@ read_file: function(filename: string): string
3670将 Yuescript 加载器插入到 Lua 包加载器(搜索器)中。 3686将 Yuescript 加载器插入到 Lua 包加载器(搜索器)中。
3671 3687
3672**签名:** 3688**签名:**
3673```tl 3689```lua
3674insert_loader: function(pos?: integer): boolean 3690insert_loader: function(pos?: integer): boolean
3675``` 3691```
3676 3692
@@ -3695,7 +3711,7 @@ insert_loader: function(pos?: integer): boolean
3695从 Lua 包加载器(搜索器)中移除 Yuescript 加载器。 3711从 Lua 包加载器(搜索器)中移除 Yuescript 加载器。
3696 3712
3697**签名:** 3713**签名:**
3698```tl 3714```lua
3699remove_loader: function(): boolean 3715remove_loader: function(): boolean
3700``` 3716```
3701 3717
@@ -3714,7 +3730,7 @@ remove_loader: function(): boolean
3714将 Yuescript 代码字符串加载为一个函数。 3730将 Yuescript 代码字符串加载为一个函数。
3715 3731
3716**签名:** 3732**签名:**
3717```tl 3733```lua
3718loadstring: function(input: string, chunkname: string, env: table, config?: Config): 3734loadstring: function(input: string, chunkname: string, env: table, config?: Config):
3719 --[[loaded function]] nil | function(...: any): (any...), 3735 --[[loaded function]] nil | function(...: any): (any...),
3720 --[[error]] string | nil 3736 --[[error]] string | nil
@@ -3745,7 +3761,7 @@ loadstring: function(input: string, chunkname: string, env: table, config?: Conf
3745将 Yuescript 代码字符串加载为一个函数。 3761将 Yuescript 代码字符串加载为一个函数。
3746 3762
3747**签名:** 3763**签名:**
3748```tl 3764```lua
3749loadstring: function(input: string, chunkname: string, config?: Config): 3765loadstring: function(input: string, chunkname: string, config?: Config):
3750 --[[loaded function]] nil | function(...: any): (any...), 3766 --[[loaded function]] nil | function(...: any): (any...),
3751 --[[error]] string | nil 3767 --[[error]] string | nil
@@ -3775,7 +3791,7 @@ loadstring: function(input: string, chunkname: string, config?: Config):
3775将 Yuescript 代码字符串加载为一个函数。 3791将 Yuescript 代码字符串加载为一个函数。
3776 3792
3777**签名:** 3793**签名:**
3778```tl 3794```lua
3779loadstring: function(input: string, config?: Config): 3795loadstring: function(input: string, config?: Config):
3780 --[[loaded function]] nil | function(...: any): (any...), 3796 --[[loaded function]] nil | function(...: any): (any...),
3781 --[[error]] string | nil 3797 --[[error]] string | nil
@@ -3804,7 +3820,7 @@ loadstring: function(input: string, config?: Config):
3804将 Yuescript 代码文件加载为一个函数。 3820将 Yuescript 代码文件加载为一个函数。
3805 3821
3806**签名:** 3822**签名:**
3807```tl 3823```lua
3808loadfile: function(filename: string, env: table, config?: Config): 3824loadfile: function(filename: string, env: table, config?: Config):
3809 nil | function(...: any): (any...), 3825 nil | function(...: any): (any...),
3810 string | nil 3826 string | nil
@@ -3834,7 +3850,7 @@ loadfile: function(filename: string, env: table, config?: Config):
3834将 Yuescript 代码文件加载为一个函数。 3850将 Yuescript 代码文件加载为一个函数。
3835 3851
3836**签名:** 3852**签名:**
3837```tl 3853```lua
3838loadfile: function(filename: string, config?: Config): 3854loadfile: function(filename: string, config?: Config):
3839 nil | function(...: any): (any...), 3855 nil | function(...: any): (any...),
3840 string | nil 3856 string | nil
@@ -3863,7 +3879,7 @@ loadfile: function(filename: string, config?: Config):
3863将 Yuescript 代码文件加载为一个函数并执行。 3879将 Yuescript 代码文件加载为一个函数并执行。
3864 3880
3865**签名:** 3881**签名:**
3866```tl 3882```lua
3867dofile: function(filename: string, env: table, config?: Config): any... 3883dofile: function(filename: string, env: table, config?: Config): any...
3868``` 3884```
3869 3885
@@ -3890,7 +3906,7 @@ dofile: function(filename: string, env: table, config?: Config): any...
3890将 Yuescript 代码文件加载为一个函数并执行。 3906将 Yuescript 代码文件加载为一个函数并执行。
3891 3907
3892**签名:** 3908**签名:**
3893```tl 3909```lua
3894dofile: function(filename: string, config?: Config): any... 3910dofile: function(filename: string, config?: Config): any...
3895``` 3911```
3896 3912
@@ -3916,7 +3932,7 @@ dofile: function(filename: string, config?: Config): any...
3916将 Yuescript 模块名解析为文件路径。 3932将 Yuescript 模块名解析为文件路径。
3917 3933
3918**签名:** 3934**签名:**
3919```tl 3935```lua
3920find_modulepath: function(name: string): string 3936find_modulepath: function(name: string): string
3921``` 3937```
3922 3938
@@ -3943,7 +3959,7 @@ find_modulepath: function(name: string): string
3943当发生错误时,将错误信息中的代码行号重写为 Yuescript 代码中的原始行号。 3959当发生错误时,将错误信息中的代码行号重写为 Yuescript 代码中的原始行号。
3944 3960
3945**签名:** 3961**签名:**
3946```tl 3962```lua
3947pcall: function(f: function, ...: any): boolean, any... 3963pcall: function(f: function, ...: any): boolean, any...
3948``` 3964```
3949 3965
@@ -3970,7 +3986,7 @@ pcall: function(f: function, ...: any): boolean, any...
3970如果模块是 Yuescript 模块且加载失败,则将错误信息中的代码行号重写为 Yuescript 代码中的原始行号。 3986如果模块是 Yuescript 模块且加载失败,则将错误信息中的代码行号重写为 Yuescript 代码中的原始行号。
3971 3987
3972**签名:** 3988**签名:**
3973```tl 3989```lua
3974require: function(name: string): any... 3990require: function(name: string): any...
3975``` 3991```
3976 3992
@@ -3995,7 +4011,7 @@ require: function(name: string): any...
3995检查传递的值的内部结构,并打印值出它的字符串表示。 4011检查传递的值的内部结构,并打印值出它的字符串表示。
3996 4012
3997**签名:** 4013**签名:**
3998```tl 4014```lua
3999p: function(...: any) 4015p: function(...: any)
4000``` 4016```
4001 4017
@@ -4014,7 +4030,7 @@ p: function(...: any)
4014当前编译器选项。 4030当前编译器选项。
4015 4031
4016**签名:** 4032**签名:**
4017```tl 4033```lua
4018options: Config.Options 4034options: Config.Options
4019``` 4035```
4020 4036
@@ -4027,7 +4043,7 @@ options: Config.Options
4027重写堆栈跟踪中的行号为 Yuescript 代码中的原始行号的 traceback 函数。 4043重写堆栈跟踪中的行号为 Yuescript 代码中的原始行号的 traceback 函数。
4028 4044
4029**签名:** 4045**签名:**
4030```tl 4046```lua
4031traceback: function(message: string): string 4047traceback: function(message: string): string
4032``` 4048```
4033 4049
@@ -4052,7 +4068,7 @@ traceback: function(message: string): string
4052检查代码是否匹配指定的 AST。 4068检查代码是否匹配指定的 AST。
4053 4069
4054**签名:** 4070**签名:**
4055```tl 4071```lua
4056is_ast: function(astName: string, code: string): boolean 4072is_ast: function(astName: string, code: string): boolean
4057``` 4073```
4058 4074
@@ -4078,7 +4094,7 @@ is_ast: function(astName: string, code: string): boolean
4078AST 类型定义,带有名称、行、列和子节点。 4094AST 类型定义,带有名称、行、列和子节点。
4079 4095
4080**签名:** 4096**签名:**
4081```tl 4097```lua
4082type AST = {string, integer, integer, any} 4098type AST = {string, integer, integer, any}
4083``` 4099```
4084 4100
@@ -4091,7 +4107,7 @@ type AST = {string, integer, integer, any}
4091将代码转换为 AST。 4107将代码转换为 AST。
4092 4108
4093**签名:** 4109**签名:**
4094```tl 4110```lua
4095to_ast: function(code: string, flattenLevel?: number, astName?: string): 4111to_ast: function(code: string, flattenLevel?: number, astName?: string):
4096 --[[AST]] AST | nil, 4112 --[[AST]] AST | nil,
4097 --[[error]] nil | string 4113 --[[error]] nil | string
@@ -4114,7 +4130,7 @@ to_ast: function(code: string, flattenLevel?: number, astName?: string):
4114如果发生加载失败,则将错误信息中的代码行号重写为 Yuescript 代码中的原始行号。 4130如果发生加载失败,则将错误信息中的代码行号重写为 Yuescript 代码中的原始行号。
4115 4131
4116**签名:** 4132**签名:**
4117```tl 4133```lua
4118metamethod __call: function(self: yue, module: string): any... 4134metamethod __call: function(self: yue, module: string): any...
4119``` 4135```
4120 4136
@@ -4145,7 +4161,7 @@ metamethod __call: function(self: yue, module: string): any...
4145编译器是否应该收集代码中出现的全局变量。 4161编译器是否应该收集代码中出现的全局变量。
4146 4162
4147**签名:** 4163**签名:**
4148```tl 4164```lua
4149lint_global: boolean 4165lint_global: boolean
4150``` 4166```
4151 4167
@@ -4158,7 +4174,7 @@ lint_global: boolean
4158编译器是否应该对根层级的代码块进行隐式的表达式返回。 4174编译器是否应该对根层级的代码块进行隐式的表达式返回。
4159 4175
4160**签名:** 4176**签名:**
4161```tl 4177```lua
4162implicit_return_root: boolean 4178implicit_return_root: boolean
4163``` 4179```
4164 4180
@@ -4171,7 +4187,7 @@ implicit_return_root: boolean
4171编译器是否应该在编译后的代码中保留原始行号。 4187编译器是否应该在编译后的代码中保留原始行号。
4172 4188
4173**签名:** 4189**签名:**
4174```tl 4190```lua
4175reserve_line_number: boolean 4191reserve_line_number: boolean
4176``` 4192```
4177 4193
@@ -4184,7 +4200,7 @@ reserve_line_number: boolean
4184编译器是否应该在编译后的代码中使用空格字符而不是制表符字符。 4200编译器是否应该在编译后的代码中使用空格字符而不是制表符字符。
4185 4201
4186**签名:** 4202**签名:**
4187```tl 4203```lua
4188space_over_tab: boolean 4204space_over_tab: boolean
4189``` 4205```
4190 4206
@@ -4197,7 +4213,7 @@ space_over_tab: boolean
4197编译器是否应该将要编译的代码视为当前正在编译的模块。仅供编译器内部使用。 4213编译器是否应该将要编译的代码视为当前正在编译的模块。仅供编译器内部使用。
4198 4214
4199**签名:** 4215**签名:**
4200```tl 4216```lua
4201same_module: boolean 4217same_module: boolean
4202``` 4218```
4203 4219
@@ -4210,7 +4226,7 @@ same_module: boolean
4210编译器错误消息是否应该包含行号偏移量。仅供编译器内部使用。 4226编译器错误消息是否应该包含行号偏移量。仅供编译器内部使用。
4211 4227
4212**签名:** 4228**签名:**
4213```tl 4229```lua
4214line_offset: integer 4230line_offset: integer
4215``` 4231```
4216 4232
@@ -4223,7 +4239,7 @@ line_offset: integer
4223目标 Lua 版本枚举。 4239目标 Lua 版本枚举。
4224 4240
4225**签名:** 4241**签名:**
4226```tl 4242```lua
4227enum LuaTarget 4243enum LuaTarget
4228 "5.1" 4244 "5.1"
4229 "5.2" 4245 "5.2"
@@ -4242,7 +4258,7 @@ end
4242要传递给编译函数的额外选项。 4258要传递给编译函数的额外选项。
4243 4259
4244**签名:** 4260**签名:**
4245```tl 4261```lua
4246options: Options 4262options: Options
4247``` 4263```
4248 4264
@@ -4261,7 +4277,7 @@ options: Options
4261编译目标 Lua 版本。 4277编译目标 Lua 版本。
4262 4278
4263**签名:** 4279**签名:**
4264```tl 4280```lua
4265target: LuaTarget 4281target: LuaTarget
4266``` 4282```
4267 4283
@@ -4274,7 +4290,7 @@ target: LuaTarget
4274额外模块搜索路径。 4290额外模块搜索路径。
4275 4291
4276**签名:** 4292**签名:**
4277```tl 4293```lua
4278path: string 4294path: string
4279``` 4295```
4280 4296
@@ -4287,7 +4303,7 @@ path: string
4287是否在回溯错误消息中输出代码块的局部变量。默认为 false。 4303是否在回溯错误消息中输出代码块的局部变量。默认为 false。
4288 4304
4289**签名:** 4305**签名:**
4290```tl 4306```lua
4291dump_locals: boolean 4307dump_locals: boolean
4292``` 4308```
4293 4309
@@ -4300,7 +4316,7 @@ dump_locals: boolean
4300是否简化输出的错误消息。默认为 true。 4316是否简化输出的错误消息。默认为 true。
4301 4317
4302**签名:** 4318**签名:**
4303```tl 4319```lua
4304simplified: boolean 4320simplified: boolean
4305``` 4321```
4306 4322