Add host stdlib modules and unify view/run capabilities.

Ship fs/time/sys/json/net L1 libs (plus existing text/table), default-on host caps with soft exit under view, bilingual public/stdlib docs, and design notes for deferred math/foreign.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-05 10:03:54 +08:00
1 parent a5d30c00b3
commit a53ebb65ee
66 files changed
+2703 -45

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
---
title: Standard library — overview
description: How to import official lib modules
---
# main
Official libraries live under lib/ (alias std/). Import them in YAML frontmatter with a greater-than line, for example lib/text.mq.md or lib/fs.mq.md.
English-named files export English APIs; Chinese-named files export Chinese APIs. JSON is special: only lib/json.mq.md (shared by both languages).
No extra allow flags: importing a module means you intend to use it. Under marqdo view or static export, exit soft-fails and long sleeps are clamped so the console stays up.
Modules: text (text / 文本), table (table / 表), files (fs / 文件), time (time / 时间), system (sys / 系统), json (json only), net (net / 网络).
Sibling pages in this folder document each module. Chinese overview: 00-索引.mq.md.
> print text=stdlib overview ok
+18
View File
@@ -0,0 +1,18 @@
---
title: 标准库 — 总览
description: 如何导入官方 lib 模块
---
# main
官方库在仓库 lib/(别名 std/)。在 YAML frontmatter 用大于号行导入,例如 lib/文本.mq.md 或 lib/文件.mq.md。
拉丁文件名导出英文 API;中文文件名导出中文 API。JSON 特例:只有 lib/json.mq.md(中英共用)。
导入即表示要用对应能力,无需再加允许旗标。marqdo view 或静态导出里,退出会软失败、长睡眠会被钳制,以免拖垮控制台。
模块:文本(text / 文本)、表(table / 表)、文件(fs / 文件)、时间(time / 时间)、系统(sys / 系统)、json(仅 json)、网络(net / 网络)。
各模块说明见本目录其它页。English: 00-overview.mq.md.
> 打印 内容=标准库总览就绪
+18
View File
@@ -0,0 +1,18 @@
---
title: lib/fs — files
description: Read and write text under the sandbox
> lib/fs.mq.md
---
# main
Import lib/fs.mq.md. Functions: read_text, write_text, append_text, exists, list_dir, make_dir, remove (path / text params).
Bare path words must not contain a slash character (parsed as division). Prefer a same-folder name or a variable.
*`ok` = > exists path=demo.txt *
+ `ok`
> print text=demo-present
+ *
> print text=demo-missing
+19
View File
@@ -0,0 +1,19 @@
---
title: lib/json — JSON
description: Shared EN/ZH path; parse and stringify
> lib/json.mq.md
---
# main
Import lib/json.mq.md from both English and Chinese docs (no translated twin). Functions: parse(text), stringify(value), get(value, key), keys(value). Objects become the map runtime type.
*`obj` = > parse text={} *
*`ty` = > type `obj` *
> print text=`ty`
*`out` = > stringify value=`obj` *
> print text=`out`
+13
View File
@@ -0,0 +1,13 @@
---
title: lib/net — HTTP
description: Minimal HTTP client and URL encode
> lib/net.mq.md
---
# main
Import lib/net.mq.md. Functions: http_get(url) returns map status/body, http_post(url, body), url_encode(text). v1 speaks cleartext http only.
*`e` = > url_encode text=hello world *
> print text=`e`
+18
View File
@@ -0,0 +1,18 @@
---
title: lib/sys — process
description: Env, cwd, args, exit, exec
> lib/sys.mq.md
---
# main
Import lib/sys.mq.md. Functions: env_get, env_set, args, cwd, exit(code), exec(cmd). Under view, exit soft-fails instead of killing the process.
*`d` = > cwd *
*`n` = > len `d` *
+ `n` > 0
> print text=cwd-ok
+ *
> print text=cwd-empty
+24
View File
@@ -0,0 +1,24 @@
---
title: lib/table — lists
description: Row count and index helpers
> lib/table.mq.md
---
# main
Import lib/table.mq.md. Functions: rows(xs), row_at(xs, i). Single-column Markdown tables are lists at runtime.
`xs` =
| v |
|---|
| a |
| b |
*`n` = > rows xs=`xs`*
> print text=`n`
*`r` = > row_at xs=`xs` i=0*
> print text=`r`
+19
View File
@@ -0,0 +1,19 @@
---
title: lib/text — strings
description: Trim, split, join wrappers
> lib/text.mq.md
---
# main
Import lib/text.mq.md. Functions: str_trim(s), str_split(s, sep), str_join(xs, sep).
*`t` = > str_trim s= marqdo *
> print text=`t`
*`parts` = > str_split s=a,b,c sep=,*
*`j` = > str_join xs=`parts` sep=-*
> print text=`j`
+19
View File
@@ -0,0 +1,19 @@
---
title: lib/time — clock
description: Unix time, format, parse, sleep
> lib/time.mq.md
---
# main
Import lib/time.mq.md. Functions: now_unix, now_ms, format(unix, pattern), parse(text, pattern), sleep_ms(ms). Patterns use strftime.
*`s` = > format unix=0 pattern=%Y-%m-%d *
> print text=`s`
*`u` = > parse text=1970-01-01 00:00:00 pattern=%Y-%m-%d %H:%M:%S *
> print text=`u`
> sleep_ms ms=0
+18
View File
@@ -0,0 +1,18 @@
---
title: lib/文件 — 文件系统
description: 沙箱内读写文本
> lib/文件.mq.md
---
# main
导入 lib/文件.mq.md。函数:读文本、写文本、追加文本、存在、列目录、建目录、删除。
裸路径字面量不要写斜杠(会被当成除法)。可用同目录文件名或变量。
*`ok` = > 存在 路径=demo.txt *
+ `ok`
> 打印 内容=有演示文件
+ *
> 打印 内容=无演示文件
+19
View File
@@ -0,0 +1,19 @@
---
title: lib/文本 — 字符串
description: 去空白、拆分、拼接
> lib/文本.mq.md
---
# main
导入 lib/文本.mq.md。函数:去空白(s)、拆分(s, sep)、拼接(xs, sep)。
*`t` = > 去空白 s= marqdo *
> 打印 内容=`t`
*`parts` = > 拆分 s=甲,乙,丙 sep=,*
*`j` = > 拼接 xs=`parts` sep=-*
> 打印 内容=`j`
+19
View File
@@ -0,0 +1,19 @@
---
title: lib/时间 — 时钟
description: Unix 时间、格式化、解析、睡眠
> lib/时间.mq.md
---
# main
导入 lib/时间.mq.md。函数:此刻秒、此刻毫秒、格式化(秒, 格式)、解析时间(内容, 格式)、睡眠毫秒(毫秒)。格式为 strftime。
*`s` = > 格式化 秒=0 格式=%Y-%m-%d *
> 打印 内容=`s`
*`u` = > 解析时间 内容=1970-01-01 00:00:00 格式=%Y-%m-%d %H:%M:%S *
> 打印 内容=`u`
> 睡眠毫秒 毫秒=0
+18
View File
@@ -0,0 +1,18 @@
---
title: lib/系统 — 进程
description: 环境变量、工作目录、参数、退出、执行
> lib/系统.mq.md
---
# main
导入 lib/系统.mq.md。函数:取环境、设环境、参数表、工作目录、退出(码)、执行(命令)。view 下退出会软失败,不结束进程。
*`d` = > 工作目录 *
*`n` = > 长度 值=`d` *
+ `n` > 0
> 打印 内容=工作目录就绪
+ *
> 打印 内容=工作目录空
+13
View File
@@ -0,0 +1,13 @@
---
title: lib/网络 — HTTP
description: 简易 HTTP 与地址编码
> lib/网络.mq.md
---
# main
导入 lib/网络.mq.md。函数:获取(地址) 返回 map status/body、提交(地址, 内容)、编码地址(内容)。本波仅明文 http。
*`e` = > 编码地址 内容=你好 *
> 打印 内容=`e`
+24
View File
@@ -0,0 +1,24 @@
---
title: lib/表 — 列表
description: 行数与取行
> lib/表.mq.md
---
# main
导入 lib/表.mq.md。函数:行数(xs)、取行(xs, i)。单列表在运行时是列表。
`xs` =
| v |
|---|
| 甲 |
| 乙 |
*`n` = > 行数 xs=`xs`*
> 打印 内容=`n`
*`r` = > 取行 xs=`xs` i=0*
> 打印 内容=`r`