gforth
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: etienne delacroix: Precisions on the forth SWIG architecture: return


From: Francois Gallois
Subject: Re: etienne delacroix: Precisions on the forth SWIG architecture: return by value structs
Date: Mon, 12 Jun 2023 20:10:55 +0200

On Mon, Jun 12, 2023 at 06:52:35PM +0200, etienne delacroix wrote:
> thanks for presenting this problem.   I have been very much wanting to use
> gforth to do graphics, but since my intel Mac got stolen I have problems
> installing the latest. gforth.  only. the.  0.7.3 is working on the M1
> 
> when I tried to include  the raylib3.fs. file   into. gforth 0.7.3. I got
> the following error:
> 
> raylib3.fs:567: Undefined word
> 
> c-function InitWindow InitWindow n n >>>s<<< -- void ( width height title
> -- )
> 
> Backtrace:
> 
> $15883DB80 throw
> 
> $15883DC18 parse-libcc-type
> 
> $158840E58 parse-function-types
> 
> $158841108 c-function-ft
> 
>   ok
> 
> 
> line 567. is the very first.  c-function. line...
> 
> so I tried
> see. c-function. which returns existing code
> 
> see c-function
> 
> : c-function
> 
>   Defer latestxt dup c-function-rt latestxt c-function-ft latestxt swap
> defer!
> 
>   ; ok
> 
> 
> 
> so I am not sure what the undefined word here
> 
> my question. is first of all to know if the arnault Daniel. gforth ray lib.
> is working with
> gforth. 0.7.3.  ????
> and if you have been able to   make this package work as it is....
> 
> merci d'avance
> 
> 
> On Mon, Jun 12, 2023 at 3:06 PM Francois Gallois <
> francois.gallois.pro@gmail.com> wrote:
> 
> > 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).
> >
> > 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.
> >
> > Separately, would there be a way to "typedef" some structures as stack
> > objects?
> > In the specific case of raylib but also as a common example, I would like
> > to
> > convert a Vector of 2 objects:
> >
> > ```
> > struct Vector2 {
> >   int x;
> >   int y;
> > };
> > ```
> >
> > into 2 stack objects, meaning that a function `foo` that takes a Vector2
> > (`int foo(Vector2 vec);`) can be called with `x y foo` in Forth,
> > and that calling a `Vector2 bar();` puts `x y` on the stack.
> > Could someone light my lantern on the things that could make that kind of
> > template possible?
> >
> > I'll be continuing to search on my side of things, but comments would be
> > much
> > appreciated.
> >
> > Thanks for your hard work, and have fun.
> >
> > ---
> > François Gallois
> > "All told, a category is just a monad in the bicategory of spans, what's
> > the
> > problem?"
> >
> >

My apologies for not adding those precisions. The bindings only work with the
latest version built from source (built on Fedora here), and when trying to do
your own bindings, you must use the swig version packed with the latest source.
I don't know what is the first version with which it will work, but you'll have
a simpler time if you just build from source.

I managed to make the binding work by building the Raylib 3.5.0 source on my
machine, and by copying the .h files in the directory of gforth-raylib. With all
of this, I managed to successfully run the binding, and to run the provided
example, though I didn't try any further experimentations. Stay aware that the
version you need to use is Raylib 3.5.0 (you can find the documentation in the
.h file). You can sure have fun with that, and I advise you to open an issue on
Github in case you have any further questions about the design of the binding;
the author was very responsive!

Bonne soirée

--
François Gallois
"All told, a category is just a monad in the bicategory of
spans, what's the problem?"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]