Skip to content

gluamapper: maps a GopherLua table to a Go struct

License

Notifications You must be signed in to change notification settings

tooolbox/gluamapper

 
 

Repository files navigation

gluamapper

Build Go Report Card License

Maps a GopherLua table to a Go struct. This is a fork of yuin/gluamapper.

gluamapper converts a GopherLua table to map[string]interface{}, and then converts it to a Go struct using mitchellh/mapstructure.

Installation of the development version

go get -u github.com/xyproto/gluamapper

API

See Go doc.

Usage

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", -- weakly input
  work_place = "San Jose",
  role = {
    {
      name = "Administrator"
    },
    {
      name = "Operator"
    }
  }
}
`); err != nil {
    panic(err)
}
var person Person
if err := gluamapper.Map(L.GetGlobal("person").(*lua.LTable), &person); err != nil {
    panic(err)
}
fmt.Printf("%s %d", person.Name, person.Age)

General info

  • License: MIT
  • Version: 1.2.0

About

gluamapper: maps a GopherLua table to a Go struct

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%