diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..9fbd432 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,34 @@ +# CHANGELOG +**仅包含语言LK的变化** + +## 0.1.2 +- `Table`索引从`0`开始 +- 去除以`'''` `"""`构造长String,当前仅支持``` `` ```构造 +- 修改`stdlib_http`库部分接口 +- 包名改为`lk` +- `stdlib_os`新增`os.args`接口,可用于获取命令行参数 +- 支持`ID++` `ID1 += ID2`等语法(通过编译器匹配,自动转换为`ID = ID + 1` +- `REPL`优化,支持方向键等(eg:上句存在语法错误,快捷修改上一行) +- `stdlib_os`支持`mkdir` + +## 0.1.1 +- 支持任意对象的`concat` +- 新增`stdlib_re` +- 支持`REPL` +- 支持`32`位系统 +- `string.format` -> `fmt` + +## 0.1.0 +- `table`构造方式:`=` -> `:`, eg: `{a = 'a'}` -> `{a: 'a'}` +- 使用`json`作为编译后格式 +- 使用`//` `/* */`用作注释 +- 新增`stdlib_http` `stdlib_json` +- `stdlib_os`支持`write` `read` `rm` `mv` `exec` +- `stdlib_base`新增`kv`函数,返回`key`列表和`value`列表 +- 支持将`table`作为参数传递 +- 去除`repeat` `until` `goto` +- `do block end` -> `{ block }` +- `tostring` -> `str`, `tonumber` -> `num` +- 编译器自动为`for ID{, ID} in ID {`添加`range` ( 原`paris` ) +- 将`stdlib_table`的内容移入`stdlib_base` +- 去除`prefixexp [‘:’ Name] args`支持,不允许`function ID:ID(args)` \ No newline at end of file diff --git a/README.md b/README.md index 6e9c2c5..9ce1129 100644 --- a/README.md +++ b/README.md @@ -22,20 +22,23 @@ ./lk -f ``` -## 📄 语法 +## 📄 速览 **详细语法**,可以查看 [test](test) 文件夹的内容 ```js // 发送请求 -shy _, resp = http.post( +shy resp, err = http.post( 'http://httpbin.org/post', {'accept': 'application/json'}, '{"foo": "bar"}' ) -print(resp) +if err != nil { + error(err) +} +print(resp.code, resp.body) // json解析 -if json.get(resp, 'json.foo') != 'bar' { +if json.get(resp.body, 'json.foo') != 'bar' { error('mismatch result') } diff --git a/consts/lang.go b/consts/lang.go index c6c609d..d36d887 100644 --- a/consts/lang.go +++ b/consts/lang.go @@ -1,6 +1,6 @@ package consts var ( - VERSION = `0.1.1` + VERSION = `0.1.2` SIGNATURE = `LANG_LK` ) diff --git a/stdlib/lib_os.go b/stdlib/lib_os.go index 1c5cd7b..5db0252 100644 --- a/stdlib/lib_os.go +++ b/stdlib/lib_os.go @@ -18,7 +18,7 @@ var sysLib = map[string]GoFunction{ "env": osGetEnv, "exec": osExecute, "exit": osExit, - "dir": osDir, + "ls": osLs, "read": osRead, "write": osWrite, "sleep": osSleep, @@ -40,13 +40,31 @@ func pushArgs(ls LkState) { ls.SetField(-2, "args") } +func osMkdir(ls LkState) int { + path := ls.CheckString(1) + rescusive := ls.OptBool(2, false) + perm := fs.FileMode(ls.OptInteger(3, 0744)) + if rescusive { + err := os.MkdirAll(path, perm) + if err != nil { + ls.PushString(err.Error()) + return 1 + } + } else if err := os.Mkdir(path, perm); err != nil { + ls.PushString(err.Error()) + return 1 + } + ls.PushNil() + return 1 +} + func osSleep(ls LkState) int { milliSec := ls.CheckInteger(1) time.Sleep(time.Duration(milliSec) * time.Millisecond) return 0 } -func osDir(ls LkState) int { +func osLs(ls LkState) int { dir := ls.CheckString(1) files, err := os.ReadDir(dir) if err != nil { diff --git a/test/os.lk b/test/os.lk index 55b67db..ccddb85 100644 --- a/test/os.lk +++ b/test/os.lk @@ -20,11 +20,16 @@ pri('ls result: ', ok, result) pri('env HOME: ', os.env('HOME')) pri('date: ', os.date()) -shy dirs, err = os.dir('test') +shy dirs, err = os.ls('test') for _, dir in dirs { print(dir) } +shy err = os.mkdir('test', true) +if err { + pri('mkdir err: ', err) +} + pri('os.sleep(1)') os.sleep(1) pri('os.args')