-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Partial Libc #51
base: main
Are you sure you want to change the base?
Partial Libc #51
Conversation
… (fenv.h, math.h, stdlib.h, string.h, time.h, stdio.h(parts))
…ry stream related fn
Are you looking to re-implement a bunch of the standard C library to make porting legacy code easier? raylib does provide some helpful libraries around using a bunch of these directly, like |
Yes, implementing parts of the standard C library to make porting code easier, but also to just allow its use, is the goal. Many functions such as |
Taking this approach does break the pattern introduced, where the WASM calls the target methods. Implementing a subset of these methods in JavaScript will keep the WASM compilation process minimal, but perhaps that's not your goal. If you're porting an existing legacy app over to the web, it's likely easier to use emscsripten via https://github.com/raysan5/raylib/wiki/Working-for-Web-(HTML5)
Remember that this is not raylib 😉 It's a reimplementation of the raylib API that makes WASM call JavaScript functions. |
The description does not contain, that every method has to be implemented in JS. Tsoding himself has mentioned a few times, that it is not necessary to implement every function in JS if we manage to implement all base functions. Example. I know it is not raylib, but who said we can't use code from raylib. If we can get parts of the source to compile, by implementing everything it needs in JS, it would make it a lot easier for us. |
libc
Parts added
math.h (fenv.h)
Added support for all functions except lgamma and tgamma.
Also function for long double just use the double variant, as js has no support for long double. This is within c spec.
stdlib
Added a very basic allocator, that allocates a specifiable number of blocks per js memory page.
The blocks are then combined or separated to form continuous memory of different sizes.
string.h
Complete implementation in c, so no JS is needed for it
time.h
Used UTC and Local time of JS to implement the functions.
stdio.h
This one is only partially implemented and is, for example, missing implementations for the scanf family and only supports the 'rb' mode for opening files on the server. Also no stdin support.
Could look into supporting this better with async.
I am still including it because the printf family support is important.
Examples
Added some basic examples with functions from the lib.
For example, displaying the local time, and calculating the result of cos/sin.
Correctness
Please use this knowing that it is not completely C-compliant and also in no way bug-free.
I hope we can all test it thoroughly and report bugs or even fix them.