| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package main
- import (
- "github.com/yuin/gopher-lua"
- "fmt"
- )
- func Double(L *lua.LState) int {
- lv := L.ToInt(1) /* get argument */
- L.Push(lua.LNumber(lv * 2)) /* push result */
-
- L.G.Global.ForEach(func(key, value lua.LValue) {
- switch k := key.(type) {
- case lua.LString:
- fmt.Println("In GO:", k.String(), value.String())
- default:
- fmt.Println("other type")
- }})
-
- return 1 /* number of results */
- }
- func Commit(L *lua.LState) int{
- fmt.Println("commit!")
- return 0
- }
-
- func main() {
- L := lua.NewState()
- defer L.Close()
-
- /*
- prm := `
- t = {10, 20, 30}
- for _,element in pairs(t) do
- print(element)
- end
- `
- */
-
- L.SetGlobal("MX_APP", lua.LString("hello world"))
- L.SetGlobal("double", L.NewFunction(Double))
- L.SetGlobal("commit", L.NewFunction(Commit))
- prm := `
- --keyspace = aaa
- --class = xxx
- --queue = grok:MX_APP, MX_APP1, MX_APP2
- --match = MX_WINDOWS
- _app = MX_APP
- t = {10, 20, 30}
- for _,element in pairs(t) do
- print(element)
- end
-
- print(_app)
-
- mybiz = function(name)
- return "hello" .. name
- end
-
- _business = mybiz(MX_APP)
-
- print(_business)
-
- for n,v in pairs(_G) do
- print("G:",n,type(v))
- end
-
- print("GO Func :",double(55))
-
- commit()
- return 200
- `
-
- if err := L.DoString(prm); err != nil {
- panic(err)
- }
-
- ret := L.Get(-1) // returned top value
- L.Pop(1)
-
- fmt.Print("RTN from lua : " ,ret)
-
- //for n,v := range L.GetGlobal("double")
- }
|