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
35
votes
2 answers

table.getn is deprecated - How can I get the length of an array?

I'm trying to get the length of an array in Lua with table.getn. I receive this error: The function table.getn is deprecated! (In Transformice Lua)
user5066707
35
votes
6 answers

What web server to use for Lua web development

What web server (and why) should I use for Lua web development?
TimH
35
votes
5 answers

How to remove spaces from a string in Lua?

I want to remove all spaces from a string in Lua. This is what I have tried: string.gsub(str, "", "") string.gsub(str, "% ", "") string.gsub(str, "%s*", "") This does not seem to work. How can I remove all of the spaces?
Village
  • 22,513
  • 46
  • 122
  • 163
34
votes
11 answers

Get containing path of lua file

I am wondering if there is a way of getting the path to the currently executing lua script file? This is specifically not the current working directory, which could be entirely different. I know luafilesystem will let me get the current working…
radman
  • 17,675
  • 11
  • 42
  • 58
34
votes
4 answers

What's the difference between table.insert(t, i) and t[#t+1] = i?

In Lua, there seem to be two ways of appending an element to an array: table.insert(t, i) and t[#t+1] = i Which should I use, and why?
Eric
  • 95,302
  • 53
  • 242
  • 374
34
votes
4 answers

Lua - Number to string behaviour

I would like to know how Lua handles the number to string conversions using the tostring() function. It is going to convert to an int (as string) if the number is round (i.e if number == (int) number) or is it always going to output a real (as…
Virus721
  • 8,061
  • 12
  • 67
  • 123
34
votes
3 answers

How to 'unpack' table into function arguments

I'm trying to call a function in Lua that accepts multiple 'number' arguments function addShape(x1, y1, x2, y2 ... xn, yn) and I have a table of values which I'd like to pass as arguments values = {1, 1, 2, 2, 3, 3} Is it possible to dynamically…
codinghands
  • 1,741
  • 2
  • 18
  • 31
34
votes
2 answers

Sort a Table[] in Lua

I have a Lua table that I am trying to sort. The table's format is as follows: tableOfKills[PlayerName] = NumberOfKills Which means, for example, if I had a player named Robin with a total of 8 kills and another named Jon with a total of 10 kills,…
sgtaziz
  • 383
  • 1
  • 3
  • 6
33
votes
2 answers

Multiple locals on one line?

Consider the following Lua code: local var1, var2; Is var2 a local variable here? Or is only var1 a local?
SirRatty
  • 2,338
  • 5
  • 25
  • 37
33
votes
9 answers

Node.js for lua?

I've been playing around with node.js (nodejs) for the past few day and it is fantastic. As far as I can tell, lua doesn't have a similar integration of libev and libio which let's one avoid almost any blocking calls and interact with the network…
Shahbaz
  • 10,395
  • 21
  • 54
  • 83
33
votes
3 answers

How to create include files in Lua language?

I want to create a header file in Lua (header.lua), then execute the require function to load it. How do I execute require to a file that I have created?
Fernando Pinheiro
  • 1,796
  • 2
  • 17
  • 21
32
votes
4 answers

Cross platform/compiler consistent sprintf of floating point numbers

We have a game that needs to be deterministic as it is part of its multiplayer model. We also use Lua, which uses the sprintf internally (the format is %.14g). The problem arises when it prints number like 0.00001. In some cases it prints 1e-05 and…
kovarex
  • 1,766
  • 18
  • 34
32
votes
9 answers

Are there any recent Lua to JavaScript converters or interpreters somewhere?

I need to find a good Lua to JavaScript converter; lua2js on luaforge.org is out of date (3 or so years old and looks like it doesn't work on Lua 5.1) and I haven't yet found anything on Google. Does anyone have any experience with any other…
Kevlar
  • 8,804
  • 9
  • 55
  • 81
32
votes
5 answers

Lua Semicolon Conventions

I was wondering if there is a general convention for the usage of semicolons in Lua, and if so, where/why should I use them? I come from a programming background, so ending statements with a semicolon seems intuitively correct. However I was…
MrHappyAsthma
  • 6,332
  • 9
  • 48
  • 78
31
votes
5 answers

How to break a big lua string into small ones

I have a big string (a base64 encoded image) and it is 1050 characters long. How can I append a big string formed of small ones, like this in C function GetIcon() return "Bigggg string 1"\ "continuation of string"\ "continuation of…
bratao
  • 1,980
  • 3
  • 21
  • 38