The default currently is that a platform calls roc main (I forget the exported function name) and then roc calls the platform for memory and other functions.
Is it possible to export multiple roc functions? So you just have some core business logic in roc but the platform does the main loop and branching?
Also, can you implement custom platform data structures that roc can manipulate?
I would say yes and yes, but there are still caveats to both answers
Roc can export multiple functions by returning them in a struct. Then the platform can technically call directly into those functions without ever calling main.
The issue is that without calling main first, you may end up trying to call into a closure without the correct captured args.
So generally I would change the roc main function to be called init. Then call if to get closure related information, but that isn't strictly necessary in many cases
My example with SDL does this.
https://github.com/bhansconnect/roc-ecs
As for manipulation of host data structure. Roc has effects. As long as the host exposes and effect that does the manipulation, roc will be able to call it. Thus roc can do any manipulation the host could do.
we plan to make this smoother by generating the FFI code. It already works (really well) for anything but functions
Yea, so I can have a platform as a cli wrapper and the roc is just a "library" that it calls into? So roc library is easier to write complex and memory safe stuff for but it doesn't do cli parsing etc.
How can I test the FFI generation?
> target/debug/roc glue
error: The following required arguments were not provided:
<ROC_FILE>
<GLUE_FILE>
USAGE:
roc glue <ROC_FILE> <GLUE_FILE>
this only works for rust platforms (for now) actually
so glue file would be output.rs
or something
and the roc file is the platform's main.roc I believe
Ok, thanks!
Last updated: Jul 06 2025 at 12:14 UTC