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

Associatively sorting a table by value in Lua

I have a key => value table I'd like to sort in Lua. The keys are all integers, but aren't consecutive (and have meaning). Lua's only sort function appears to be table.sort, which treats tables as simple arrays, discarding the original keys and…
Ben Blank
  • 54,908
  • 28
  • 127
  • 156
25
votes
6 answers

How to check if two tables(objects) have the same value in Lua

I wanna check if two tables have the same value in Lua, but didn't find the way. I use the operator ==, it seems just to check the same objects, but not the elements in the table. If I have two tables, a={} b={} the value of a==b is false. but…
LetsOMG
  • 429
  • 1
  • 5
  • 11
25
votes
12 answers

How to add a "sleep" or "wait" to my Lua Script?

I'm trying to make a simple script for a game, by changing the time of day, but I want to do it in a fast motion. So this is what I'm talking about: function disco ( hour, minute) setTime ( 1, 0 ) SLEEP setTime ( 2, 0 ) SLEEP setTime ( 3, 0…
Donavon Decker
  • 443
  • 2
  • 5
  • 6
24
votes
4 answers

How can I get the lua stack trace from a core file using gdb

I have a C++ application (for OS X) that calls lua as a scripting language. I'm running a large number of these applications (100s) and they can run for a very long time (days or weeks). Sometimes one crashes. And when it crashes it leaves me a…
Michael Anderson
  • 70,661
  • 7
  • 134
  • 187
24
votes
6 answers

How do I add the Lua module for nginx on Alpine linux?

I'd like to have a lean Docker image for nginx with the Lua module enabled. How can I create this based on Alpine linux?
Marian
  • 14,759
  • 6
  • 32
  • 44
24
votes
3 answers

Why doesn't whatsapp play all gifs?

When I create a gif, which works fine in Chrome, I cannot make it play in WhatsApp. It just shows a static image. To give an example, I am using lua with the lua-gd package to draw gifs. Even the example code given, which gives a nice gif of an…
JBrouwer
  • 385
  • 1
  • 3
  • 6
24
votes
3 answers

Lua read beginning of a string

I am making an adventure game and I'm trying to make the user input a string and if the string starts with action then it will read the rest of the line in a function. act=io.read(); if act=="blah" then doSomething(); elseif act=="action"+random…
Albin9000
  • 343
  • 1
  • 2
  • 4
24
votes
1 answer

is it possible to get lua interpreter version information in script?

All I know is how to do it from command line, that is the -v switch. I need something like phpversion() or sys.version in python. Is that possible ?
rsk82
  • 28,217
  • 50
  • 150
  • 240
24
votes
1 answer

Reading whole files in Lua

I am trying to read a full mp3 file in order to read out the id3 tags. That's when I noticed that file:read("*a") apparently does not read the full file but rather a small part. So I tried to build some kind of workaround in order to get the content…
Henrik Ilgen
  • 1,879
  • 1
  • 17
  • 35
23
votes
4 answers

nginx proxy_pass based on whether request method is POST, PUT or DELETE

I have two iKaaro instances running on port 8080 and 9080, where the 9080 instance is Read only. I am unsure how to use nginx for example if the request method is POST, PUT, DELETE then send to write instance (8080) else send to 9080 instance. I…
khinester
  • 3,398
  • 9
  • 45
  • 88
23
votes
6 answers

Ruby vs Lua as scripting language for C++

I am currently building a game server (not an engine), and I want it to be extendable, like a plugin system. The solution I found is to use a scripting language. So far, so good. I'm not sure if I should use Ruby or Lua. Lua is easier to embed,…
bl00dshooter
  • 991
  • 2
  • 10
  • 17
23
votes
3 answers

What is the neatest way to split out a Path Name into its components in Lua

I have a standard Windows Filename with Path. I need to split out the filename, extension and path from the string. I am currently simply reading the string backwards from the end looking for . to cut off the extension, and the first \ to get the…
Jane T
  • 2,081
  • 2
  • 17
  • 23
23
votes
7 answers

Display contents of tables in lua

What I'm trying to do is display the content of table using the following code in Lua. local people = { { name = "Fred", address = "16 Long Street", phone = "123456" }, { name = "Wilma", address = "16 Long Street", phone…
Neenu
  • 479
  • 1
  • 6
  • 15
23
votes
1 answer

Unable to use environment variables in Lua code

I have some Lua code, which I use in my openresty nginx.conf file. This Lua code contains such lines: ... local secret = os.getenv("PATH") assert(secret ~= nil, "Environment variable PATH not set") ... Just for testing reasons I tried to check if…
Jacobian
  • 10,122
  • 29
  • 128
  • 221
23
votes
6 answers

Scientific libraries for Lua?

Are there any scientific packages for Lua comparable to Scipy?
Nope
  • 34,682
  • 42
  • 94
  • 119