datautils

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CastBool

func CastBool(value bool) (cast int)

func ConvertCTypes

func ConvertCTypes[RET, SRC any](src SRC) RET

ConvertCTypes intendedd use is to convert packageA.C.MyType to packageB.C.MyType. make sure your types are identical C types before using it. THIS IS HIGHLY UNSAFE AND NOT RECOMMENDED TO USE OUTSIDE CIMGUI. It just forces pointer/type reinterpretation with unsafe.Pointer.

func Ptr

func Ptr(data interface{}) unsafe.Pointer

Ptr takes a slice or pointer (to a singular scalar value or the first element of an array or slice) and returns its GL-compatible address.

For example:

var data []uint8
...
gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))

func PtrToByteSlice

func PtrToByteSlice(p unsafe.Pointer) []byte

func PtrToUint16Slice

func PtrToUint16Slice(p unsafe.Pointer) []uint16

func Wrap

func Wrap[CTYPE any, self any](in WrappableType[CTYPE, self]) (cPtr *CTYPE, finisher func())

Wrap takes a variable of one of the types defined in this file and returns a pointer to its C equivalend as well as a "finisher" func. This finisher func should be called after doing any operations on C pointer in order to apply the changes back to the original GO variable.

func WrapBool

func WrapBool[RESULT ~bool](goValue *bool) (wrapped *RESULT, finisher func())

WrapBool converts a Go bool pointer to a C bool pointer. Default value of RESULT should be C.bool

func WrapNumberPtr

func WrapNumberPtr[CTYPE Number, GOTYPE Number](goValue *GOTYPE) (wrapped *CTYPE, finisher func())

WrapNumberPtr is a generic method to convert GOTYPE (int32/float32 e.t.c.) into CTYPE (c_int/c_float e.t.c.)

func WrapString

func WrapString[RET ~int8](value string) (wrapped *RET, finisher func())

WrapString converts Go string to C char* Default value of RET is C.char

func WrapStringList

func WrapStringList[RET ~int8](value []string) (wrapped **RET, finisher func())

WrapStringList converts Go string slice to C char** Default value of RET is C.char

func WrapVoidPtr

func WrapVoidPtr(value unsafe.Pointer) (wrapped unsafe.Pointer, finisher func())

WrapVoidPtr uses runtime.Pinner to pin value

Types

type Number

type Number interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64
}

Number is a generic type for Go/C types that can be used as a number. It could be anything that you can convert to that type (e.g. C.int is a Number, because it can be directly converted to int)

type StringBuffer

type StringBuffer struct {
	// contains filtered or unexported fields
}

func NewStringBuffer

func NewStringBuffer(initialValue string) *StringBuffer

func (*StringBuffer) Free

func (buf *StringBuffer) Free()

func (*StringBuffer) Ptr

func (buf *StringBuffer) Ptr() unsafe.Pointer

func (*StringBuffer) ResizeTo

func (buf *StringBuffer) ResizeTo(requestedSize int)

func (*StringBuffer) Size

func (buf *StringBuffer) Size() int

func (*StringBuffer) ToGo

func (buf *StringBuffer) ToGo() string

type Vector

type Vector[T any] struct {
	Size     int
	Capacity int
	Data     T
	// contains filtered or unexported fields
}

func NewVectorFromC

func NewVectorFromC[T any, CINT ~int32](size, capacity CINT, data T) Vector[T]

func (*Vector[T]) Pinner

func (v *Vector[T]) Pinner() *runtime.Pinner

type WrappableType

type WrappableType[CTYPE any, self any] interface {
	// ToC converts self into CTYPE
	ToC() CTYPE
	// FromC force-converts taken any to CTYPE, converts it into self,
	// applies to receiver and returns it.
	FromC(unsafe.Pointer) self
}

WrappableType represents a GO type that can be converted into a C value and back - into a GO value. CTYPE represents the equivalent C type of self. self is the type WrappableType applies to - TODO - figure out if it can be ommited :-) intentional values: - CTYPE is e.g. C.ImVec2, C.ImColor e.t.c. - self is a pointer type (e.g. *Vec2, Color)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL