
Hello Lua - ponticellif
http://haxe.org/blog/hello-lua
======
tomcam
Haxe is one of the best kept secrets of the programming world. Created by none
other than the author of curl, it's A C-ish, javascripty, but strictly typed
language with almost infinite portability. It "compiles" to many different
target languages, from PHP to Java to Python to C++ and more. It's fast, has a
beefy standard library, well-documented system interfaces, and just feels fun.
A remarkable accomplishment.

~~~
jdonaldson
I agree completely! ... Well, almost agree completely.

Daniel Stenberg is the author of curl:
[https://daniel.haxx.se/](https://daniel.haxx.se/)

Nicolas Cannasse is the (main) author of haxe:
[https://medium.com/@ncannasse](https://medium.com/@ncannasse)

Both are awesome in their own right.

I wrote the Lua target announced here, and am happy to answer any questions.

~~~
veli_joza
Can you explain who is the target audience for Lua target? What can I do with
it?

~~~
i336_
Well, with LuaJIT you get speed.

How much speed?

CloudFlare's firewall system uses LuaJIT to analyse approximately 4 million
GET requests per second.

( _Small pause, reread_ )

 _That_ much speed. That was the figure in June 2015, at least.

Some of the autogenerated code looks like this:
[http://i.imgur.com/F5aT0NF.png](http://i.imgur.com/F5aT0NF.png) (snagged via
pdfimages from [http://www.slideshare.net/jgrahamc/lua-the-worlds-most-
infur...](http://www.slideshare.net/jgrahamc/lua-the-worlds-most-infuriating-
language))

This video was where I had my major TIL moment:
[http://www.thedotpost.com/2015/06/john-graham-cumming-i-
got-...](http://www.thedotpost.com/2015/06/john-graham-cumming-i-
got-10-trillion-problems-but-logging-aint-one)

I also got the impression from the one other page of autogenerated code
briefly visible in this video that the firewall logic is also full of regular
expressions. And yet, it completes its analysis in roughly less than 1
millisecond.

It's almost a crime I haven't learned LuaJIT yet. :P

That said, looking at the slideshare link, you can see that Lua as a language
has some pretty annoying syntax, so I've sorta been shying away from it.

So maybe I'll learn HaXe instead. :D

~~~
delroth
> CloudFlare's firewall system uses LuaJIT to analyse approximately 4 million
> GET requests per second.

While I agree with your premise (LuaJIT is a pretty awesome project), this
example means nothing in terms of performance.

— "analyse" doesn't give an indication of the workload -- it could vary from
"matching against a precompiled regexp" to running advanced statistical
models.

— 4 millions requests per second does not mean anything without knowing the
size of the deployment. You can always throw more hardware at a "trivially"
parallelizable problem.

— Throughput is only one dimension on the "speed" continuum, latency (and
especially tail latency) is also very important. Some languages have very good
throughput and fail hard at tail latency (Java, Go until recently). Some
others have lower throughput but more predictable latency.

~~~
signa11
> While I agree with your premise (LuaJIT is a pretty awesome project), this
> example means nothing in terms of performance.

Yup, without knowing deployment details etc this number doesn't really mean
much.

perhaps you might have heard of the snabb-switch project ? which does line
rate 10gbps forwarding of 64b packets on a single x86 core. entire thing is
written in lua including the user land 'drivers' for Intel 10g cards :)

Edit: s/shabby/snabb (damn you autocorrect)

~~~
i336_
Wait, wait. Lua or LuaJIT? That's amazing!

~~~
signa11
> Wait, wait. Lua or LuaJIT? That's amazing!

from 'user' perspective you are still writing lua code. lua-jit would be an
optimizing compiler doing it's magic no ? get the code from here :
[https://github.com/snabbco/snabb](https://github.com/snabbco/snabb)

~~~
i336_
The README says it uses both Lua and LuaJIT, and I can see clear references to
LuaJIT in the codebase.

I'd heard of snabb a little while ago (I think in the context of Erlang), but
this only makes it even more interesting. Thanks for the pointer!

------
cszerzo
Sorry for off topic, just a heads up for the maintainers of haxe.org. Several
links in the footer, inside 'Learn Haxe' section are broken. They point to
'/http...'.

~~~
brndn
Also, on most websites, the logo/brand in the top left is a link to the
homepage. I clicked it a couple times until I saw the "Home" link next to it.

~~~
DanBC
I've been trained out of this because many company blogs link to the root of
the blog, and not back to the company product website.

I don't bother clicking that logo anymore.

~~~
i336_
Yeah, I hate that too.

I remember seeing a random website the other day, the blog had a homepage link
(not in the image, as "Home" text). That was really nice.

~~~
brndn
Yeah, this Haxe blog has that. It is nice.

------
stephenr
Well this has just introduced me to Haxe in general. This looks frankly,
amazing. Where has it been all my life.

------
alexatkeplar
If you have a piece of business logic that you want to make available in N
languages/platforms, is Haxe a valid option? The only other alternative I know
is to write a library in C/C++/Rust and use the FFIs in your target languages
to call it.

~~~
nacs
Definitely.

I use it for some game development projects and its able to compile and run
code on all Windows/Mac/Linux/iOS/Android (all native code) and even
Javascript+WebGL.

Obviously the framework I use is targeted to games but there are other
frameworks that target webdev (can target Node.js/PHP and lots of other
things).

~~~
stcredzero
_Obviously the framework I use is targeted to games_

Which one is that, and how well does it do cross-platform?

~~~
nacs
The framework is Luxe [1][2] and it/Haxe support the platforms I listed above
really well (there are published/commercial games made with it on all
platforms).

If you have any questions about it, their Gitter/chat [3] is pretty active.

[1]
[https://github.com/underscorediscovery/luxe](https://github.com/underscorediscovery/luxe)

[2] [http://luxeengine.com/docs/](http://luxeengine.com/docs/)

[3] [https://gitter.im/snowkit/public](https://gitter.im/snowkit/public)

------
tluyben2
If Haxe had an interpreter (not hscript as it is far too limited) I would use
it for a lot. Now compiling takes too long. The JS version is quite fast but
not good for everything. It's a fantastic product though; in my experience it
is write once - run anywhere. With some tweaks but that's to be expected.
Please someone implement an interpreter in Haxe for Haxe.

~~~
ciroduran
Is Neko what you'd be looking for? Or a completely interpreted version?

------
greenspot
From Haxe's introduction:

> Its syntax largely follows the ECMAScript standard, but deviates where
> necessary.

Anyone can tl;dr the main differences to JS?

~~~
PeCaN
It's much closer to ActionScript and ES4 than to ES5 or
ES6/2015/Next/Harmony/Trickshot.LegitScript/whatever the latest ECMAScript
standard is. The main difference is probably decent macro support.

There's always the Cookbook
([http://code.haxe.org/category/beginner/index.html](http://code.haxe.org/category/beginner/index.html))
if you want to see for yourself.

~~~
jdonaldson
Off the top of my head, Haxe has:

    
    
      block level scoping (vs. function level scoping)
      classic inheritance (vs. prototypes)
      distinction between hash and object (vs. nope)
      required semicolons (vs. still uncertain on that after 10 years)
    

There's also the whole raft of static typing features, but there's too many of
those to mention.

~~~
carussell
ES has all of those things except for requiring that a statement ends with a
semicolon.

~~~
Widdershin
I would disagree that ES has classical inheritance. ES6 has syntactic sugar
over prototypical inheritance that resembles classical inheritance in other
languages, but it's still prototypical under the hood.

~~~
colbyAFTrustedK
Is there a meaningful ? I.e., what does classical inheritance get you that
prototypes-under-the-hood don't? For a programmer using classes, that ES's are
implemented using prototypes should be as important has how the JVM works.

~~~
robocat
Classical inheritance enforces that a method can only be overridden by another
method in a subclass.

Prototypical "inheritance" allows different types of values to be assigned to
the same symbol.

E.g. if you have a method bob() on a prototype, you can set object.bob =
'astring'; and it isn't an error.

~~~
colbyAFTrustedK
That has more to do with a language opting out of having fixed types than it
does with class-based versus prototype-based inheritance.

------
robohamburger
Another reason to make 2d games with haxe! It already has some great
frameworks and libraries for it. So its great from a practical perspective if
you want to build something like that.

I have found the language to be a bit quirky. Its powerful but an odd
combination ocaml features and actionscript cruft.

------
beeswax
I did not get around to use haXe in a production env yet but it is one of the
very few language/ecosystem/target areas where there has been a huge amount of
both innovation and consolidation during the past n years.

Shouts to Nicolas and all contributors!

------
homero
Lua is a great language

~~~
4e1a
i concur

------
simplify
Does anyone think Haxe is a good server-side language? I'm still desperately
thirsty for a server-side language that has a sound, yet understandable and
easy-to-use static type system.

~~~
faide
What about Go?

------
NicoJuicy
Haxe seems an interesting alternative for mobile development ( cross platform)
for my currently chosen way : Xamarin.

Any tutorial for a crossplatform app on haxe with using native features ( eg.
gps)?

~~~
mrcdk
Haxe is cross platform in the sense of being able to compile to different
languages not in the sense of merging different platform features into one
library.

For example, you can use Haxe to build a native Android application using the
Java target as you would do with using Java in the first place. Same with iOS
(but using the C++ target)

AFAIK, there isn't any active project that offer the same as Xamarin in Haxe.
You could, in theory, use Haxe to target C# and Xamarin but I haven't tested
it.

------
koder2016
It's transpilers all the way down.

