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
31
votes
5 answers

Print all local variables accessible to the current scope in Lua

I know how to print "all" global variables using the following code for k,v in pairs(_G) do print("Global key", k, "value", v) end So my question is how to do that for all variables that are accessible from the currently executing function,…
Edu Felipe
  • 10,197
  • 13
  • 44
  • 41
31
votes
3 answers

How to debug lua code inside nginx config?

I want to insert log points (io.write) inside my lua code which itself is in nginx configuration (using HttpLuaModule for nginx). How to do that? Access and error logs are not showing them.
mannuscript
  • 4,711
  • 6
  • 26
  • 25
31
votes
3 answers

Not Equal to This OR That in Lua

I am trying to verify that a variable is NOT equal to either this or that. I tried using the following codes, but neither works: if x ~=(0 or 1) then print( "X must be equal to 1 or 0" ) return end if x ~= 0 or 1 then print( "X must be…
Ian
  • 5,704
  • 6
  • 40
  • 72
31
votes
1 answer

if, else, else if and end Lua

Any idea why this is wrong in Lua? if Pieza == 1 then if Rotacion == 1 then Piezas = Cuadrado1 else if Rotacion == 2 then Piezas = Cuadrado2 else if Rotacion == 3 then --this…
Makenshi
  • 993
  • 3
  • 15
  • 28
30
votes
2 answers

How to count lines of code (LOC) using IntelliJ IDEA?

title says everything plus: - development language Lua - code revision control system - Perforce (integrated with IntelliJ IDE)
Aleksey Dr.
  • 532
  • 1
  • 4
  • 11
30
votes
4 answers

What is userdata and lightuserdata in Lua?

What is userdata and lightuserdata in Lua? Where do I need it? I have been trying to wrap my head around it for some time now, but I can't seem to find any tutorials/explanations that I really understand. Why do you need them, why can't you just…
Lars
  • 301
  • 1
  • 3
  • 3
30
votes
1 answer

Looping over array values in Lua

I have a variable as follows local armies = { [1] = "ARMY_1", [2] = "ARMY_3", [3] = "ARMY_6", [4] = "ARMY_7", } Now I want to do an action for each value. What is the best way to loop over the values? The typical thing I'm finding…
Jeroen De Dauw
  • 10,321
  • 15
  • 56
  • 79
30
votes
2 answers

Why do we need an embeddable programming language like Lua?

What are the typical use cases of using an embeddable programming language? Do I understand it correctly that such language should be embedded into some program environment and should be able to be executed from there?
Vladimir Kostyukov
  • 2,492
  • 3
  • 21
  • 30
30
votes
10 answers

Lua, what is Lua?

I read something about Lua today, and I was wondering what it was. I did a Google and Wikipedia search, I understood it until they began talking about C and API. I still don't understand it. What is Lua and are there any tutorials for beginners?
user142019
29
votes
6 answers

What is the maximum value of a number in Lua?

There doesn't seem to be a clear answer to this in the documentation. I'm interested in incrementing a variable time that counts the seconds since the program started. If the maximum value can count far into the future, like 100 years, then I don't…
Kai
  • 9,444
  • 6
  • 46
  • 61
29
votes
6 answers

Debugging embedded Lua

How do you debug lua code embedded in a c++ application? From what I gather, either I need to buy a special IDE and link in their special lua runtime (ugh). Or I need to build a debug console in to the game engine, using the lua debug API calls. I…
deft_code
  • 57,255
  • 29
  • 141
  • 224
29
votes
3 answers

LuaJIT 2 optimization guide

I'm looking for a good guide on how to optimize Lua code for LuaJIT 2. It should focus on LJ2 specifics, like how to detect which traces are being compiled and which are not, etc. Any pointers? Collection of links to Lua ML posts would do as an…
Alexander Gladysh
  • 39,865
  • 32
  • 103
  • 160
29
votes
8 answers

Incrementation in Lua

I am playing a little bit with Lua. I came across the following code snippet that have an unexpected behavior: a = 3; b = 5; c = a-- * b++; // some computation print(a, b, c); Lua runs the program without any error but does not print 2 6 15 as…
prapin
  • 6,395
  • 5
  • 26
  • 44
28
votes
3 answers

Variable number of function arguments Lua 5.1

In my Lua script I'm trying to create a function with a variable number of arguments. As far as I know it should work like below, but somehow I get an error with Lua 5.1 on the TI-NSpire (global arg is nil). What am I doing wrong? Thanks! function…
Frog
  • 1,631
  • 2
  • 17
  • 26
28
votes
3 answers

In Lua how do you import modules?

Do you use require "name" or local name = require "name" Also, do you explicitly declare system modules as local variables? E.g. local io = require "io" Please explain your choice. Programming in Lua 2ed says "if she prefers to use a shorter name…
Vitaly
  • 4,358
  • 7
  • 47
  • 59