Questions tagged [lua]

Lua is a powerful, fast, lightweight, embeddable scripting language. It is dynamically typed, runs by interpreting bytecode, and has automatic garbage collection. Its speed is one of the main reasons it is widely used by the machine learning community. It is often referred to as an "extensible extension language".

This tag is used for questions about the Lua programming language.

From Lua's About page:

What is Lua?

Lua is a powerful, fast, lightweight, embeddable scripting language.

Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.

The official implementation of Lua is written in clean ANSI C, but a list of several other implementations can be found on the Lua Users Wiki page on Lua Implementations.

The latest official version of Lua is 5.4.1. The previous minor version (5.3.6) is available in the version history on the official site. Lua version numbers are defined as follows: major.minor.bugfix. Minor version increases will often no longer be backwards compatible with prior minor versions.

Lua is certified Open Source software distributed under the terms of the MIT license. As such, Lua is free to use, even for commercial products.

Please note that the official name of this programming language is Lua (a Portuguese word for Earth's moon). It is not an acronym -- it is not spelled LUA.

Learning Lua

Resources

  • Lua.org - The official Lua site.
  • LuaJIT - A fast tracing Just-In-Time compiler for Lua 5.1.
  • LuaRocks - the package manager for Lua modules.
  • ZeroBrane Studio - An IDE and debugger supporting a variety of Lua systems.
  • Lua Development Tools - An Eclipse-based IDE and debugger.
  • LuaDist - Lua modules management system with Virtual Environment capabilities.

Some projects using Lua

  • Torch - A scientific computing framework based on Lua[JIT] with strong CPU and CUDA backends.
  • lua-alchemy - Port of the Lua programming language for ActionScript using Alchemy.
  • Nutria - PHP Standard Library Written in Lua Programming Language
  • Sputnik - A content management system designed for extensibility.

Community

Other places for discussing Lua, beyond the question & answer format of Stack Overflow:

Books

22266 questions
5
votes
4 answers

How to sort two tables simultaneously by using one of tables order?

Example: table1 = {2,3,1} table2 = {a,b,c} to table1 = {1,2,3} table2 = {c,a,b}
Frank05
  • 51
  • 1
5
votes
4 answers

How to pass large struct back and forth between between C++ and Lua

I am looking at embedding Lua in a C++ application I am developing. My intention is to use Lua to script what ordered operation(s) to perform for some given input, ie. receive a new work item in c++ program, pass details to Lua backend, Lua calls…
Dunni
  • 53
  • 1
  • 4
5
votes
1 answer

How to put a label after a return statement in Lua?

The following results in a syntax error on the third line: function f() return ::x:: end Why is it not possible to have a label following a return statement?
user1804599
5
votes
1 answer

gsub in Lua. Unable to replace pattern

I want to replace all phrases $br$ in the string for the character '\n'. I write the following code: str = string.gsub("String 1 $br$ String 2", "$br$", "\n"). But this does not work and displays the string String 1 $br$ String 2. What am I doing…
Victor
  • 333
  • 2
  • 10
5
votes
1 answer

Lua - direct package path to another folder in parent director

I have a directory laid out : -parent -target -current -firstChild -secondChild I am trying to direct my package.path from inside "secondChild" to "target" to retrieve other .lua folders stashed there. I have this set up…
Whelandrew
  • 195
  • 10
5
votes
2 answers

"attempt to call global 'tonumber' (a nil value)" in Lua, embedded (in VLC)

I use VLC media player 1.1.9 on Ubuntu 11.04. I'm trying to experiment with lua extensions for VLC; so I've added the file test.lua in ~/.local/share/vlc/lua/extensions/, which has only these two…
sdaau
  • 36,975
  • 46
  • 198
  • 278
5
votes
1 answer

Passing table without parentheses in lua giving error

The following gives me an error 'syntax error near 'Person' even though in the faq (http://www.luafaq.org/) it stats: "so it cleverly uses the fact that Lua will accept single function arguments without parentheses if the argument is a string or a…
user441521
  • 6,942
  • 23
  • 88
  • 160
5
votes
1 answer

lua c api: how to push a string with a null character in the middle?

normally, I would just use lua_pushstring(lua_State* L, const char* s); however, the string I want to push might have a null character in it. How do I make that work?
anon
  • 41,035
  • 53
  • 197
  • 293
5
votes
3 answers

Lua sort table alphabetically, except numbers

I would want to sort a table alphabetically. Except numbers. The code below shows how the table is sorted with comparator function: function( a,b ) return a.N < b.N end Gives me: obj = { [1] = { ["N"] = "Green 1"; }; [2] = { …
Dreanh
  • 53
  • 4
5
votes
1 answer

Lua: methods and properties when exporting class from c

I use lua as a scripting language for my 3d engine. I have lua "classes" for several objects and now I want to use properties instead of getters and setters. So instead of something like this local oldState =…
5
votes
1 answer

How to export, then access exported methods in Lua

I have a file, display.lua in which I have code to load some resources. ----display.lua Resources = {} function Resources:new(rootdir) local newObj = {image = {}, audio = {}, root = ""} newObj.root = rootdir return setmetatable(newObj,…
chown
  • 101
  • 1
  • 5
5
votes
2 answers

Luasql and SQLite?

I just got started looking at Lua as an easy way to access the SQLite DLL, but I ran into an error while trying to use the DB-agnostic LuaSQL module: require "luasql.sqlite" module "luasql.sqlite" print("Content-type:…
Gulbahar
  • 5,343
  • 20
  • 70
  • 93
5
votes
1 answer

Lua jump to right line

I have a makefile that looks like: default: lua blah.lua Now, in Vim, I type ":make". There's an error in my Lua code; it gives a file name + line number. I would like Vim to jump to the right file/line. How do I make this happen?
anon
  • 41,035
  • 53
  • 197
  • 293
5
votes
3 answers

Lua Relative Path Required

I am writing a Lua script and am trying to use require on a file that exists in the same directory as the main script. I cannot seem to get require to work in this case and have tried several solutions I have found but none seem to work. I have…
Lance
  • 611
  • 6
  • 28
5
votes
1 answer

Lua execute something stored in tables key value

I want to make a table with specific names as keys and specific functions as values. The key names represent commands that a user enters and if a key by that name exists, then the program should execute the code stored in that keys value. So for…
thee
  • 53
  • 4