Recent Three.js externs ?

607 views
Skip to first unread message

Malek

unread,
Feb 19, 2014, 3:31:23 PM2/19/14
to haxe...@googlegroups.com
Hi,

I'm looking for up to date Haxe externs of Three.js.

So far I found those:
https://github.com/jgranick/three.js-completion (by Joshua Granick, but not updated since 2011)
https://github.com/labe-me (by a former Motion Twin guy, but not really updated since April 2013)

Couldn't find more recent unfortunately. This can be annoying because unlike with Flash, there can be no --gen-hx-classes to generate externs automatically since JavaScript is not strongly typed to begin with.

So, what about taking advantage of the huge library of TypeScript externs on DefinitelyTyped ? These three.js externs are recent, and type information is all there.

One would just need to write a tool to translate a .d.ts file into .hx.

So did someone do it already by any chance ? :)

da...@postite.com

unread,
Feb 19, 2014, 5:15:05 PM2/19/14
to haxe...@googlegroups.com

https://github.com/Simn/ts2hx
Or
https://github.com/aduros/dts2haxe

I tested both .they make a pretty good job.
Ts2hx is pure haxe and require less dependency than dts2haxe.

Your choice

Simon Krajewski

unread,
Feb 19, 2014, 6:42:36 PM2/19/14
to haxe...@googlegroups.com
While we're on the subject, I'm looking for someone to maintain ts2hx. I
wrote it mainly because everyone said it's a great idea and also because
I wanted to test hxparse some more, but I don't use/know Typescript at all.

Simon

Malek

unread,
Feb 19, 2014, 8:28:57 PM2/19/14
to haxe...@googlegroups.com
Yay, thanks !

That was a pretty good idea indeed. Unfortunately I'm way too short on money to be able to spend time on a new hobby project, but I'll be sure to mention it whenever the topic rolls in :)

Anyway, do you remember which features are supported in ts2hx ? Trying to compare with dts2haxe which says:

What works

  • Classes.
  • Interfaces (mapped to Haxe typedefs).
  • Enums.
  • Global variables and functions (placed as statics in a generated "Globals" class).
  • Array types.
  • Anonymous types.
  • Varargs methods.
  • Nested modules.
  • Escaping Haxe keywords.

What doesn't work yet

  • Generics.
  • Method overloading.
  • Certain weird JS patterns that don't map well to Haxe.
  • Splitting generated Haxe into multiple .hx files.
  • Importing external type dependencies. Converting HTML dependencies to js.html.*.
  • Allowing quoted strings for identifiers.

Simon Krajewski

unread,
Feb 20, 2014, 3:08:29 AM2/20/14
to haxe...@googlegroups.com
I tested it with DefinitelyTyped where it parsed and converted the entire thing. You can check https://github.com/Simn/ts2hx/blob/master/src/tshx/Converter.hx for // TODO comments which hint at limitations. Most of these simply don't map to Haxe.

One problem with the generated Haxe code might actually be a limitation of Haxe itself: https://github.com/HaxeFoundation/haxe/issues/2563 This could be fixed by generating one .hx file per type, but that would be a lot of files.

In general, ts2hx works by parsing typescript into some simplified AST, then converting it to Haxe AST (the definitions from Expr.hx) and using the expression printer for output. This means you don't have to deal with strings at all.

Simon

Laurent Bedubourg

unread,
Feb 20, 2014, 6:34:03 AM2/20/14
to haxe...@googlegroups.com
Hello,

The former Motion Twin guy says that the externs are not "that" outdated, thank to John Croisant we got a clean .57 last year.

It is the version advertised by the README but under the blanket three.js .65 is provided by the library.

If you find some missing externs or some changes in the API please fork and make a pull request.

I still use the externs for some quick prototypes but since I don't need bleeding edge features I welcome any help to update three.js externs !

Maybe better than using some manually created .ts file, it would be better to parse official three.js documentation to extract the information. You could even get in touch with dr doob to help him create a more parseable documentation/code!

Regards
Laurent



--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.



--
Laurent Bédubourg
lau...@labe.me
http://labe.me

Boyan O

unread,
Feb 22, 2014, 2:10:23 PM2/22/14
to haxe...@googlegroups.com
I pushed latest r65 js scripts, but almost didn't changed much externs code, so externs should be close to r57. It worked fine for my experiments.

There are should be some externs generators, maybe something like this might work:

Anyway, you know it's not really easy to get static types from dynamically typed JS.

Or writing a parser for TS could do the job.

I think when someone uses Three.js externs, they could easily keep it up to date. So externs is getting better and up to date when people use it and create pull requests to merge changes together, not just keep it local, this is just my imho.

четверг, 20 февраля 2014 г., 13:34:03 UTC+2 пользователь Laurent Bedubourg написал:

Malek

unread,
Mar 4, 2014, 9:28:49 PM3/4/14
to haxe...@googlegroups.com
Sorry for the delay. I finally found some time to dig into moving my TypeScript development back to Haxe, and it looks like I'll be able to do without DefinitelyTyped as long as I can get Simon's tool to work :)

The code is too low level for me so I definitely won't be able to contribute >_<
Worse, I can't even get it to work output anything but an empty folder and some errors :D

Simon, I don't know if it's a bug you introduced in your updates to hxargs and hxparse from March 1st, or if it's me being dumb, but here's what's up:

- I downloaded both dependencies directly from your Github (not Haxelib, to get latest updates), and installed them locally
- I compiled ts2hx without modifying anything from the project provided on your Github
- Haxe 3.0.1 complains, so I used Haxe 3.1 (Windows ZIP version)
- I added Haxe 3.0.1 haxelib.exe into Haxe 3.1 folder since at the time of posting, it is missing from the ZIP
- Compile is a success
- I run neko 2.0 from command line in a folder that has ts2hx.n and three.d.ts, with the command
neko ts2hx.n three.d.ts

Here's the error I get:
Called from ? line 1
Called from Main.hx line 60
Called from Main.hx line 120
Called from Main.hx line 110
Called from Main.hx line 70
Uncaught exception - three:lines 1-2: NoMatch TEllipsis

I tried to understand what's up but that kind of code goes way over my head. ;_;
Maybe I'm doing something stupid with the neko commands though, in which case it is pathetic and I'm sorry :D

Malek

unread,
Mar 6, 2014, 3:35:05 AM3/6/14
to haxe...@googlegroups.com
So the Haxe 3.1 ZIP has been fixed and hxargs has had an update.

That drove my hopes up, unfortunately a newly compiled ts2hx.n produces the same error >_<.
I can't move use HaxeJS without my beloved DefinitelyTyped ;)

I'm using Neko 2.0.0 from nekovm.org in case it matters (another thread says there might be an updated Neko bundled with Haxe 3.1)

I don't get the "NoMatch TEllipsis" exception: There's no ellipsis "..." in the d.ts files I'm feeding to ts2hx. Hhhrrrmmmm.

Malek

unread,
Mar 6, 2014, 4:59:09 PM3/6/14
to haxe...@googlegroups.com
For anyone trying to use ts2hx: It works when you use hxparse from February 20th, although comments won't be copied to the externs. (whether /**/ or //. The parser class seems to care at least about /**/ comments, but fails to copy them)

ts2hx seems very good so far :)

It only erroneously put Mr. Doob's stats.js in toplevel.hx instead of in its own file.

Boyan O

unread,
Mar 10, 2014, 9:55:16 AM3/10/14
to haxe...@googlegroups.com
I wonder if would hxtern for it
https://github.com/jdonaldson/hxtern

четверг, 6 марта 2014 г., 23:59:09 UTC+2 пользователь Malek написал:

Justin Donaldson

unread,
Mar 11, 2014, 9:28:54 PM3/11/14
to Haxe
hxtern is designed to be generated automatically, so there's actually *no* manually written externs in the hxtern repo.  The externs are generated via a jsdoc plugin called jsdoc-hxtern: https://github.com/jdonaldson/jsdoc3-hxtern
This process lets me make large numbers of changes that I couldn't hope to do with manual edits:
https://github.com/jdonaldson/hxtern/commit/2f58700d8126d280e927f80c38ace2bd66a8d6bb#diff-1380

The plugin only works on libraries with "classic" or "closure-compiler" jsdoc documentation.  Unfortunately, the author of three.js has stated on several occasions that he doesn't want to add jsdoc markup to the library. 
https://github.com/h5bp/lazyweb-requests/issues/17
https://github.com/mrdoob/three.js/issues/76
I can still run the plugin on the library, but all of the arguments will come out as Dynamic, which isn't that helpful.

FWIW, hxtern has come a long way, but it's still not quite where I want it to be yet.  I'm running the jsdoc-hxtern plugin against the externs in the closure compiler source:
https://code.google.com/p/closure-compiler/source/browse/#git%2Fcontrib%2Fexterns

Once I get all of those working, with basic sanity-check tests, I'll dress the docs and examples up a bit and make another announcement.




--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Haxiomic

unread,
Oct 18, 2014, 11:18:04 PM10/18/14
to haxe...@googlegroups.com
I've just tried using ts2hx to generate externs for r68, it took some tweaking but here's the result

https://gist.github.com/haxiomic/461b2ca498c0282d121b

Yaroslav Sivakov

unread,
Oct 19, 2014, 1:08:28 PM10/19/14
to haxe...@googlegroups.com
ts2hx does not keep comments and generate raw code, so two or three week ago I made http://lib.haxe.org/p/threejs library (full version with conversion tools: https://bitbucket.org/yar3333/haxe-threejs). Conversion from TypeScript is fully automatic.

Haxiomic

unread,
Oct 19, 2014, 2:30:52 PM10/19/14
to haxe...@googlegroups.com
Awesome! Thanks Yaroslav, that library is much better. I came across your bitbucket repo but I hadn't realised it was already working

Confidant

unread,
Oct 20, 2014, 11:14:32 AM10/20/14
to haxe...@googlegroups.com
I'll be using this, thanks!

varomix WEY

unread,
Jul 31, 2015, 9:01:40 PM7/31/15
to Haxe
Hi there

seems like the source is updated to r71
how can we get the most recent version

thanks for this 

Yaroslav Sivakov

unread,
Aug 1, 2015, 6:31:24 AM8/1/15
to Haxe
Try to clone the repo https://bitbucket.org/yar3333/haxe-threejs and run
```shell
haxelib install refactor
make clean
make native-ts
make library
```

On Windows I use MinGW to run makefiles. I don't test on other OS or Cygwin.

суббота, 1 августа 2015 г., 4:01:40 UTC+3 пользователь varomix WEY написал:

Alvaro Castaneda

unread,
Aug 2, 2015, 2:18:46 AM8/2/15
to haxe...@googlegroups.com
when I run make native-ts still gets version 68

thanks

--
You received this message because you are subscribed to a topic in the Google Groups "Haxe" group.
Reply all
Reply to author
Forward
0 new messages