RobLoach / node-raylib

Node.js bindings for Raylib
https://robloach.github.io/node-raylib/
Other
242 stars 20 forks source link

Typescript? #35

Open adenine-dev opened 5 years ago

adenine-dev commented 5 years ago

Not really an issue but are there any plans to migrate this to typescript? If not would you accept a pull request that did this?

RobLoach commented 5 years ago

Thanks, always looking for better ways to accomplish this. As long as TypeScript provides value, is easier to maintain and build upon, then it'd be worth investigation.

RobLoach commented 4 years ago

I've added the types definitions in the latest version. Would love some testing on it!

While adopting Typescript entirely will cause a bunch of duplicate code, we are still able to make using Typescript with it much easier. Here's a Typescript example! https://github.com/RobLoach/node-raylib/blob/master/templates/typescript_game/typescript_game.ts

Would love more thoughts on how it could improve. Thanks a lot!

insideone commented 3 years ago

The current definitions don't have structures nor they have arguments for most of the functions (InitWindow has 0 arguments which isn't right). To really use it with Typescript we need something like this:

type Color = {
    r: number,
    g: number,
    b: number,
    a: number,
};

export const BEIGE: Color;
export const BLACK: Color;
export const BLANK: Color;
// ...

export function InitWindow(width: number, height: number, title: string): void;

// ...

I saw that nbind offers automatically generated definitions:

Automatically generate TypeScript .d.ts definition files from C++ code for IDE autocompletion and compile-time checks of JavaScript side code

Is https://github.com/RobLoach/node-raylib/pull/13 still a goal?

Another idea: parse raylib.h (node-c-parser?) and generate d.ts file from it. I'm thinking of doing it.

RobLoach commented 3 years ago

Using nbind would be pretty cool... Oh, didn't know about node-c-parser. How far would it push it for us???