roc/examples/platform-switching
2022-09-09 01:12:30 -06:00
..
c-platform move C example 2022-08-31 14:05:43 -04:00
rust-platform Move Rust example 2022-08-31 13:21:53 -04:00
swift-platform move Swift example 2022-08-31 13:39:24 -04:00
web-assembly-platform Add angle brackets to bare URLs 2022-09-09 01:12:30 -06:00
zig-platform move Zig example 2022-08-31 14:09:34 -04:00
.gitignore Separate hello-world platform switching into its own example 2022-06-27 00:06:33 -06:00
main.roc Reword "web" example things to "web assembly" 2022-06-27 00:07:11 -06:00
README.md Ensure only one h1 per .md file 2022-09-07 23:27:18 -06:00
rocLovesC.roc move C example 2022-08-31 14:05:43 -04:00
rocLovesRust.roc Move Rust example 2022-08-31 13:21:53 -04:00
rocLovesSwift.roc move Swift example 2022-08-31 13:39:24 -04:00
rocLovesWebAssembly.roc move WebAssembly example 2022-08-31 14:20:25 -04:00
rocLovesZig.roc move Zig example 2022-08-31 14:09:34 -04:00

Platform switching

To run, cd into this directory and run this in your terminal:

roc run

This will run main.roc because, unless you explicitly give it a filename, roc run defaults to running a file named main.roc. Other roc commands (like roc build, roc test, and so on) also default to main.roc unless you explicitly give them a filename.

About this example

This uses a very simple platform which does nothing more than printing the string you give it.

The line main = "Which platform am I running on now?\n" sets this string to be "Which platform am I running on now?" with a newline at the end, and the lines packages { pf: "c-platform/main.roc" } and provides [main] to pf specify that the c-platform/ directory contains this app's platform.

This platform is called c-platform because its lower-level code is written in C. There's also a rust-platform, zig-platform, and so on; if you like, you can try switching pf: "c-platform/main.roc" to pf: "zig-platform/main.roc" or pf: "rust-platform/main.roc" to try one of those platforms instead. They all do similar things, so the application won't look any different.

If you want to start building your own platforms, these are some very simple example platforms to use as starting points.