Esempio n. 1
0
func makeValueProxy(L *lua.State, val reflect.Value, proxyMT string) {
	rawptr := L.NewUserdata(uintptr(unsafe.Sizeof(ValueProxy{})))
	ptr := (*ValueProxy)(rawptr)
	ptr.value = val
	ptr.t = val.Type()
	lua.LGetMetaTable(L, proxyMT)
	L.SetMetaTable(-2)
}
func main() {
	var L *lua.State
	L = lua.NewState()
	L.OpenLibs()

	rawptr := L.NewUserdata(uintptr(unsafe.Sizeof(Userdata{})))
	var ptr *Userdata
	ptr = (*Userdata)(rawptr)
	ptr.a = 2
	ptr.b = 3

	fmt.Println(ptr)

	rawptr2 := L.ToUserdata(-1)
	ptr2 := (*Userdata)(rawptr2)

	fmt.Println(ptr2)
}