Skip to content

Commit

Permalink
新增CHANGELOG.md
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Oct 1, 2022
1 parent 48112ea commit e564975
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 8 deletions.
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)`
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@
./lk -f <file>
```

## 📄 语法
## 📄 速览
**详细语法**,可以查看 [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')
}

Expand Down
2 changes: 1 addition & 1 deletion consts/lang.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package consts

var (
VERSION = `0.1.1`
VERSION = `0.1.2`
SIGNATURE = `LANG_LK`
)
22 changes: 20 additions & 2 deletions stdlib/lib_os.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion test/os.lk
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit e564975

Please sign in to comment.