# Lua Tips and Tricks

> ## Using the LuaJIT Console

> It is possible to use the LuaJIT console REPL (Read-Eval-Print Loop) to instantly enter eXtremeDB commands and see their results. To do this, assuming the required environment variables have already been set (see page Quick Start), just start the supplied luajit interpreter and load the eXtremeDB library. For example:

>         LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2017 Mike Pall. http://luajit.org/
>         JIT: ON SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc sink fuse
>         > require 'exdb'
>         > initRuntime{}
>         > devices = {{  type='conv',
>         assignment= 'database',
>         size = 64*1024*1024
>         }}>> >> >>
>         > dbparams = {ddl_dict_size=64*1024, max_classes=100, max_indexes=100}
>         > db = create("luadb", devices, dbparams)
>         > =db
>         cdata<struct McoLuaDatabase *>: 0x01c12d78
>         > c = connect{db=db}
>         > c:statement("create table t(i int)")
>         > c:statement("insert into t values([1,2,3])")
>         > curs = c:query("select i from t")
>         > for row in curs:rows() do print (row.i) end
>         1
>         2
>         3
>         > c:close()
>         > close(db)
>         > close(dbname)

> ## Debugging

> It is possible to debug UDFs and scripts written in Lua using debuggers. A general approach is to use client-server methods. eXtremeSQL includes a special module that executes debugger code and works as a network server. The user interface part works as a client and a GUI.

> To start debugging a server inside aLua program, some third-party library has to be used. Then the Lua code must load and start this server code.

> ## ZeroBrain Studio

> ZeroBrain Studio is a free lightweight Lua IDE that provides code completion, syntax highlighting, live coding, code analyzer, and debugging support. It is possible to debug Lua UDFs and applications using the ZeroBrain Studio debugger. For example

>         require('mobdebug').start()

> Please refer to the site https://studio.zerobrane.com/doc-remote-debugging for more information.

> ## Eclipse Lua Development Tools (LDT)

> To debug with LDT, it is necessary to first create an eclipse project based on Lua source code. This requires installing a debugger toolkit for LDT. Please refer to the site:

> https://wiki.eclipse.org/Koneki/LDT/User_Guide/Concepts/Debugger for more information.

> To start debugging, type this line into the beginning of the UDF to debug:

>         require('debugger')('192.168.0.112', 10000)

> This command will load the debugger module, create a server on local host and bind to a particular network adapter.