差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
manual:reference:package:standard:main_page [2023/03/23 15:25] – mikecovlee | manual:reference:package:standard:main_page [2023/07/17 16:25] (当前版本) – [解释器上下文环境] mikecovlee | ||
---|---|---|---|
行 1: | 行 1: | ||
====== Covariant Script 标准包 ====== | ====== Covariant Script 标准包 ====== | ||
+ | 标准包是内置于 CovScript 解释器中的各类功能和函数,是标准的组成部分之一 | ||
\\ | \\ | ||
===== 3.1 全局作用域(global) ===== | ===== 3.1 全局作用域(global) ===== | ||
行 19: | 行 20: | ||
\\ | \\ | ||
^**单例对象** | ^**单例对象** | ||
- | | '' | + | | '' |
\\ | \\ | ||
^**类型** | ^**类型** | ||
行 92: | 行 93: | ||
|'' | |'' | ||
|'' | |'' | ||
- | |'' | + | |'' |
==== 3.3.3 输入流(istream) ==== | ==== 3.3.3 输入流(istream) ==== | ||
行 143: | 行 144: | ||
\\ | \\ | ||
^方法 | ^方法 | ||
- | |void **exit**(number) | + | |void **exit**(number) |
|boolean **is_platform_darwin**() | |boolean **is_platform_darwin**() | ||
|boolean **is_platform_linux**() | |boolean **is_platform_linux**() | ||
行 149: | 行 150: | ||
|boolean **is_platform_windows**() | |boolean **is_platform_windows**() | ||
|number **run**(string) | |number **run**(string) | ||
- | |string **getenv**(string) | + | |string **getenv**(string) |
行 160: | 行 161: | ||
|void **gotoxy**(number x, number y) |移动光标至x,y | | |void **gotoxy**(number x, number y) |移动光标至x,y | | ||
|bool **kbhit**() | |bool **kbhit**() | ||
- | |number **terminal_height**() | ||
|number **terminal_width**() | |number **terminal_width**() | ||
+ | |number **terminal_height**() | ||
行 167: | 行 168: | ||
^方法 | ^方法 | ||
- | |boolean **copy**(string path, string target_path) | + | |boolean **copy**(string path, string target_path) |
- | |boolean **remove**(string path) |删除文件 | | + | |boolean **remove**(string path) | 删除文件 | |
- | |boolean **exists**(string path) |判断文件是否存在 | | + | |boolean **exist**(string path) | 判断文件是否存在 | |
- | |boolean **rename**(string path,string target_path) | + | |boolean **rename**(string path,string target_path) |
- | |boolean | + | |number |
- | |boolean | + | |number |
- | |boolean **can_read**(string path) |判定一个路径是否具有可读权限 | | + | |boolean **can_read**(string path) | 判定一个路径是否具有可读权限 | |
- | |boolean **can_write**(string path) |判定一个路径是否具有可写权限 | | + | |boolean **can_write**(string path) | 判定一个路径是否具有可写权限 | |
- | |boolean **can_execute**(string path) |判定一个文件是否为可执行文件 | | + | |boolean **can_execute**(string path) | 判定一个文件是否为可执行文件 |
- | |boolean **mkdir**(string path) |创建一个目录,成功返回真 | | + | |
- | |boolean **mkdir_p**(string path) |递归创建一个目录,成功返回真 | | + | ==== 3.4.3 路径(system.path) ==== |
- | |boolean **chmod**(string path,string mod) |更改路径权限 | | + | |
- | |boolean **chmod_r**(string path,string mod) |递归更改路径权限 | | + | ^命名空间 |
+ | | '' | ||
+ | | '' | ||
+ | \\ | ||
+ | ^单例对象与方法 | ||
+ | |char **separator** | ||
+ | |char **delimiter** | ||
+ | |array **scan**(string) | ||
+ | |boolean **copy**(string path, string target_path) | ||
+ | |boolean **remove**(string path) | 删除文件 | | ||
+ | |boolean **exist**(string path) | 判断目录是否存在 | | ||
+ | |boolean **rename**(string path,string target_path) | ||
+ | |boolean **mkdir**(string path) | 创建一个目录,成功返回真 | | ||
+ | |boolean **mkdir_p**(string path) | 递归创建一个目录,成功返回真 | | ||
+ | |boolean **chmod**(string path,string mod) | 更改路径权限 | | ||
+ | |boolean **chmod_r**(string path,string mod) | 递归更改路径权限 | ||
+ | |boolean **is_file**(string path) | 判定一个路径是否为文件 | | ||
+ | |boolean **is_directory**(string path) | 判定一个路径是否为目录 | ||
< | < | ||
行 193: | 行 211: | ||
</ | </ | ||
- | ==== 3.4.3 路径(system.path) ==== | + | === 3.4.3.1 路径类型(system.path.type) === |
- | + | ||
- | ^命名空间 | + | |
- | | '' | + | |
- | | '' | + | |
- | \\ | + | |
- | ^单例对象与方法 | + | |
- | |char **separator** | + | |
- | |char **delimiter** | + | |
- | |array **scan**(string) | + | |
- | + | ||
- | === 3.4.3.1 路径类型(system.type) === | + | |
^选项代码 | ^选项代码 | ||
行 226: | 行 233: | ||
===== 3.5 运行时(runtime) ===== | ===== 3.5 运行时(runtime) ===== | ||
+ | ==== 运行时命名空间 ==== | ||
^命名空间 | ^命名空间 | ||
- | | '' | + | | '' |
- | ^单例对* | + | ^单例对象 |
- | |number **std_version** | + | |number **std_version** |
^方法 | ^方法 | ||
- | |void **add_literal**([context], | ||
- | |number **argument_count**([function] func) |返回函数的参数数量 | | ||
- | |[expression] **build**([context], | ||
- | |array **cmd_args**([context]) | ||
- | |void **delay**(number) | ||
- | |[exception] **exception**(string) | ||
- | |string **get_current_dir**() | ||
- | |string **get_import_path**() | ||
- | |[hash_value] **hash**(var) | ||
- | |[namespace] **import**([context], | ||
|void **info**() | |void **info**() | ||
- | |[time_type] **local_time**() |获取当地时间和日期 | | + | |[hash_value] **hash**(var) |
- | |var **solve**([context], | + | |
- | |[namespace] **source_import**([context], | + | |
|number **time**() | |number **time**() | ||
+ | |void **delay**(number) | ||
+ | |[time_type] **local_time**() | ||
+ | |[time_type] **local_time**(number unix_time) | ||
|[time_type] **utc_time**() | |[time_type] **utc_time**() | ||
+ | |[time_type] **utc_time**(number unix_time) | ||
+ | |[exception] **exception**(string) | ||
+ | |number **argument_count**([function] func) |返回函数的参数数量 | | ||
+ | |string **get_current_dir**() | ||
+ | |string **get_import_path**() | ||
|var **wait_for**(number time, [function] func, array args) |使用传入的参数执行函数,等待指定时间(毫秒)后若函数仍未完成则抛出异常 | | |var **wait_for**(number time, [function] func, array args) |使用传入的参数执行函数,等待指定时间(毫秒)后若函数仍未完成则抛出异常 | | ||
|var **wait_until**(number time, [function] func, array args) |使用传入的参数执行函数,直到指定时间(毫秒)后若函数仍未完成则抛出异常 | | |var **wait_until**(number time, [function] func, array args) |使用传入的参数执行函数,直到指定时间(毫秒)后若函数仍未完成则抛出异常 | | ||
+ | |||
+ | ==== 解释器上下文环境 ==== | ||
+ | |||
+ | ^单例对象 | ||
+ | |array **cmd_args** | 由 string 构成的运行参数 array | | ||
+ | |[type] **channel** | 协程消息队列类型 | | ||
+ | |||
+ | ^方法 | ||
+ | |[expression] **build**([context], | ||
+ | |var **solve**([context], | ||
+ | |[namespace] **import**([context], | ||
+ | |[namespace] **source_import**([context], | ||
+ | |void **add_literal**([context], | ||
+ | |void **link_var**([context], | ||
+ | |void **unlink_var**([context], | ||
+ | |[coroutine] **create_co**([context], | ||
+ | |[coroutine] **create_co_s**([context], | ||
+ | |void **destroy_co**([context], | ||
+ | |var **await**([context], | ||
+ | |var **await_s**([context], | ||
+ | |number **resume**([context], | ||
+ | |void **yield**([context]) | 切换回主协程 | | ||
+ | |||
+ | **注意,await 系列函数一般在协程中使用,用于在等待执行时间较长函数的过程中自动的将上下文交由其他协程使用(也就是自动 yield)**\\ | ||
+ | **因此,await 系列函数应使用原始的 CovScript API,而不是 CovScript 函数 ** | ||
+ | |||
+ | === 协程消息队列类型 === | ||
+ | |||
+ | ^方法 | ||
+ | |void **consumer**([channel], | ||
+ | |void **push**([channel], | ||
+ | |var **pop**([channel]) |异步读取数据,会将当前协程设置为消费者,并当队列为空时 yield | | ||
+ | |void **clear**([channel]) |清空队列 | | ||
+ | |void **touch**([channel]) |手动唤醒消费者 | | ||
+ | |number **size**([channel]) |获取队列大小 | | ||
+ | |boolean **empty**([channel]) |返回队列是否为空 | | ||
==== 3.5.1 时间类型命名空间(runtime.time_type) ==== | ==== 3.5.1 时间类型命名空间(runtime.time_type) ==== | ||
行 265: | 行 305: | ||
|number **year**([time_type]) | |number **year**([time_type]) | ||
|boolean **is_dst**([time_type]) | |boolean **is_dst**([time_type]) | ||
+ | |number **unixtime**([time_type]) |*转换为 Unix Time | | ||
----- | ----- | ||
行 296: | 行 337: | ||
^单例对象 | ^单例对象 | ||
- | |number **max** | + | |number **max** |
- | |number **min** | + | |number **min** |
+ | |number **integer_max** | ||
+ | |number **integer_min** | ||
+ | |number **float_max** | ||
+ | |number **float_min** | ||
|number **inf** | |number **inf** | ||
|number **nan** | |number **nan** | ||
行 327: | 行 372: | ||
\\ | \\ | ||
- | ===== 3.8 字符串(string) ===== | + | ===== 3.8 数值(number) ===== |
+ | |||
+ | ^**方法** | ||
+ | |boolean **is_integer**(number) | ||
+ | |boolean **is_float**(number) | ||
+ | |integer **ntoi**(number) | ||
+ | |float **ntof**(number) | ||
+ | |||
+ | ----- | ||
+ | \\ | ||
+ | |||
+ | ===== 3.9 字符串(string) ===== | ||
^方法 | ^方法 | ||
行 349: | 行 405: | ||
\\ | \\ | ||
- | ===== 3.9 数组(array) ===== | + | ===== 3.10 数组(array) ===== |
^命名空间 | ^命名空间 | ||
- | |'' | + | |'' |
^方法 | ^方法 | ||
行 369: | 行 425: | ||
|void **push_back**(array, | |void **push_back**(array, | ||
|var **pop_back**(array) | |var **pop_back**(array) | ||
+ | |var **sort**(array, | ||
|list **to_list**(array) | |list **to_list**(array) | ||
|hash_map **to_hash_map**(array) | |hash_map **to_hash_map**(array) | ||
行 376: | 行 433: | ||
\\ | \\ | ||
- | ==== 3.9.1 数组迭代器(array.iterator) ==== | + | ==== 3.10.1 数组迭代器(array.iterator) ==== |
^方法 | ^方法 | ||
行 388: | 行 445: | ||
\\ | \\ | ||
- | ===== 3.10 线性表(list) ===== | + | ===== 3.11 线性表(list) ===== |
^命名空间 | ^命名空间 | ||
- | |'' | + | |'' |
^方法 | ^方法 | ||
行 410: | 行 467: | ||
|void **reverse**(list) | |void **reverse**(list) | ||
|void **unique**(list) | |void **unique**(list) | ||
+ | |void **sort**(list, | ||
- | ==== 3.10.1 线性表迭代器(list.iterator) ==== | + | ==== 3.11.1 线性表迭代器(list.iterator) ==== |
^方法 | ^方法 | ||
行 418: | 行 476: | ||
|var **data**([iterator]) | |var **data**([iterator]) | ||
- | ===== 3.11 映射(pair) ===== | + | ===== 3.12 映射(pair) ===== |
^方法 | ^方法 | ||
行 427: | 行 485: | ||
\\ | \\ | ||
- | ===== 3.12 哈希映射(hash_map) ===== | + | ===== 3.13 哈希映射(hash_map) ===== |
^方法 | ^方法 | ||
行 438: | 行 496: | ||
|boolean **exist**(hash_map, | |boolean **exist**(hash_map, | ||
- | ===== 3.13 哈希集合(hash_set) ===== | + | ===== 3.14 哈希集合(hash_set) ===== |
^方法 | ^方法 |