luatable

package module
v0.0.0-...-9f9e314 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

README

luatable

根据lua格式修改的配置表,

格式说明

格式如下:

Config1 = {
    {
        id=1,
        name="name1",
    },
    {
        id=2,
        name="name2",
    }
},
Config2 = {
    name1 = {
        id=1,
        name="name1",
    },
    name2 = {
        id=2,
        name="name2",
    }
}

解析成map为:

map[Config1:[map[id:1 name:name1] map[id:2 name:name2]] Config2:map[name1:map[id:1 name:name1] name2:map[id:2 name:name2]]]

再将map转成json:

{"Config1":[{"id":1,"name":"name1"},{"id":2,"name":"name2"}],"Config2":{"name1":{"id":1,"name":"name1"},"name2":{"id":2,"name":"name2"}}}

使用方式

  • 安装
   go get github.com/billyplus/luatable
  • 使用

    和json包里面的Unmarshal一样

    var result interface{}
    err := luatable.Unmarshal(tc.data, &result)

    if assert.NoError(err, tc.name) {
        
    }

TODO

  • Unmarshal:将字符串转成对象
  • Marshal:将对象转成字符串

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal 将字符串解析成对象、数组、或变量

Types

type Pos

type Pos int

Pos represents a byte position in the original input text from which this template was parsed.

type Reader

type Reader interface {
	ReadAll() (string, error)
}

Reader 接口读取全部内容,返回string

type Token

type Token interface {
	// Filter(cond interface{}) bool // 根据条件过滤token
	Position() string // 返回position的字符串表达式
	String() string   // 返回token的字符串表达式
	Value() string    // 获取实际的值
	Type() tokType    // 获取token type
}

Token 用来描述一个token实例

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL