gluamapper provides an easy way to map GopherLua values to Go values.
go get github.com/jinq0123/gluamapper
See Go doc.
type Role struct {
Name string
}
type Person struct {
Name string
Age int
WorkPlace string
Role []*Role
}
L := lua.NewState()
if err := L.DoString(`
person = {
Name = "Michel",
Age = 31,
WorkPlace = "San Jose",
Role = {
{
Name = "Administrator"
},
{
Name = "Operator"
}
}
}
`); err != nil {
panic(err)
}
var person Person
if err := gluamapper.Map(L.GetGlobal("person"), &person); err != nil {
panic(err)
}
fmt.Printf("%s %d", person.Name, person.Age)
MIT
- Yusuke Inuzuka
- Jin Qing
Differences from yuin/gluamapper
-
Speedup
- Converts directly from Lua table to Go struct, while yuin/gluamapper
converts the table to
map[string]interface{}
, and then converts it to a Go struct usingmapstructure
. - No "weak" conversions
- returns error if types are different
- only convert Lua number to int types
- Always ignores unused keys
- Converts directly from Lua table to Go struct, while yuin/gluamapper
converts the table to
-
New feature
- Maps Lua types other than table to Go types
- Maps Lua user data to Go value
-
Bugfix
- TODO: circular reference
- handle embedded fields