Playing with CRUNCH, literally
John Croisant via Chicken-users <[email protected]>
| Newsgroups | gmane.lisp.scheme.chicken |
|---|---|
| Message-ID | <[email protected]> |
Hi all, I have been experimenting with CRUNCH, and it is exciting! It has great potential for game dev, because of its performance and easy deployment. PC, mobile devices, game consoles... even web browsers! I have written an SDL3 demo that can run natively and in a browser, using CRUNCH and emscripten to compile Scheme to C to WASM. I could never get that working with CHICKEN, but it was trivial with CRUNCH. This makes it super easy to deploy games for game jams, etc. You can see the demo running in your browser: https://croisant.net/projects/crunch-sdl3-demo/demo.html And get the annotated source code, with build instructions: https://croisant.net/projects/crunch-sdl3-demo/demo.scm I plan to develop CRUNCH bindings to SDL3 and several other game libraries. I have already been working on CHICKEN bindings to those libraries, which I still plan to finish, because CHICKEN offers some advantages like interactive coding and debugging. The goal would be for the APIs to be compatible as much as possible, so people can develop using CHICKEN then deploy using CRUNCH, with minimal porting. I do have a small-ish feature request for CRUNCH, which would enable me to share code across CHICKEN and CRUNCH, instead of needing to maintain separate codebases. That is the ability to define type aliases, as with CHICKEN's define-type or define-foreign-type. In CHICKEN, I wrap struct pointers in records, for type checking and safety. In CRUNCH, I just use bare struct pointers, because CRUNCH and the C compiler both do type checking already. So I could conditionally define corresponding type aliases like this: (cond-expand (crunched (define-type SDL_Window* (pointer (typename SDL_Window)))) (else (define-type SDL_Window* (struct window)) (define-foreign-type SDL_Window* (c-pointer "SDL_Window") unwrap-window wrap-window))) After that it's just a matter of adjusting my helper macros to conditionally expand to c-external instead of foreign-lambda, c-value instead of foreign-value, etc. And voila, 80% of my existing code suddenly works in CRUNCH, verbatim or with only minor tweaks. I have a wishlist of other small CRUNCH features that would make FFI easier in CRUNCH, but type aliases would be... a game changer. B-) If there is anything I can do to help make this a reality, I'm happy to lend a hand! - John Croisant