Neko (programming language)

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
Paradigm Object-oriented, structured, prototype-based, scripting
Designed by Nicolas Cannasse
Developer Motion Twin, Shiro Games
First appeared 2005; 13 years ago (2005)
Stable release
2.2.0 / December 19, 2017; 7 months ago (2017-12-19)
Typing discipline Dynamic
Implementation language C, OCaml
Platform IA-32, x86-64
OS Windows, macOS, Linux
License MIT
Filename extensions .neko .n
Major implementations
Neko, Haxe

Neko is a high-level dynamically typed programming language developed by Nicolas Cannasse as part of research and development (R&D) efforts at two indie video game firms in Bordeaux, France: first at Motion Twin and then at Shiro Games.


Neko has a compiler and a virtual machine (VM) with garbage collection. The compiler converts a source .neko file into a bytecode .n file that can be executed with the VM. Since Neko is dynamically typed with no fixed classes, a developer only needs to find the proper runtime mapping (in contrast to type mapping) so that code executes correctly. As the Neko FAQ puts it: " is easier to write a new or existing language on the NekoVM than it is for the CLR / JVM, since you don’t have to deal with a highlevel type system. Also, this means that languages can interoperate more easily since they only need to share the same data structures and not always the same types."[1]

Neko requires compiling before executing, like other scripting languages such as Apache Groovy. Since Neko need not be interpreted at runtime, it executes faster. The Haxe programming language compiles to Neko code, among other targets.

Virtual machine[edit]

The Neko virtual machine is used to execute a Neko bytecode file, the VM also has the option to convert a bytecode file into an executable file (output changes depending on the target operating system).


Hello World[edit]

$print("Hello World!");

Type conversions[edit]

$int("67.87"); // Converts string "67.87" to integer 67
$float(12345); // Converts integer 12345 to float 12345.0000
$string($array(1,2,3)); // Converts array [1,2,3] to string "[1,2,3]"


o = $new(null); // new empty object
o2 = $new(o); // makes a copy of o
o2 = $new(33); // if parameter is not an object, throw an exception
o.field = value; //sets field to value
o.field; // returns "field" value of object o


foo = function() {
o = $new(null);
o.x = 3; = function() { 
};; // prints 3

Function scope[edit]

var x = 3;
f = function() {
x = 4;
f(); // print 3


var proto = $new(null); = function() { 

var o = $new(null);
o.msg = "hello";
$objsetproto(o,proto);; // print "hello"

$objsetproto(o,null); // remove proto; // exception

Web functionality[edit]

Neko includes a mod_neko module for the Apache server. As such, it can process user input using GET and POST requests:

get_params = $loader.loadprim("mod_neko@get_params",0);
$print("PARAMS = "+get_params());

See also[edit]


External links[edit]