install gnu smalltalk
autoreconf -i
./configure --with-x --enable-blox=yes
sudo make install
install his own package
- ROE.star
- DBI.star
- DBD-SQLite.star
- sqlite3 c devel package, maybe require
sudo gst-package ROE.star
sudo gst-package package.xml
todo.st, kind of shit
"1. 加载依赖包"
PackageLoader fileInPackage: 'ROE'.
PackageLoader fileInPackage: 'DBI'.
PackageLoader fileInPackage: 'DBD-SQLite'.
"2. TODO 程序(修复键不存在错误)"
Eval [
| dbName conn command running taskId taskDesc lastId substring getLastInsertId |
dbName := 'todo.db'.
running := true.
"创建数据库连接"
conn := DBI.Connection
connect: 'dbi:SQLite:dbname=' , dbName
user: nil
password: nil.
"字符串截取方法"
substring := [:str :start :end |
| result i char |
result := ''.
i := start.
[i <= end and: [i <= str size]] whileTrue: [
char := str at: i.
result := result , char asString.
i := i + 1.
].
result
].
"【核心修复】用列名作为键获取ID(适配LookupTable)"
getLastInsertId := [:dbConn |
| rs row |
"查询时给列指定别名'last_id',确保行对象有明确的键"
rs := dbConn select: 'SELECT last_insert_rowid() AS last_id'.
row := rs next. "获取行对象(LookupTable)"
row at: 'last_id' "用列名'last_id'作为键访问,避免键不存在错误"
].
[
"初始化表"
conn do: 'CREATE TABLE IF NOT EXISTS tasks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
description TEXT NOT NULL,
completed INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)'.
Transcript show: 'TODO 程序启动成功!'; cr.
Transcript show: '命令:add [任务]、list、complete [ID]、delete [ID]、exit'; cr.
Transcript show: '--------------------------'; cr.
"命令循环"
[running] whileTrue: [
Transcript show: '> '; flush.
command := (FileStream stdin nextLine) trimSeparators.
"处理add命令"
(command size >= 4 and: [ (command copyFrom: 1 to: 4) = 'add ' ]) ifTrue: [
taskDesc := command copyFrom: 5 to: command size.
taskDesc isEmpty
ifTrue: [Transcript show: '错误:任务描述不能为空'; cr]
ifFalse: [
conn do: 'INSERT INTO tasks (description) VALUES ("', taskDesc, '")'.
lastId := getLastInsertId value: conn. "使用修复后的ID获取方法"
Transcript show: '已添加任务(ID: ', lastId printString, '):', taskDesc; cr.
]
] ifFalse: [
"处理list命令"
(command = 'list') ifTrue: [
| rs row status createdAt |
Transcript show: 'ID | 状态 | 任务描述 | 创建时间'; cr.
Transcript show: '-----------------------------------'; cr.
rs := conn select: 'SELECT id, description, completed, created_at FROM tasks ORDER BY id DESC'.
[rs atEnd] whileFalse: [
row := rs next. "行对象包含'id'等列名作为键"
status := (row at: 'completed') = 1 ifTrue: ['✓'] ifFalse: ['✗'].
createdAt := substring value: (row at: 'created_at') value: 1 value: 16.
Transcript show: (row at: 'id') printString;
show: ' | ';
show: status;
show: ' | ';
show: (row at: 'description');
show: ' | ';
show: createdAt;
cr.
]
] ifFalse: [
"处理complete命令"
(command size >= 9 and: [ (command copyFrom: 1 to: 9) = 'complete ' ]) ifTrue: [
taskId := (command copyFrom: 10 to: command size) asNumber.
(taskId isNil or: [taskId isInteger not])
ifTrue: [Transcript show: '错误:请输入有效ID'; cr]
ifFalse: [
conn do: 'UPDATE tasks SET completed = 1 WHERE id = ', taskId printString.
(conn handle changes) > 0
ifTrue: [Transcript show: '已完成任务 ', taskId printString; cr]
ifFalse: [Transcript show: '错误:ID不存在'; cr]
]
] ifFalse: [
"处理delete命令"
(command size >= 7 and: [ (command copyFrom: 1 to: 7) = 'delete ' ]) ifTrue: [
taskId := (command copyFrom: 8 to: command size) asNumber.
(taskId isNil or: [taskId isInteger not])
ifTrue: [Transcript show: '错误:请输入有效ID'; cr]
ifFalse: [
conn do: 'DELETE FROM tasks WHERE id = ', taskId printString.
(conn handle changes) > 0
ifTrue: [Transcript show: '已删除任务 ', taskId printString; cr]
ifFalse: [Transcript show: '错误:ID不存在'; cr]
]
] ifFalse: [
"处理exit命令"
(command = 'exit') ifTrue: [
running := false.
Transcript show: '程序已退出,数据已保存'; cr
] ifFalse: [
Transcript show: '未知命令,请重新输入'; cr
]
]
]
]
]
]
] ensure: [
conn close.
]
]
测试gst <file.st>
gst miss.st
"Global garbage collection... done"
Loading package ROE
Loading package ROE
Loading package DBI
Loading package DBI
Loading package DBD-SQLite
TODO 程序启动成功!
命令:add [任务]、list、complete [ID]、delete [ID]、exit
--------------------------
> add 1
已添加任务(ID: 22):1
> add 2lcallcks
已添加任务(ID: 23):2lcallcks
> add fuckerfucker
已添加任务(ID: 24):fuckerfucker
> list
ID | 状态 | 任务描述 | 创建时间
-----------------------------------
24 | ✗ | fuckerfucker | 2025-08-09 18:12
23 | ✗ | 2lcallcks | 2025-08-09 18:12
22 | ✗ | 1 | 2025-08-09 18:12
21 | ✗ | lxlsal | 2025-08-09 18:05
20 | ✗ | llal | 2025-08-09 18:05
19 | ✗ | xlla | 2025-08-09 18:04
18 | ✗ | llxa | 2025-08-09 18:02
17 | ✗ | lla | 2025-08-09 18:01
16 | ✗ | 1l | 2025-08-09 17:59
15 | ✗ | 1 | 2025-08-09 17:57
14 | ✗ | 2222 | 2025-08-09 17:53
13 | ✗ | 1111 | 2025-08-09 17:53
12 | ✗ | 4 | 2025-08-09 17:44
11 | ✗ | 3 | 2025-08-09 17:44
10 | ✗ | 2 | 2025-08-09 17:44
9 | ✗ | 1 | 2025-08-09 17:44
8 | ✗ | llxa | 2025-08-09 17:29
7 | ✗ | kkcs | 2025-08-09 17:29
6 | ✗ | lxlsa | 2025-08-09 17:28
5 | ✗ | lcds | 2025-08-09 17:28
> complete 19
已完成任务 19
> list
ID | 状态 | 任务描述 | 创建时间
-----------------------------------
24 | ✗ | fuckerfucker | 2025-08-09 18:12
23 | ✗ | 2lcallcks | 2025-08-09 18:12
22 | ✗ | 1 | 2025-08-09 18:12
21 | ✗ | lxlsal | 2025-08-09 18:05
20 | ✗ | llal | 2025-08-09 18:05
19 | ✓ | xlla | 2025-08-09 18:04
18 | ✗ | llxa | 2025-08-09 18:02
17 | ✗ | lla | 2025-08-09 18:01
16 | ✗ | 1l | 2025-08-09 17:59
15 | ✗ | 1 | 2025-08-09 17:57
14 | ✗ | 2222 | 2025-08-09 17:53
13 | ✗ | 1111 | 2025-08-09 17:53
12 | ✗ | 4 | 2025-08-09 17:44
11 | ✗ | 3 | 2025-08-09 17:44
10 | ✗ | 2 | 2025-08-09 17:44
9 | ✗ | 1 | 2025-08-09 17:44
8 | ✗ | llxa | 2025-08-09 17:29
7 | ✗ | kkcs | 2025-08-09 17:29
6 | ✗ | lxlsa | 2025-08-09 17:28
5 | ✗ | lcds | 2025-08-09 17:28
> delete 19
已删除任务 19
> exit
程序已退出,数据已保存
这个程序花了6个小时+ debug, damn, shut down Windows and sleep now (2:21 am)