Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
.travis.yml | H A D | 23-Mar-2015 | 150 | |||
LICENSE | H A D | 23-Mar-2015 | 1.1 KiB | |||
README.rst | H A D | 23-Mar-2015 | 2.2 KiB | |||
gluamapper.go | H A D | 23-Mar-2015 | 2.7 KiB | |||
gluamapper_example_test.go | H A D | 23-Mar-2015 | 725 | |||
gluamapper_test.go | H A D | 23-Mar-2015 | 3 KiB |
README.rst
1=============================================================================== 2gluamapper: maps a GopherLua table to a Go struct 3=============================================================================== 4 5.. image:: https://godoc.org/github.com/yuin/gluamapper?status.svg 6 :target: http://godoc.org/github.com/yuin/gluamapper 7 8.. image:: https://travis-ci.org/yuin/gluamapper.svg 9 :target: https://travis-ci.org/yuin/gluamapper 10 11| 12 13gluamapper provides an easy way to map GopherLua tables to Go structs. 14 15gluamapper converts a GopherLua table to ``map[string]interface{}`` , and then converts it to a Go struct using `mapstructure <https://github.com/mitchellh/mapstructure/>`_ . 16 17---------------------------------------------------------------- 18Installation 19---------------------------------------------------------------- 20 21.. code-block:: bash 22 23 go get github.com/yuin/gluamapper 24 25---------------------------------------------------------------- 26API 27---------------------------------------------------------------- 28See `Go doc <http://godoc.org/github.com/yuin/gluamapper>`_ . 29 30---------------------------------------------------------------- 31Usage 32---------------------------------------------------------------- 33 34.. code-block:: go 35 36 type Role struct { 37 Name string 38 } 39 40 type Person struct { 41 Name string 42 Age int 43 WorkPlace string 44 Role []*Role 45 } 46 47 L := lua.NewState() 48 if err := L.DoString(` 49 person = { 50 name = "Michel", 51 age = "31", -- weakly input 52 work_place = "San Jose", 53 role = { 54 { 55 name = "Administrator" 56 }, 57 { 58 name = "Operator" 59 } 60 } 61 } 62 `); err != nil { 63 panic(err) 64 } 65 var person Person 66 if err := gluamapper.Map(L.GetGlobal("person").(*lua.LTable), &person); err != nil { 67 panic(err) 68 } 69 fmt.Printf("%s %d", person.Name, person.Age) 70 71---------------------------------------------------------------- 72License 73---------------------------------------------------------------- 74MIT 75 76---------------------------------------------------------------- 77Author 78---------------------------------------------------------------- 79Yusuke Inuzuka 80