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
55
votes
4 answers

How can I embed Lua in Java?

Is LuaJava a must for this? Or can I embed Lua into Java without it?
anon
55
votes
15 answers

Concatenation of tables in Lua

ORIGINAL POST Given that there is no built in function in Lua, I am in search of a function that allows me to append tables together. I have googled quite a bit and have tried every solutions I stumbled across but none seem to work properly. The…
John Mark Mitchell
  • 4,522
  • 4
  • 28
  • 29
53
votes
3 answers

How to format a lua string with a boolean variable?

I have a boolean variable whose value I'd like to display in a formatted string. I tried using string.format, but get something like the following for any choice of format option listed in the language reference: Lua 5.1.4 Copyright (C) 1994-2008…
Michael J. Barber
  • 24,518
  • 9
  • 68
  • 88
53
votes
3 answers

Get back the output of os.execute in Lua

When I do an "os.execute" in Lua, a console quickly pops up, executes the command, then closes down. But is there some way of getting back the console output only using the standard Lua libraries?
Drealmer
  • 5,578
  • 3
  • 30
  • 37
53
votes
2 answers

lua: retrieve list of keys in a table

I need to know how to retrieve the key set of a table in lua. for example, if I have the following table: tab = {} tab[1]='a' tab[2]='b' tab[5]='e' I want to be retrieve a table that looks like the following: keyset = {1,2,5}
ewok
  • 20,148
  • 51
  • 149
  • 254
51
votes
6 answers

What is a good game engine that uses Lua?

I know Love2D and Corona SDK (for mobile devices). Is there any other game engines that use Lua you recommend?
Fábio Perez
  • 23,850
  • 22
  • 76
  • 100
50
votes
6 answers

Lua print on the same line

In Pascal, I have write and writeln. Apparently Lua's print is similar to writeln of Pascal. Do we have something similar to write of Pascal? How can consecutive print commands send their output to the same…
AlexStack
  • 16,766
  • 21
  • 72
  • 104
49
votes
5 answers

Function/variable scope (pass by value or reference?)

I'm completely confused by Lua's variable scoping and function argument passing (value or reference). See the code below: local a = 9 -- since it's define local, should not have func scope local t = {4,6} -- since it's define local, should…
frooyo
  • 1,863
  • 3
  • 19
  • 21
49
votes
3 answers

What is the relationship between PyTorch and Torch?

There are two PyTorch repositories : https://github.com/hughperkins/pytorch https://github.com/pytorch/pytorch The first clearly requires Torch and lua and is a wrapper, but the second doesn't make any reference to the Torch project except with…
Labo
  • 2,482
  • 2
  • 18
  • 38
48
votes
4 answers

How to exit a Lua script's execution?

I want to exit the execution of a Lua script on some condition. For example: content = get_content() if not content then -- ( Here i want some kind of exit function ) next_content = get_content() --example there can lot of further checks Here I…
Prashant Gaur
  • 9,540
  • 10
  • 49
  • 71
48
votes
12 answers

Safely remove items from an array table while iterating

This question is similar to How can I safely iterate a lua table while keys are being removed but distinctly different. Summary Given a Lua array (table with keys that are sequential integers starting at 1), what's the best way to iterate through…
Phrogz
  • 296,393
  • 112
  • 651
  • 745
48
votes
4 answers

How to read data from a file in Lua

I was wondering if there was a way to read data from a file or maybe just to see if it exists and return a true or false function fileRead(Path,LineNumber) --..Code... return Data end
user1465457
47
votes
4 answers

Lua: converting from float to int

Even though Lua does not differentiate between floating point numbers and integers, there are some cases when you want to use integers. What is the best way to covert a number to an integer if you cannot do a C-like cast or without something like…
ddk
  • 1,813
  • 1
  • 15
  • 18
47
votes
4 answers

How do I get the number of keys in a hash table in Lua?

myTable = {} myTable["foo"] = 12 myTable["bar"] = "blah" print(#myTable) -- this prints 0 Do I actually have to iterate through the items in the table to get the number of keys? numItems = 0 for k,v in pairs(myTable) do numItems = numItems +…
Jay
  • 1,423
  • 2
  • 11
  • 9
47
votes
4 answers

What does operator ~= mean in Lua?

What does the ~= operator mean in Lua? For example, in the following code: if x ~= params then
Alejandro Simkievich
  • 3,512
  • 4
  • 33
  • 49