Skip to content

Commit

Permalink
优化 luaTable 默认 print 格式
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Oct 3, 2022
1 parent e30dba6 commit fc71d15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- `REPL`支持自动添加`print`
- 不再支持任意对象 `concat`,如不能拼接则会返回 `""`
- 去除 `metatable` 属性,直接将其置于 `luaTable` 对象中
- 优化 `luaTable` 默认 `print` 格式
- `PCall` 仅在 `REPL` 输出错误

## 0.1.2
- `Table`索引从`0`开始
Expand Down
6 changes: 6 additions & 0 deletions state/lua_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ type luaTable struct {
}

func (self *luaTable) String() (string, error) {
if len(self._map) == 0 {
return json.MarshalToString(self.arr)
}
if len(self.arr) == 0 {
return json.MarshalToString(self._map)
}
m := map[string]any{
"arr": self.arr,
"map": self._map,
Expand Down

0 comments on commit fc71d15

Please sign in to comment.