Support via Liberapay

Lua Source Code Blocks in Org Mode

Org Mode support for Lua


The Lua site describes the language as

a powerful, efficient, lightweight, embeddable scripting language. It supports procedural programming, object-oriented programming, functional programming, data-driven programming, and data description.

Lua is commonly used as a scripting language in games. It is the scripting language embedded in LuaTeX, an extended version of pdfTeX.

Requirements and Setup

The Lua site has the C source code for the interpreter and compilation instructions. LuaBinaries offers Lua libraries and executables compiled for several platforms. Several Linux distributions either include Lua or offer it as a package. Note that the interpreter is usually named lua or lua5.3.

Lua mode is a major mode for editing Lua sources in Emacs. It is available from MELPA as lua-mode. Code completion can be configured with LSP mode or company-lua.

Finally, you'll need to ensure that org-babel-load-languages includes an entry for Lua. Typically, org-babel-load-languages will contain many entries. The example below omits other languages.

 '((lua . t)))

Org Mode Features for Lua Source Code Blocks

Header Arguments

There are no Lua-specific default header arguments.

There are no Lua-specific header arguments.


Sessions are not currently supported.

Result Types

Only basic text output is supported.

Examples of Use

Hello World!

In the Org mode buffer:

#+name: lua-hello-world
#+begin_src lua :results output :exports both
print 'Hello World!'
print ("Hello World!")

HTML export of the source block:

print 'Hello World!'
print ("Hello World!")

HTML export of the result:

Hello World!
Hello World!

Some limitations

The current implementation of ob-lua.el honors strings, integers, reals, or Org lists as variables. It does not honor Org tables:

org-babel-lua-var-to-lua: Wrong type argument: stringp, 1

The current implementation works solely in scripting mode and does not return :results value.

Links to Tutorials and Other Resources

Documentation from the orgmode.org/worg/ website (either in its HTML format or in its Org format) is licensed under the GNU Free Documentation License version 1.3 or later. The code examples and css stylesheets are licensed under the GNU General Public License v3 or later.