luar.go
func LuaToGo(L *lua.State, idx int, a interface{}) error {
	// LuaToGo should not pop the Lua stack to be consistent with L.ToString(), etc.
	// It is also easier in practice when we want to keep working with the value on stack.

	v := reflect.ValueOf(a)
	// TODO: Test interfaces with methods.
	// TODO: Allow unreferenced map? encoding/json does not do it.
	if v.Kind() != reflect.Ptr {
		return errors.New("not a pointer")
	}
	if v.IsNil() {
		return errors.New("nil pointer")
	}

	v = v.Elem()
	// If the Lua value is 'nil' and the Go value is a pointer, nullify the pointer.
	if v.Kind() == reflect.Ptr && L.IsNil(idx) {
		v.Set(reflect.Zero(v.Type()))
		return nil
	}

	return luaToGo(L, idx, v, map[uintptr]reflect.Value{})
}
func LuaToGo(L *lua.State, idx int, a interface{}) error {
	// LuaToGo should not pop the Lua stack to be consistent with L.ToString(), etc.
	// It is also easier in practice when we want to keep working with the value on stack.

	v := reflect.ValueOf(a)
	// TODO: Test interfaces with methods.
	// TODO: Allow unreferenced map? encoding/json does not do it.
	if v.Kind() != reflect.Ptr {
		return errors.New("not a pointer")
	}
	if v.IsNil() {
		return errors.New("nil pointer")
	}

	v = v.Elem()
	// If the Lua value is 'nil' and the Go value is a pointer, nullify the pointer.
	if v.Kind() == reflect.Ptr && L.IsNil(idx) {
		v.Set(reflect.Zero(v.Type()))
		return nil
	}

	return luaToGo(L, idx, v, map[uintptr]reflect.Value{})
}
// LuaToGo converts the Lua value at index 'idx' to the Go value.
//
// The Go value must be a non-nil pointer.
//
// Conversions to strings and numbers are straightforward.
//
// Lua 'nil' is converted to the zero value of the specified Go value.
//
// If the Lua value is non-nil, pointers are dereferenced (multiple times if
// required) and the pointed value is the one that is set. If 'nil', then the Go
// pointer is set to 'nil'. To set a pointer's value to its zero value, use
// 'luar.null'.
//
// The Go value can be an interface, in which case the type is inferred. When
// converting a table to an interface, the Go value is a []interface{} slice if
// all its elements are indexed consecutively from 1, or a
// map[string]interface{} otherwise.
//
// Existing entries in maps and structs are kept. Arrays and slices are reset.
//
// Nil maps and slices are automatically allocated.
//
// Proxies are unwrapped to the Go value, if convertible. If both the proxy and
// the Go value are pointers, then the Go pointer will be set to the proxy
// pointer.
// Userdata that is not a proxy will be converted to a LuaObject if the Go value
// is an interface or a LuaObject.