# Using Lua with eXtremeSQL

> eXtremeSQL supports the Lua programming language using the LuaJIT translator. The LuaJIt 2.1.0-beta3 is recommended and can be found at https://luajit.org/. LuaJIT is a low-level scripting language that is translated directly to machine code; also, a low-level FFI interface is used internally to directly call native functions. This provides good performance, but may not be error-proof, so programming with LuaJIT requires attention. eXtremeSQL packages include the appropriate version of Lua with some modifications to the Lua libraries to support specific eXtremeSQL implementation needs. Lua syntax is described in Appendix C.

> Though Lua is not available as a native language eXtremeDB API, it can be used to access eXtremeDB databases in the context of the eXtremeSQL engine. The Lua language can be used for both user defined functions and for performing scripts in the Lua language.

> A user defined function (UDF) is a Lua program that executes on the server, can be called like any other SQL function and can return results to the SQL engine as a query result or to use in subsequent SQL subqueries. In fact, these UDFs act as extensions to the server. A UDF can be one of two types:

> - Value returning UDF: This type of UDF returns a single value of a particular type which is defined when the UDF is created.
> - Result set returning UDF: This type of UDF will return a result set, and can be used in any context where a table would appear in a query. To create a result set returning UDF, a table definition is required. The structure of the result will match that table, which is referred to when the UDF is created. The table may or may not have any data and it cannot be referred to outside of the UDF.

> Using Lua as a script, which works as a separate program, it is possible to create a database, connect to an existing database, perform DDL and DML statements and process query results.

> Please use links in the following table to view topics of interest:

> Quick Start | Setting up the Lua environment
> Data Type Mappings | Lua Data Types
> Creating UDFs | Creating Lua UDFs
> Scripting | Creating Lua scripts
> eXtremeSQL Interface | How Lua interfaces with eXtremeSQL
> Tips and Tricks | Some important tips
> API Reference | The eXtremeSQL Lua API reference
> Lua Reference Manual | The Lua Language Reference Manual