haXe Externs
Ok so you get how to write haXe(more or less) but how do you get language specific functionalists to be included in your code... say hello to haXe Externs...
Video Transcript
00:01So the next thing I want to jump to is, again, because our time is, okay, we're getting close here.
00:09I have a little bit more.
00:10The next thing I want to talk a little bit about is actually about how to use X-turns with hex,
00:17and it might seem a little bit of a jump.
00:20But if you know, if you had saw in that last example that you saw that we had a,
00:26I was using jQuery, or actually Mike in that example was using jQuery.
00:31And this is a simple example I had made not so long, a long time ago.
00:37And so you're thinking, well, how do you get jQuery and hex?
00:42What's going on there?
00:44How do you just automatically have these JavaScript libraries available to you?
00:47It's magic.
00:48Well, that was just kind of magic, how they did it.
00:52They did a really cool thing.
00:54There's a concept called X-turns.
00:56And that basically is that, again, if you're familiar with JavaScript,
01:01as soon as you tell the browser to load in a library,
01:04it's going to download the JavaScript library into the browser,
01:08and it's going to make it available to you throughout the lifecycle of that browser session.
01:15And so all you need to do is to have hex, okay, well, you know,
01:20I need to make sure that my generated JavaScript code can see that library.
01:26And I want to actually make sure that I have type safety here and hex,
01:31and I have auto-completion.
01:33So we do that with something called X-turns.
01:36Now, I'm using, if you're familiar with Mr. Doob,
01:40I'm using actually his 3.js library, which is a written, again,
01:45this is a JavaScript Canvas example here.
01:49And it's a very powerful – I mean, even Google uses 3.js.
01:53If you guys saw that maps demo that was floating around that Google put out last week,
01:59it was actually using 3.js for the animations.
02:04So what's happened is that – and I'll just kind of show it here.
02:09You know, you have the 3.js library, right, right here.
02:13So, again, I'm having the JavaScript in here,
02:15and I'll just open up this HTML guy here.
02:20This is actually – this rotating cube right there, source code for that is just this.
02:25It's very simple.
02:27So you can see that I'm loading everybody in, the 3.js library.
02:32So he's in there.
02:34And then what's happened is that with these X-turns,
02:37these X-turns are basically – and I'll open up some of these up.
02:40These are just like over here on the right.
02:43I'll just make that a full window here.
02:46This is what the X-turn files look like.
02:48So this is actually how you would be able to talk to an existing JavaScript library,
02:53and people make these X-turn files for you.
02:55So these are hex files that just mimic the API of a JavaScript library you would want to work with.
03:02So, again, yeah, it's definitely a different example or a different way of working
03:09if you've never done hacks or have similar experience with their languages.
03:14So I'll just kind of give a very brief example here.
03:17So let's see, a renderer.
03:20So you can see that – okay, so my renderer here, you can see it's a Canvas renderer.
03:29So that's the type.
03:30It's a type of Canvas renderer.
03:32So how am I getting – this is the auto-completion option for that JavaScript library.
03:38Well, how am I getting that?
03:39Well, it's because of the Canvas renderer X-turn, which I've – again, it's just these dummy files that exist
03:49that you put on your source path.
03:51And you can actually see that now these are the methods that are actually part of that JavaScript library.
03:58So that's as far as I'll go with the X-turns, because, again, as you can tell,
04:06I could spend an hour just talking about the X-turns.
04:09But it's really important to know about how you would work with existing JavaScript libraries,
04:15because I know that was one of my first questions that came out to me when I was working with hacks.
04:20I'm like, okay, cool.
04:22I can work with the Canvas in a real easy way.
04:25However, how do I use – there's just tons of existing JavaScript libraries out there.
04:30And the way you would work with those is by creating these X-turn files
04:35and adding that to your source path.
04:37And then you'll have the auto-completion for you, and you'll actually have the type safety there.
