Exemple #1
1
func luaU_FetchPointer(l Lua_State, v *reflect.Value) (ok bool) {
	if ok = Lua_isthread(l, -1); ok {
		v.SetPointer(unsafe.Pointer(Lua_tothread(l, -1)))
	}
	Lua_pop(l, 1)
	return
}
Exemple #2
0
func setRetValue(v reflect.Value, p unsafe.Pointer) {
	if !v.IsValid() {
		return
	}

	switch v = v.Elem(); v.Kind() {
	case reflect.Int:
		v.SetInt(int64(*((*C.int)(p))))

	case reflect.Int8:
		v.SetInt(int64(*(*C.int8_t)(p)))

	case reflect.Int16:
		v.SetInt(int64(*(*C.int16_t)(p)))

	case reflect.Int32:
		v.SetInt(int64(*(*C.int32_t)(p)))

	case reflect.Int64:
		v.SetInt(int64(*(*C.int64_t)(p)))

	case reflect.Uint:
		v.SetUint(uint64(*((*C.uint)(p))))

	case reflect.Uint8:
		v.SetUint(uint64(*(*C.uint8_t)(p)))

	case reflect.Uint16:
		v.SetUint(uint64(*(*C.uint16_t)(p)))

	case reflect.Uint32:
		v.SetUint(uint64(*(*C.uint32_t)(p)))

	case reflect.Uint64:
		v.SetUint(uint64(*(*C.uint64_t)(p)))

	case reflect.Uintptr:
		v.SetUint(uint64(*(*C.size_t)(p)))

	case reflect.Float32:
		v.SetFloat(float64(*(*C.float)(p)))

	case reflect.Float64:
		v.SetFloat(float64(*(*C.double)(p)))

	case reflect.String:
		v.SetString(C.GoString(*(**C.char)(p)))

	case reflect.UnsafePointer:
		v.SetPointer(*(*unsafe.Pointer)(p))
	}
}