Skip to content
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

Automatically Build TypeScript Definitions from raylib_api.json #96

Open
twuky opened this issue Oct 23, 2021 · 1 comment
Open

Automatically Build TypeScript Definitions from raylib_api.json #96

twuky opened this issue Oct 23, 2021 · 1 comment

Comments

@twuky
Copy link
Collaborator

twuky commented Oct 23, 2021

In another issue I tried manually putting together some typescript definitions (with doc strings) from the old typescript branch, with some updates where i could fit them. Obviously manually generating definitions may not be ideal.

But recently I found the repo for raylib itself keeps a JSON file with type information on its structs, functions and enums. I thought I would try to parse that into a typescript definitions file.

Included in this gist is a script I wrote to pull the JSON definitions from the raylib repo and generate a typescript def file out of them. There are a few things I am unsure of about this process for generating bindings though:

  • It's not necessarily clear in the file what the intended use for different pointer variables/arguments should be. In JS we don't really care about pointers, but this may be important for properly recognizing which functions take arrays as arguments? This script makes the assumption that char * is a string, not a string[]. It didn't look like any raylib functions needed arrays of strings though. I'm not really a C user, so if someone could double check this logic that would be nice.
  • I believe this binding itself has a few wrapper functions to help creating data - things like Color(r,g,b,a) => Color. Is there somewhere documented in this repo where those functions could be brought into this generator? Or somewhere I could reference so that I could just manually add them each into this script (I imagine these wrapper functions won't change much, or new ones won't be implemented often)
  • The latest branch is raylib '4.0' which technically isn't released yet, so this isn't necessarily accurate to whats available to users of this npm package.

It seems like something like this could be used in the build/dist process, or to just create a @types/raylib repo seperately. This may be a better solution (at least at this moment) than relying on the binding library itself to generate definitions.

@RobLoach
Copy link
Owner

I'd love using that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants