c-for-go
c-for-go copied to clipboard
How to convert the union in struct?
Hi,
I'm trying to write a binding to FMOD which is an audio engine in games.
When building the generated go project, it given the message as following:
./cgo_helpers.go:6331: ref9919197a.floatdesc undefined (type *C.struct_FMOD_DSP_PARAMETER_DESC has no field or method floatdesc)
The interface defined as this:
typedef struct FMOD_DSP_PARAMETER_DESC
{
FMOD_DSP_PARAMETER_TYPE type; /* [w] Type of this parameter. */
char name[16]; /* [w] Name of the parameter to be displayed (ie "Cutoff frequency"). */
char label[16]; /* [w] Short string to be put next to value to denote the unit type (ie "hz"). */
const char *description; /* [w] Description of the parameter to be displayed as a help item / tooltip for this parameter. */
union
{
FMOD_DSP_PARAMETER_DESC_FLOAT floatdesc; /* [w] Struct containing information about the parameter in floating point format. Use when type is FMOD_DSP_PARAMETER_TYPE_FLOAT. */
FMOD_DSP_PARAMETER_DESC_INT intdesc; /* [w] Struct containing information about the parameter in integer format. Use when type is FMOD_DSP_PARAMETER_TYPE_INT. */
FMOD_DSP_PARAMETER_DESC_BOOL booldesc; /* [w] Struct containing information about the parameter in boolean format. Use when type is FMOD_DSP_PARAMETER_TYPE_BOOL. */
FMOD_DSP_PARAMETER_DESC_DATA datadesc; /* [w] Struct containing information about the parameter in data format. Use when type is FMOD_DSP_PARAMETER_TYPE_DATA. */
};
} FMOD_DSP_PARAMETER_DESC;
I want to know how to handle the problem. Please help.
@cznic are you sure Go is aware of this union at all? ;)
@xlab All I know is that the error looks to me like a fault of cc, perhaps because of the anonymous struct member. How it is/should be handled in higher layers is to be cleared later.
I hope to dive into this in the morning, that's in ~10 hours from now.
@xlab Finally looking into this and the error message seems to be not produced by cc.
Sorry for the noise.
@gengen1988 you'll have to make a wrapper in C for this union, if you want to access and set the data. That's a imitation from Go (cgo part).
You can simply ignore this struct or make it raw see MemTips https://github.com/xlab/c-for-go/wiki/Translator-config-section#memtips
This is my yaml:
---
GENERATOR:
PackageName: fmod
FlagGroups:
- {name: LDFLAGS, flags: ["-lfmod", "-L${SRCDIR}"]}
Includes:
- fmod.h
PARSER:
IncludePaths:
- fmod
SourcesPaths:
- fmod.h
TRANSLATOR:
ConstRules:
defines: eval
Rules:
global:
- {action: accept, from: ^FMOD_}
function:
type:
# - {action: ignore, from: FMOD_DSP_PARAMETER_DESC}
const:
- {action: ignore, from: ^FMOD_PRESET_}
private:
- {transform: unexport}
post-global:
# - {load: snakecase}
PtrTips:
function:
- {target: FMOD_System_Create, tips: [sref]}
MemTips:
# - {target: FMOD_DSP_PARAMETER_DESC, self: raw}
if add {action: ignore, from: FMOD_DSP_PARAMETER_DESC} then:
./cgo_helpers.go:9437: undefined: FMOD_DSP_PARAMETER_DESC
./cgo_helpers.go:9477: undefined: FMOD_DSP_PARAMETER_DESC
./cgo_helpers.go:9483: undefined: NewFMOD_DSP_PARAMETER_DESCRef
./fmod.go:3384: undefined: FMOD_DSP_PARAMETER_DESC
if I make it raw, then:
./cgo_helpers.go:9689: x[i0][i1].PassValue undefined (type FMOD_DSP_PARAMETER_DESC has no field or method PassValue)
Is there some example for "wrapper in C"?