Getting Started With Lua UDFs
Currently, User-Defined Functions are written in Lua. Lua is a powerful, fast, lightweight, embeddable scripting language. To learn more about Lua, see About Lua.
If this is your first foray into Lua programming, then we suggest the following material:
- Programming in Lua, Second Edition (Lua 5.1)
- Lua 5.1 Reference Manual
- Lua Tutorials
- Lua Unofficial FAQ (uFAQ)
Aerospike currently supports Lua 5.1.4.
Aerospike supports the full Lua programming language, with a few exceptions.
Globals are restricted
- Global variables are not allowed.
- Global functions can only be called by Aerospike Server, and cannot be called by other Lua functions.
- To call a custom Lua function from another Lua function, the called function must be declared as a "local" function. For example, external function
sum()can call local function
add(), provided it is defined as local.
local function add(a,b)
return a + b
Restricted modules and functions
- coroutines - Lua functions can call each other provided they are "forward declared" before their actual use. In this example, we forward-declare
fun_B()and then we can use it inside the body of
fun_B(). We don't have to forward-declare
fun_A()in this example because it is declared first.
local fun_A( foo )
fun_B( foo.bar )
local fun_B( bar )
fun_A( bar.foo )
- debug module – Not enabled due to not being able to support the debugging features in Lua.
os.exit()– Not enabled because it didn't make sense for a Lua script to cause the database to process to exit.