diff options
author | Li Jin <dragon-fly@qq.com> | 2024-10-19 00:35:11 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2024-10-19 00:35:11 +0800 |
commit | 1334c0ae67fdf4cb1377e0e7a3ef291f5cf694c0 (patch) | |
tree | 8bd3fbeb396fd2fce6e5b34c3ee10f4923feca72 /doc | |
parent | 05da3cbfa3689e6c229c41156d0dd08ab554cd77 (diff) | |
download | yuescript-1334c0ae67fdf4cb1377e0e7a3ef291f5cf694c0.tar.gz yuescript-1334c0ae67fdf4cb1377e0e7a3ef291f5cf694c0.tar.bz2 yuescript-1334c0ae67fdf4cb1377e0e7a3ef291f5cf694c0.zip |
Fixed issue #174.
Diffstat (limited to 'doc')
-rwxr-xr-x | doc/docs/doc/README.md | 16 | ||||
-rwxr-xr-x | doc/docs/zh/doc/README.md | 90 |
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 | |||
1318 | You can also use if assignment in a while loop to get the value as the loop condition. | ||
1319 | ```moonscript | ||
1320 | while byte := stream\read_one! | ||
1321 | -- do something with the byte | ||
1322 | print byte | ||
1323 | ``` | ||
1324 | <YueDisplay> | ||
1325 | <pre> | ||
1326 | while 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 | ||
1318 | You can assign the results returned from a function to a varargs symbol `...`. And then access its content using the Lua way. | 1334 | You 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 | ||
1317 | while byte := stream\read_one! | ||
1318 | -- 对 byte 做一些操作 | ||
1319 | print byte | ||
1320 | ``` | ||
1321 | <YueDisplay> | ||
1322 | <pre> | ||
1323 | while 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 |
3554 | version: string | 3570 | version: string |
3555 | ``` | 3571 | ``` |
3556 | 3572 | ||
@@ -3563,7 +3579,7 @@ version: string | |||
3563 | 当前平台的文件分隔符。 | 3579 | 当前平台的文件分隔符。 |
3564 | 3580 | ||
3565 | **签名:** | 3581 | **签名:** |
3566 | ```tl | 3582 | ```lua |
3567 | dirsep: string | 3583 | dirsep: string |
3568 | ``` | 3584 | ``` |
3569 | 3585 | ||
@@ -3576,7 +3592,7 @@ dirsep: string | |||
3576 | 编译模块代码缓存。 | 3592 | 编译模块代码缓存。 |
3577 | 3593 | ||
3578 | **签名:** | 3594 | **签名:** |
3579 | ```tl | 3595 | ```lua |
3580 | yue_compiled: {string: string} | 3596 | yue_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 |
3593 | to_lua: function(code: string, config?: Config): | 3609 | to_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 |
3624 | file_exist: function(filename: string): boolean | 3640 | file_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 |
3649 | read_file: function(filename: string): string | 3665 | read_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 |
3674 | insert_loader: function(pos?: integer): boolean | 3690 | insert_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 |
3699 | remove_loader: function(): boolean | 3715 | remove_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 |
3718 | loadstring: function(input: string, chunkname: string, env: table, config?: Config): | 3734 | loadstring: 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 |
3749 | loadstring: function(input: string, chunkname: string, config?: Config): | 3765 | loadstring: 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 |
3779 | loadstring: function(input: string, config?: Config): | 3795 | loadstring: 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 |
3808 | loadfile: function(filename: string, env: table, config?: Config): | 3824 | loadfile: 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 |
3838 | loadfile: function(filename: string, config?: Config): | 3854 | loadfile: 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 |
3867 | dofile: function(filename: string, env: table, config?: Config): any... | 3883 | dofile: 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 |
3894 | dofile: function(filename: string, config?: Config): any... | 3910 | dofile: 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 |
3920 | find_modulepath: function(name: string): string | 3936 | find_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 |
3947 | pcall: function(f: function, ...: any): boolean, any... | 3963 | pcall: 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 |
3974 | require: function(name: string): any... | 3990 | require: 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 |
3999 | p: function(...: any) | 4015 | p: function(...: any) |
4000 | ``` | 4016 | ``` |
4001 | 4017 | ||
@@ -4014,7 +4030,7 @@ p: function(...: any) | |||
4014 | 当前编译器选项。 | 4030 | 当前编译器选项。 |
4015 | 4031 | ||
4016 | **签名:** | 4032 | **签名:** |
4017 | ```tl | 4033 | ```lua |
4018 | options: Config.Options | 4034 | options: 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 |
4031 | traceback: function(message: string): string | 4047 | traceback: 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 |
4056 | is_ast: function(astName: string, code: string): boolean | 4072 | is_ast: function(astName: string, code: string): boolean |
4057 | ``` | 4073 | ``` |
4058 | 4074 | ||
@@ -4078,7 +4094,7 @@ is_ast: function(astName: string, code: string): boolean | |||
4078 | AST 类型定义,带有名称、行、列和子节点。 | 4094 | AST 类型定义,带有名称、行、列和子节点。 |
4079 | 4095 | ||
4080 | **签名:** | 4096 | **签名:** |
4081 | ```tl | 4097 | ```lua |
4082 | type AST = {string, integer, integer, any} | 4098 | type 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 |
4095 | to_ast: function(code: string, flattenLevel?: number, astName?: string): | 4111 | to_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 |
4118 | metamethod __call: function(self: yue, module: string): any... | 4134 | metamethod __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 |
4149 | lint_global: boolean | 4165 | lint_global: boolean |
4150 | ``` | 4166 | ``` |
4151 | 4167 | ||
@@ -4158,7 +4174,7 @@ lint_global: boolean | |||
4158 | 编译器是否应该对根层级的代码块进行隐式的表达式返回。 | 4174 | 编译器是否应该对根层级的代码块进行隐式的表达式返回。 |
4159 | 4175 | ||
4160 | **签名:** | 4176 | **签名:** |
4161 | ```tl | 4177 | ```lua |
4162 | implicit_return_root: boolean | 4178 | implicit_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 |
4175 | reserve_line_number: boolean | 4191 | reserve_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 |
4188 | space_over_tab: boolean | 4204 | space_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 |
4201 | same_module: boolean | 4217 | same_module: boolean |
4202 | ``` | 4218 | ``` |
4203 | 4219 | ||
@@ -4210,7 +4226,7 @@ same_module: boolean | |||
4210 | 编译器错误消息是否应该包含行号偏移量。仅供编译器内部使用。 | 4226 | 编译器错误消息是否应该包含行号偏移量。仅供编译器内部使用。 |
4211 | 4227 | ||
4212 | **签名:** | 4228 | **签名:** |
4213 | ```tl | 4229 | ```lua |
4214 | line_offset: integer | 4230 | line_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 |
4227 | enum LuaTarget | 4243 | enum 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 |
4246 | options: Options | 4262 | options: Options |
4247 | ``` | 4263 | ``` |
4248 | 4264 | ||
@@ -4261,7 +4277,7 @@ options: Options | |||
4261 | 编译目标 Lua 版本。 | 4277 | 编译目标 Lua 版本。 |
4262 | 4278 | ||
4263 | **签名:** | 4279 | **签名:** |
4264 | ```tl | 4280 | ```lua |
4265 | target: LuaTarget | 4281 | target: LuaTarget |
4266 | ``` | 4282 | ``` |
4267 | 4283 | ||
@@ -4274,7 +4290,7 @@ target: LuaTarget | |||
4274 | 额外模块搜索路径。 | 4290 | 额外模块搜索路径。 |
4275 | 4291 | ||
4276 | **签名:** | 4292 | **签名:** |
4277 | ```tl | 4293 | ```lua |
4278 | path: string | 4294 | path: string |
4279 | ``` | 4295 | ``` |
4280 | 4296 | ||
@@ -4287,7 +4303,7 @@ path: string | |||
4287 | 是否在回溯错误消息中输出代码块的局部变量。默认为 false。 | 4303 | 是否在回溯错误消息中输出代码块的局部变量。默认为 false。 |
4288 | 4304 | ||
4289 | **签名:** | 4305 | **签名:** |
4290 | ```tl | 4306 | ```lua |
4291 | dump_locals: boolean | 4307 | dump_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 |
4304 | simplified: boolean | 4320 | simplified: boolean |
4305 | ``` | 4321 | ``` |
4306 | 4322 | ||