Introduction

Lua is an extension programming language designed to support general procedural programming with data description facilities. It also offers good support for object-oriented programming, functional programming, and data-driven programming. Lua is intended to be used as a powerful, lightweight scripting language for any program that needs one.

Overview

As an extension language, Lua has no notion of a “main” program. It works only when embedded in a host program, called the embedding program or simply the host. This host program can invoke functions to run a piece of Lua code, can write and read Lua variables, and register C functions to be called by Lua code. By using C functions, Lua can be augmented to handle a wide range of different domains, creating customized programming languages that share a syntactical framework.

Using the Lua API, Netezza has created nzLua. nzLua can be used to create user-defined functions, aggregates, and table functions on the Netezza appliance. Some of the features of Lua, such as the ability to access external files, ability to run external programs, and debugging features are unavailable in nzLua. In addition to the features that have been removed, many functions have been added to nzLua to make the language easy to use for developers who are familiar with the standard functions available in SQL. The version of Lua used to create nzLua (LuaJIT) uses just-in-time compilation techniques to compile frequently used code paths directly into 80x86 instructions.

Although slower than a UDX built that uses C++, the JIT compiler does result in execution which is 5x to 50x faster than is typical for other interpreted languages such as Perl, Python, and JavaScript (including JavaScript V8, which also uses a JIT compiler). To make nzLua as easy to learn as possible, the nzLua development kit includes an examples directory containing sample nzLua user-defined functions, aggregates, and table functions. Many of the examples include extensive comments that explain how to use the features available in nzLua.