Being reading a lot about betterC, but still have some questions
kiboshimo
matheusmvpeixoto at gmail.com
Wed Jul 10 01:48:54 UTC 2024
On Tuesday, 9 July 2024 at 20:24:14 UTC, H. S. Teoh wrote:
> What are you planning to run your wasm on? If in the browser,
> you could just use the browser's JS math functions. The
> performance won't be stellar (the wasm-JS boundary is SLOW),
> but it'd work and you wouldn't have to write your own math
> functions. This is what I use in my own D/wasm project. (It'd
> probably still beat any hand-written WASM reimplementation of
> math functions that you write. Remember, wasm is interpreted,
> so it won't beat the browser's built-in native math functions,
> which in all likelihood use the CPU's hardware math
> instructions.)
This cleared up some fundamental misunderstandings I had, thank
you. I want to use raylib and betterC to build a small game that
runs on the browser. For motivation I though Wasm had many
advantages over Js, but now I don't know if that is necessarily
the case.
> If you're planning to run your wasm in a native environment,
> you could probably just use the C API to interface with the
> host system's C library functions.
That covers native use-case. In the browser I can compile my
programs to .js using emscripten/dscripten or I can just use JS
API from WASM (but that is slow).
I though emscripten could target WASM directly, without
conversion to .js first. And, since it supports C, I'm assuming
they re-implemented C API to the OS on WASM, without the need for
calling JS API or WASI. (that might not serve me still, see
bellow)
I feel some fundamental misunderstanding remain, but now I have
more material to research on my own, so feel free to ignore this
if it is "too wrong".
- I though one could write an application with -betterC for WASM,
because LDC can target it, then could build it linking to C
libraries that already work on WASM and run the resulting build
on the browser. That would avoid the JS-WASM bondary since
everything would be WASM and I would not need to write my own
abstractions.
// I'm guessing one can't simply do that, and the toolchain that
compiles to WASM is not so flexible/similar to compiling a normal
binary. Maybe WASM does not have support for dynamic linking, for
example.
- Is WASI relevant to the browser context? Or just to native
apps? I though WASI API could be used on the browser, but
comments and blogs about it often bring up the native context
only.
I tried to reply everyone here, since I think most answers
converge. Thank you all for your help :)
More information about the Digitalmars-d-learn
mailing list