Outputting the members types of a structure in the interface C file

Francois Gallois <[email protected]> Sun, 18 Jun 2023 17:52:55 +0200
Newsgroups gmane.comp.programming.swig
Message-ID <kidq7lmjbgcerpgsvhuxxixx7vzfeaxmwtcbnfdfve4hqbhn3o@2ytv5ryf7kv6>
Sorry in advance if this kind of question was answered already; I have no idea
for which feature to reach or what to search for in this mailing list.

I want to make an update to the swig 3.0.9 extension for Forth (https://github.com/forthy42/swig/)
(gforth in particular); it uses Swig only to output C files we then compile to
produce Forth interface files that look like this :

```
\ ------===< functions >===-------
c-function vkCreateInstance vkCreateInstance a a a -- n	( pCreateInfo pAllocator pInstance -- )
c-function vkDestroyInstance vkDestroyInstance a a -- void	( instance pAllocator -- )
c-function vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices a a a -- n	( instance pPhysicalDeviceCount pPhysicalDevices -- )
```

We use Swig to map the types in the C program to normalized identifiers for our
libcc.fs file (https://github.com/forthy42/gforth/blob/master/libcc.fs)
(in the example above, it transforms pointers into "a" and ints into "n").

As usual (?) in Swig, most structures are made into pointers before being passed
to and from C functions (devs recently added a way to do so for structures
returned by value). But my goal is to bind Raylib, which like many game
libraries tries to remove memory management by returning simple structures (such
as vectors of 2 or 3 coordinates) by value.

For this, I need to be able to output things of the form "c(*{ n n *})"
for structures with 2 ints. Would there be a practical way of converting types
to this kind of string depending on their inner members?

Thanks for your hard work,
François Gallois