func ExampleGoToLua() { // The luar's Init function is only required for proxy use. L := lua.NewState() defer L.Close() L.OpenLibs() input := "Hello world!" luar.GoToLua(L, nil, reflect.ValueOf(input), true) L.SetGlobal("input") luar.GoToLua(L, nil, reflect.ValueOf(fmt.Println), true) L.SetGlobal("Print") L.DoString("Print(input)") // Output: // Hello world! }
// goToLua copies Go values to Lua and sets the result to global 'name'. // Compound types are deep-copied. // Functions are automatically converted to 'func (L *lua.State) int'. func goToLua(L *lua.State, name string, val interface{}) { t := reflect.TypeOf(val) if t.Kind() == reflect.Func { L.PushGoFunction(luar.GoLuaFunc(L, val)) } else { luar.GoToLua(L, t, reflect.ValueOf(val), true) } L.SetGlobal(name) }