HyperTextMatters
22 May 2005
 
Grokking the Virtual Machine
Post a comment (login required)
This month we consider Javascript's syntactic cousin, Lua:  

a = {}
a["b"] = "c"  

This code is valid in both Lua and Javascript; the first line creates a Javascript "associative array", or in Lua, a "table".  In both languages these constructs serve as "objects", so both of the following are valid statements for retrieving the "b" property of "a":  

a["b"]
a.b  

Other similarities include that functions are first-class values in both languages: they can be stored in variables, passed as arguments, and returned as results.  Furthermore, both languages support "lexical closures", which allow "data hiding" (see last month's column).  

Lua may well be the lowest-level of the C-based scripting languages: it is a "register-based" virtual machine, and has some hooks directly into C.  Lua originated in Brazil but, designed especially for embedding, is popular worldwide, particularly with game programmers.  Look into Lua, and become a better Javascript programmer!
Posted by htmatters at 3:56 PM | Comments (0)
 
Subscription Options

You are not logged in, so your subscription status for this entry is unknown. You can login or register here.

No comments found.

Post a comment (login required)