Am Montag, 12. Juni 2023, 10:50:46 CEST schrieb Francois Gallois: > Hello there, > I've been taking a look at the gforth bindings for Raylib at > https://github.com/ArnautDaniel/gforth-raylib in order to update them to the > latest version. One of the biggest problems the original authors has been > facing was converting the structures passed by value by raylib into > pointers to allow their use, such as : > > ``` > \c Vector2 * iGetWindowScaleDPI(Vector2 * p){ > \c Vector2 v = GetWindowScaleDPI(); > \c *p = v; return p; } > c-function iGetWindowScaleDPI iGetWindowScaleDPI a -- a ( emptyVector2 -- > Vector2 ) ``` > > It seems that the "default behavior" for SWIG is to convert structures > returned by value into pointers > (https://www.swig.org/Doc3.0/SWIGDocumentation.pdf#__WKANCHOR_58) (this is > the link to the docs of the relevant version of SWIG for > https://github.com/GeraldWodni/swig, which I've been using according to the > manual).
Gerald does not use the wrapper-generating part of Swig, because that's what libcc.fs does. > Has anyone played around enough with forth-SWIG to explain in more detail > how the current implementation behaves? I'd like to make that kind of fixes > automatic. Me, too. There should be enough information in the way Gerald uses Swig to tell that something is a struct, either as parameter or return value, and in that case emit struct{*(type*)} instead of a/n/r…, or whatever one-letter name we could come up with for convenience (t for tuple?). It's not difficult to add struct-support in libcc.fs, i.e. a struct in Forth is always passed as pointer, and if a function returns a struct, it's taking the next item from the stack as address to store the result. So the stack code really is ( return-pointer arg-pointer -- ). Structs as arguments are already dealt with by a{*(type*)} (the argument- generating code would be then identical for a, but with struct as name). There, the cast includes the pointer-accessing *, it's just structs as return are not yet supported by libcc.fs. -- Bernd Paysan "If you want it done right, you have to do it yourself" net2o id: kQusJzA;7*?t=uy@X}1GWr!+0qqp_Cn176t4(dQ* https://net2o.de/
signature.asc
Description: This is a digitally signed message part.