What is Neko anyway?
Asked Answered
L

3

29

I have started to use Haxe to convert my ActionScript 3 projects into NME, but, I like to know please what is Neko in the world of Linux? I searched for it, I found its an animated cat!

Can any one please explain to me?

Laaspere answered 12/2, 2013 at 6:43 Comment(0)
H
60

Neko for most people is nothing more than a Haxe target. That's not technically true (it does have its own language, and could potentially be a target for other languages), but for most people, Neko is one of the Haxe output targets.

In the same way the Java Virtual Machine (JVM) can be targeted from multiple languages (See the list on wikipedia), Neko is a bytecode format that can theoretically be written to from multiple languages. For Neko however, most people seem to use Haxe to create their *.n files.

For Haxe programmers, the Neko target lets you:

  • Write command line tools and utilities (for example, haxelib and haxedoc are written in Haxe targeting Neko)
  • Write web apps or dynamic web pages - using mod_neko (or mod_tora) you get a web processor with the same sort of capabilities as PHP, but a fair bit faster.
  • Create games with NME (which originally started with Neko, it stands for Neko Media Engine), and compile them quickly, having a target closer to what CPP has, but which compiles a lot faster and where the output is cross platform.
  • A runtime that is closely tied into Haxe and can be used from within macros etc - so you can use all of the neko.* classes inside Macros.

If you're only interested in targetting SWF or JS, you'll probably not have much need for Neko. But if you are writing server side code, you'll appreciate the performance, and if you are writing CPP, you may appreciate having a simple target that is dead easy and super quick to compile, and which behaves similarly to CPP.

Of course, outside of Haxe neko is it's own language... but to me at least it seems most people just use it with Haxe.

More Info:

If you want to write in the Neko language (See this tutorial) you might save your code as "myfile.neko" and compile with nekoc myfile.neko, which will compile a Neko bytecode file "myfile.n".

If you want to write in the Haxe language, you might save your file as "MyFile.hx" and compile with "haxe -neko myfile.n -main MyFile".

The "myfile.n" that is generated by both of these doesn't have human readable source code - this is the Neko bytecode. You can run it on any computer that has Neko installed by running neko myfile.n. You can turn it into an executable (that runs without Neko installed) for your platform/OS by running nekotools boot myfile.n.

Here is a tutorial on Getting Started With Neko, which covers both command line programs you write and (very very basic) web pages.

Hernia answered 12/2, 2013 at 9:47 Comment(7)
Thanks for detailed answer, can you please explain, what is *.n files? is there a link where I can learn how to use neko to write web apps& CPP targeting?Laaspere
Updated my answer to answer your questions hopefully :)Screw
Surely this answers my questions, thanks for descriptive answerLaaspere
Hi Simo! I just want to second what Jason says here - I use Neko for web development, and I would never dream about going back to php again. Speed is great (compared to php), but the main reason is the excellent Haxe language - pure joy to work with, and constantly improving! (haxe.org)Candiecandied
Talking about NME, I do most of the core NME development using Neko target, and later on I compile to Flash, Html5, Cpp, Android...Candiecandied
If you were interested in the performance boost neko can give you, why would you not target C++ ?Perquisite
@singpolyma, basically because neko is ready to use with Apache etc and has mod_tora, which caches modules between requests, so it is already very fast and well integrated. It's already comparable in speed to any existing solution, so I'm not desperate for the extra speed of C++. You could get Haxe C++ to work with mod_cgi, but you would have to implement a lot of that low level code yourself, including all the advanced caching between requests. For now it's just easier to use neko, and for web (unlike mobile games), performance can always be increased by adding more servers :)Screw
P
10

"Neko" is Japanese for "cat", which is probably why you found what you did.

Neko is also a virtual machine (a "VM") like the Java Virtual Machine ("JVM") or the .Net Common Language Runtime (".Net CLR").

Neko has a custom high-level language made as an easily targeted language backend (like C-- in a way, but not like LLVM, which is closer to an assembly language). In other words: It's something that a programming language can be translated into rather than a more involved "full" compilation (like to assembly, to bytecode, or to machine code). Neko's language can be translated into a bytecode, which is portable and is usually stored in a ".n" file.

Neko was made by Nicolas Cannasse (the same person that made the Haxe Programming language), which is probably why Haxe has a Neko target in its compiler, and the Haxe tools, such as "haxelib" use it. Because the tools are compiled into ".n" files, they only need to be built once, and then they work on any platform with the VM executable "neko" installed.

Perhaps a more interesting bit about neko, and why you should learn it for Haxe development is that it's the runtime used for compile-time macros. See this tutorial for how part of your program can be run at compile time with full access to the build machine, which means you could even do complex tasks, such as parse a data file, at compile time.

Polarity answered 16/9, 2014 at 11:1 Comment(0)
E
6

Neko provides a common runtime for several different languages, including javascript and haxe. the compiler converts a source file (.neko) into a bytecode file (.n) that can be executed with the virtual machine. you can use the compiler as standalone commandline executable separated from the virtual machine, or as a neko library to perform compile-and-run for interactive languages. neko was written by nicolas cannasse.

you can find Neko Tutorial here

Eyot answered 12/2, 2013 at 6:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.