josephg / Chipmunk-js

Port of slembcke/Chipmunk-Physics to Javascript
http://dl.dropbox.com/u/2494815/demo/Joints.html
536 stars 59 forks source link

Typescript Type Definitions? #25

Open lihaoyi opened 10 years ago

lihaoyi commented 10 years ago

These would not only let Typescript users use chipmunk-js conveniently, it'd also let some other languages like F# and Scala (which I'm using) interop more conveniently. Given that chipmunk-js follows the C library pretty closely, it should be pretty straightforward (if tedious) to mark out the type signatures for the various functions and methods.

josephg commented 10 years ago

I considered doing this recently hoping that typescript would be able to generate asmjs-style javascript to make chipmunk go faster, but as far as I can't.

Does typescript use google closure-style /** @param (String) foo ... */ comment-based type annotations or does it do something else?

lihaoyi commented 10 years ago

It uses it's own syntax/format; there's a whole bunch of typescript type defs for existing JS libraries here:

https://github.com/borisyankov/DefinitelyTyped

if you want to take a look.

Typescript does not generate asm-js style javascript, so there's no speed advantage. Only cleanliness/ease-of-use (which is non trivial). The typescript definitions can be kept separately from the javascript code, so you can keep running the original on normal js engines and only pull in the typedefs (*.d.ts files) if you want to compile it with typescript.

My feeling is that it's simple enough to write the type declarations manually. I've basically written Scala.Js type signatures for almost the bulk of chipmunk's external API, and it's somewhere around 150 lines of code. Granted it's not a complete signature for the public interface, but even so I don't expect it to be more than ~250 lines of code to totally spec out every method/variable/struct in the public interface of the library. It'll also be great to use typescript over Scala for the canonical typedefs, since then Scala.Js/Funscript/others can parse those and code-gen bindings in their own language.

On Mon, Nov 4, 2013 at 2:31 PM, Joseph Gentle notifications@github.comwrote:

I considered doing this recently hoping that typescript would be able to generate asmjs-style javascript to make chipmunk go faster, but as far as I can't.

Does typescript use google closure-style /* @param (String) foo ... /comment-based type annotations or does it do something else?

— Reply to this email directly or view it on GitHubhttps://github.com/josephg/Chipmunk-js/issues/25#issuecomment-27729518 .

josephg commented 10 years ago

Cool. I'd be happy to throw it somewhere in the chipmunk-js source tree if you're keen. Are there tools for dealing with that on macos, or is it just a microsoft thing?

lihaoyi commented 10 years ago

I think the compiler runs on node.js, so it should work on macos just fine. I'll spend some time and see if I can put something together

On Mon, Nov 4, 2013 at 3:49 PM, Joseph Gentle notifications@github.comwrote:

Cool. I'd be happy to throw it somewhere in the chipmunk-js source tree if you're keen. Are there tools for dealing with that on macos, or is it just a microsoft thing?

— Reply to this email directly or view it on GitHubhttps://github.com/josephg/Chipmunk-js/issues/25#issuecomment-27735058 .