node-raylib icon indicating copy to clipboard operation
node-raylib copied to clipboard

Typescript?

Open adenine-dev opened this issue 6 years ago • 4 comments

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?

adenine-dev avatar Jul 17 '19 19:07 adenine-dev

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 avatar Jul 17 '19 20:07 RobLoach

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!

RobLoach avatar Apr 06 '20 15:04 RobLoach

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.

insideone avatar Apr 18 '21 21:04 insideone

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

RobLoach avatar Apr 19 '21 15:04 RobLoach