[m-users.] Calling pass-by-value with C FFI with raylib

Peter Wang novalazy at gmail.com
Fri Jul 14 17:51:41 AEST 2023


On Fri, 14 Jul 2023 07:29:10 +0100 "Sean Charles (emacstheviking)" <objitsu at gmail.com> wrote:
> 
> The only real way I could find to model that in Mercury has been to literally
> re-invent the weel and create this union type and then some helpers:
> 
>     :- type p_color
>         --->    lightgray
>         ;       gray
>         ;       yellow
>         :
>         ;       raywhite. % FInal colour from header file palette
> 
>     :- type color
>         --->    rgb(uint8, uint8, uint8)
>         ;       rgba(uint8, uint8, uint8, uint8)
>         ;       c(p_color).

I expect you don't actually need color to be a Mercury d.u. type,
so you can define color as a uint32, and have predicates/functions
that convert between colors and color components.

Peter


More information about the users mailing list