Skip to content

Commit

Permalink
Merge pull request #321 from gucio321/add-some-types-support
Browse files Browse the repository at this point in the history
Add some more types support
  • Loading branch information
gucio321 authored Sep 24, 2024
2 parents c4b0409 + 8d7c8eb commit 17bd63c
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 6 deletions.
7 changes: 7 additions & 0 deletions cmd/codegen/arguments_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func getArgWrapper(
"unsigned char*": simplePtrW("uint", "C.uchar"),
"unsigned char**": uCharPtrW,
"size_t": simpleW("uint64", "C.xulong"),
"time_t": simpleW("uint64", "C.xulong"),
"size_t*": sizeTPtrW,
"float": simpleW("float32", "C.float"),
"const float": simpleW("float32", "C.float"),
Expand Down Expand Up @@ -74,6 +75,7 @@ func getArgWrapper(
"const ImS16*": simplePtrSliceW("C.ImS16", "int"),
"ImS32": simpleW("int", "C.ImS32"),
"ImS32*": simplePtrW("int32", "C.ImS32"),
"int32_t": simpleW("int32", "C.int32_t"),
"const ImS32*": simplePtrSliceW("C.ImS32", "int32"),
"ImS64": simpleW("int64", "C.ImS64"),
"ImS64*": simplePtrW("int64", "C.ImS64"),
Expand All @@ -89,6 +91,7 @@ func getArgWrapper(
"bool": simpleW("bool", "C.bool"),
"const bool": simpleW("bool", "C.bool"),
"bool*": boolPtrW,
"const bool*": boolPtrW,
"ImWchar": simpleW(prefixGoPackage("Wchar", "imgui", context), "C.ImWchar"),
"ImWchar*": simpleW("("+prefixGoPackage("*Wchar", "imgui", context)+")", "(*C.ImWchar)"),
"const ImWchar*": simpleW("("+prefixGoPackage("*Wchar", "imgui", context)+")", "(*C.ImWchar)"),
Expand Down Expand Up @@ -117,6 +120,10 @@ func getArgWrapper(
"const ImPlotTime": wrappableW(prefixGoPackage("PlotTime", "implot", context), "C.ImPlotTime"),
"ImPlotTime*": wrappablePtrW(prefixGoPackage("*PlotTime", "implot", context), "C.ImPlotTime"),
"const ImPlotTime*": wrappablePtrW(prefixGoPackage("*PlotTime", "implot", context), "C.ImPlotTime"),
"tm": wrappableW(prefixGoPackage("Tm", "implot", context), "C.struct_tm"),
"const tm": wrappableW(prefixGoPackage("Tm", "implot", context), "C.struct_tm"),
"tm*": wrappablePtrW(prefixGoPackage("*Tm", "imgui", context), "C.struct_tm"),
"const tm*": wrappablePtrW(prefixGoPackage("*Tm", "imgui", context), "C.struct_tm"),
}

if a.Name == "type" || a.Name == "range" {
Expand Down
12 changes: 10 additions & 2 deletions cmd/codegen/return_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func getReturnWrapper(
) (returnWrapper, error) {
returnWrapperMap := map[CIdentifier]returnWrapper{
"bool": {"bool", "%s == C.bool(true)"},
"bool*": simplePtrR("bool"),
"const bool*": simplePtrR("bool"),
"char": simpleR("rune"),
"unsigned char": simpleR("uint"),
"unsigned char*": {"*uint", "(*uint)(unsafe.Pointer(%s))"}, // NOTE: This should work but I'm not 100% sure
Expand All @@ -34,6 +36,7 @@ func getReturnWrapper(
"double": simpleR("float64"),
"double*": simplePtrR("float64"),
"int": simpleR("int32"),
"int32_t": simpleR("int32"),
"int*": simplePtrR("int32"),
"unsigned int": simpleR("uint32"),
"unsigned int*": simplePtrR("uint32"),
Expand All @@ -52,6 +55,7 @@ func getReturnWrapper(
"ImU16*": simplePtrR("uint16"),
"ImU32": simpleR("uint32"),
"ImU32*": simplePtrR("uint32"),
"const ImU32*": simplePtrR("uint32"),
"ImU64": simpleR("uint64"),
"ImU64*": simplePtrR("uint64"),
"ImVec4": wrappableR(prefixGoPackage("Vec4", "imgui", context)),
Expand All @@ -61,8 +65,11 @@ func getReturnWrapper(
"ImPlotPoint": wrappableR(prefixGoPackage("PlotPoint", "implot", context)),
"ImRect": wrappableR(prefixGoPackage("Rect", "imgui", context)),
"ImPlotTime": wrappableR(prefixGoPackage("PlotTime", "implot", context)),
"tm": wrappableR(prefixGoPackage("Tm", "implot", context)),
"const tm": wrappableR(prefixGoPackage("Tm", "implot", context)),
"uintptr_t": simpleR("uintptr"),
"size_t": simpleR("uint64"),
"time_t": simpleR("uint64"),
}

pureType := TrimPrefix(TrimSuffix(t, "*"), "const ")
Expand All @@ -71,7 +78,7 @@ func getReturnWrapper(
_, isRefTypedef := context.refTypedefs[pureType]
_, shouldSkipRefTypedef := skippedTypedefs[pureType]
_, isStruct := context.structNames[pureType]
isStruct = isStruct || (isRefStruct && !shouldSkipRefTypedef)
isStruct = isStruct || ((isRefStruct || (isRefTypedef && !isEnum(pureType, context.refEnumNames))) && !shouldSkipRefTypedef)
w, known := returnWrapperMap[t]
// check if is array (match regex)
isArray, err := regexp.Match(".*\\[\\d+\\]", []byte(t))
Expand All @@ -87,7 +94,8 @@ func getReturnWrapper(
switch {
case known:
return w, nil
case (context.structNames[t] || context.refStructNames[t]) && !shouldSkipStruct(t):
// case (context.structNames[t] || context.refStructNames[t]) && !shouldSkipStruct(t):
case !HasSuffix(t, "*") && isStruct && !shouldSkipStruct(pureType):
return returnWrapper{
returnType: prefixGoPackage(t.renameGoIdentifier(), srcPackage, context),
// this is a small trick as using prefixGoPackage isn't in fact intended to be used in such a way, but it should treat the whole string as a "type" and prefix it correctly
Expand Down
24 changes: 24 additions & 0 deletions imgui/cimgui_funcs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions immarkdown/cimmarkdown_funcs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions imnodes/cimnodes_funcs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 17bd63c

Please sign in to comment.