Lua - The Scripting Interpreter

D

DevynCJohnson

Guest
Lua is an increasingly popular scripting language that is used to make programs or addons. Many programs (like Minetest) use Lua for creating addons and extensions. The standard Lua interpreter is written in ANSI C, thus making it cross-platform. The Lua scripts are compiled to bytecode on run-time and then executed in the Lua Virtual Machine which is register-based. It may be helpful to know a little about Lua before deciding to learn it or implement it in a software project.

NOTE: The standard Lua interpreter is known as "PUC Lua".

Lua is a high-level object-oriented scripting language that is easy to learn compared to other programming languages. The official documentation is at http://www.lua.org/docs.html . Developers that are experienced in other programming languages may enjoy learning Lua at http://learnxinyminutes.com/docs/lua/ which provides a fast way to learn. http://lua-users.org/wiki/ may provide some additional help with learning the language.

Lua was designed to be embedded inside other programs to provide an extensions or addon framework. Minetest, Celestia, Cocos2d, MediaWiki, VLC, and others use Lua to provide a scripting layer, addons, or whatever the particular software needs.

Lua programmers can obtain new libraries by going to LuaRocks.org. LuaRocks is a package manager for Lua that provides a way for obtaining additional Lua libraries, called "rocks". This is just like the RubyGems package manager for Ruby developers to obtain "gems" or Pip for Python developers to get "eggs".

Lua scripts can be compiled to bytecode with the "luac" command. Doing so speeds up the loading time, but the execution time is the same. A Lua script compiled on a particular architecture will only be able to run on another system of the same Lua version and architecture. Striping the debugging information (with the "-s" argument) may help with performance. However, if an error occurs, it will be harder to find and fix the issue.

Embedded Lua (eLua) is the Lua Virtual Machine designed to run on bare-metal (http://www.eluaproject.net/). eLua is free and open-source. eLua is not an operating system, and it is not a stripped down version of the usual Lua interpreter. Lua code written for a desktop system can run on a microcontroller running eLua. The Lua code has not changed. Rather, eLua provides a way for Lua developers to program microcontrollers.

LuaJIT (Lua Just-In-Time compiler - http://luajit.org/) is a Lua interpreter in the form of a Just-In-Time compiler. LuaJIT operates faster than PUC Lua (http://luajit.org/performance.html). Like, PUC Lua, LuaJIT can be embedded inside other applications and is portable. However, LuaJIT is less portable and less stable than PUC Lua. Also, LuaJIT is larger than PUC Lua.

The LuaJIT IO Framework (http://luajit.io/) is an HTTP server that is comparable to Nginx.

Metalua is a macros system for Lua (http://metalua.luaforge.net/). This provides Lua developers a way to make Lua programs using metaprogramming.

Lua-Alchemy (https://github.com/lua-alchemy/lua-alchemy) is a port for running Lua with Adobe Alchemy and Adobe Flash.

Luaclang is a library that allows Lua to interface with LLVM/Clang (https://github.com/grrrwaaa/luaclang).

With all of the available uses and Lua interpreters and compilers, it may be beneficial to learn Lua. If Lua has already been learned, then the topics discussed in this article may inspire Lua programmers.

Further Reading
 

Attachments

  • lua0.jpg
    lua0.jpg
    20.3 KB · Views: 175,075


Lua is a nice popular scripting language with good interface...
 

Members online


Latest posts

Top