Gluamapper
gluamapper: maps a GopherLua table to a Go struct
Install / Use
/learn @yuin/GluamapperREADME
=============================================================================== gluamapper: maps a GopherLua table to a Go struct
.. image:: https://godoc.org/github.com/yuin/gluamapper?status.svg :target: http://godoc.org/github.com/yuin/gluamapper
.. image:: https://travis-ci.org/yuin/gluamapper.svg :target: https://travis-ci.org/yuin/gluamapper
|
gluamapper provides an easy way to map GopherLua tables to Go structs.
gluamapper converts a GopherLua table to map[string]interface{} , and then converts it to a Go struct using mapstructure <https://github.com/mitchellh/mapstructure/>_ .
Installation
.. code-block:: bash
go get github.com/yuin/gluamapper
API
See Go doc <http://godoc.org/github.com/yuin/gluamapper>_ .
Usage
.. code-block:: go
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)
License
MIT
Author
Yusuke Inuzuka
Related Skills
node-connect
345.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
104.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
