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
22
votes
7 answers

Is developing an application for Android using Lua only possible?

So I read this article on Mobile Orchard and, as I'm planning on having my first steps in Android development, it got me thinking: is it possible to develop for Android in Lua only? I Googled the topic but found no definitive answer. I know Java is…
Straightfw
  • 2,143
  • 5
  • 26
  • 39
22
votes
5 answers

Inverse of math.atan2?

What is the inverse of the function math.atan2 I use this in Lua where I can get the inverse of math.atan by math.tan. But I am lost here. EDIT OK, let me give you more details. I needed to calculate angle between 2 points (x1,y1) and (x2,y2) and…
SatheeshJM
  • 3,575
  • 8
  • 37
  • 60
21
votes
1 answer

Should I use ipairs or a for loop

I have read that the use of ipairs is slow compared to a for loop, should I change my programming habit? I'll be using lua 5.2 one day, currently 5.1. My arrays are approximately 1000 items at most. local mytbl = { 'a','b','c','e'} for i,v in…
topskip
  • 16,207
  • 15
  • 67
  • 99
21
votes
10 answers

How do I know if a table is an array?

I'm developing a simple optimized JSON function. Lua uses tables to represent arrays but in JSON I need to recognize between them. The code below is used: t={ a="hi", b=100 } function table2json(t,formatted) if type(t)~="table" then return…
AlexStack
  • 16,766
  • 21
  • 72
  • 104
21
votes
3 answers

Is there a fully managed (.NET) Lua interpreter?

Does anyone know if there is a fully managed (.NET) Lua interpreter? The regular source can be compiled with managed extensions for desktop .NET, but it can't be embedded in a Silverlight application.
Paul
  • 211
  • 1
  • 2
  • 3
21
votes
12 answers

Memory leaks - the horror of every programmer?

I'm programming a game engine in C++, which also has Lua support. My biggest horror: Memory leaks. It's not like my game is already infested with them, I'm rather afraid of them popping out of the ground like mushrooms, when the development is in a…
21
votes
2 answers

How to iterate Lua table from end?

How do I iterate a simple Lua table, that is a sequence, from end? Example of wanted behavior: local mytable = {'a', 'b', 'c'} for i, value in reversedipairs(mytable) do print(i .. ": " .. value) end should output 3: c 2: b 1: a How to…
Franz Wexler
  • 1,112
  • 2
  • 9
  • 15
21
votes
1 answer

Why does Lua default to global variables?

My favourite language these days is Lua. I have only one issue with it, why on earth is its default behaviour that variables in functions are global? In the similar language Icon there is a keyword "global" that is used when one really wants to use…
AndersH
  • 808
  • 6
  • 7
21
votes
6 answers

call/cc in Lua - Possible?

The Wikipedia article on Continuation says: "In any language which supports closures, it is possible to write programs in continuation passing style and manually implement call/cc." Either that is true and I need to know how to do it or it is not…
PeterM
  • 1,188
  • 1
  • 10
  • 15
21
votes
6 answers

Problems with Vim and lua?

I installed yadr onto my terminal, but I keep getting the following error when I open Vim: neocomplete does not work this version of Vim. It requires "if_lua" enabled Vim(7.3.885 or above). EDIT: Upgraded Vim to version 7.4.493 but still get the…
Kevin Lin
  • 681
  • 5
  • 11
21
votes
8 answers

What's a good C memory allocator for embedded systems?

I have an single threaded, embedded application that allocates and deallocates lots and lots of small blocks (32-64b). The perfect scenario for a cache based allocator. And although I could TRY to write one it'll likely be a waste of time, and not…
Robert Gould
  • 68,773
  • 61
  • 187
  • 272
20
votes
10 answers

Lua: print integer as a binary

How can I represent integer as Binary? so I can print 7 as 111
fl00r
  • 82,987
  • 33
  • 217
  • 237
20
votes
1 answer

How do I make a 2D array in Lua?

How can I make a 2D array with Lua? I need to dynamically create this. local tbl = { { } } Something like the above but where I can specify how many items. In my case they'll be the same amount. I basically want to access it like tbl[3][5]. Thanks
user441521
  • 6,942
  • 23
  • 88
  • 160
20
votes
3 answers

Are curly brackets used in Lua?

If curly brackets ('{' and '}') are used in Lua, what are they used for?
Sydius
  • 13,567
  • 17
  • 59
  • 76
20
votes
7 answers

How do I use the bitwise operator XOR in Lua?

How can I implement bitwise operators in Lua language? Specifically, I need a XOR operator/method.
Trevor
  • 1,858
  • 4
  • 21
  • 28