Debian Codegraph @

README.md

raw
1 # gopher-luar [![GoDoc](https://godoc.org/layeh.com/gopher-luar?status.svg)](https://godoc.org/layeh.com/gopher-luar)
2
3 gopher-luar simplifies data passing to and from [gopher-lua](https://github.com/yuin/gopher-lua).
4
5 Example usage:
6
7 package luar_test
8
9 import (
10 "fmt"
11
12 "github.com/yuin/gopher-lua"
13 "layeh.com/gopher-luar"
14 )
15
16 type User struct {
17 Name string
18 token string
19 }
20
21 func (u *User) SetToken(t string) {
22 u.token = t
23 }
24
25 func (u *User) Token() string {
26 return u.token
27 }
28
29 const script = `
30 print("Hello from Lua, " .. u.Name .. "!")
31 u:SetToken("12345")
32 `
33
34 func Example_basic() {
35 L := lua.NewState()
36 defer L.Close()
37
38 u := &User{
39 Name: "Tim",
40 }
41 L.SetGlobal("u", luar.New(L, u))
42 if err := L.DoString(script); err != nil {
43 panic(err)
44 }
45
46 fmt.Println("Lua set your token to:", u.Token())
47 // Output:
48 // Hello from Lua, Tim!
49 // Lua set your token to: 12345
50 }
51
52 ## License
53
54 MPL 2.0
55
56 ## Author
57
58 Tim Cooper (<[email protected]>)