Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewValue ¶
NewValue wraps the Lua value at the top of the stack (index -1) as a structlua.Value.
Example ¶
package main
import (
"fmt"
"log"
"github.com/Shopify/go-lua"
"github.com/tomgray/structlua"
"github.com/tomgray/structlua/golua"
)
func main() {
type ServerConfig struct {
Host string `lua:"host"`
Port int `lua:"port"`
TLS bool `lua:"tls"`
Allowed []string `lua:"allowed_hosts"`
}
l := lua.NewState()
lua.OpenLibraries(l)
script := `
return {
host = "0.0.0.0",
port = 8080,
tls = true,
allowed_hosts = { "example.com", "api.example.com" },
}
`
if err := lua.DoString(l, script); err != nil {
log.Fatal(err)
}
var cfg ServerConfig
if err := structlua.Unmarshal(golua.NewValue(l), &cfg); err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", cfg)
}
Output: {Host:0.0.0.0 Port:8080 TLS:true Allowed:[example.com api.example.com]}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.