Hi,
I'm still trying to wrap my mind around writing platforms. One thing I really want to do is to require the roc main to not just return String, but, say, MyType : { x: U8, y: U8 }
. As a rust beginner I was a bit blown away by the rust platform example, so I'm sticking to the c-platform for now. Naively I would want to just make a struct struct MyStruct { int x; int y }
. Then change the mainForHost line a bit:
extern void roc__mainForHost_1_exposed_generic(struct MyStruct *string);
and then write in the main
struct MyCType r;
roc__mainForHost_1_exposed_generic(&r);
int x = r.x;
int y = r.y;
int sum = x + y;
printf("%d + %d = %d\n", x, y, sum);
However this seems to be a bit too naive as it does not work :D Could someone maybe explain to me the basics of how to transport such data from roc?
Most of the complexity here comes from Tasks. Without tasks, most of it is pretty direct like that.
Have you just modified platform switching C?
oh, though you are returning U8
, which isn't int
it is uint8_t
or unsigned char
This commit works for me to do what you asked: https://github.com/roc-lang/roc/commit/26d69bada770f40fded8b111a0f51be6882e8602
You are right, I changed int to uint8_t in the c code and it works as expected now. So I wasn't that far off :D Thanks for the quick answer!
Hannes has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC