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
17
votes
6 answers

Get the index of an item by value in a redis list

I have a redis list I have created, I am using it as a queue at the moment that reverses once in a while. My problem is that I would like to be able to get the index of an item on that queue/list by value. Example If I have a list with the following…
dmportella
  • 4,614
  • 1
  • 27
  • 44
17
votes
4 answers

Iterate through Lua Table

I am trying to iterate through a lua table but I keep getting this error: invalid key to 'next' I know that index starts off as -8 and I know that there is a table there because it gets the first (and only) value in it. However, it tries to loop…
Tom Leese
  • 19,309
  • 12
  • 45
  • 70
17
votes
4 answers

Can I compile LÖVE games into EXE files and sell them?

I've got two questions about LÖVE. Can I sell what I make in LÖVE? Can I compile anything I make into an EXE file?
Freesnöw
  • 30,619
  • 30
  • 89
  • 138
17
votes
2 answers

using type() function to see if current string exist as table

Is it possible to see if a string is the same as the name of a table? For example: I know that a table called 'os' exists, and I have a string "os". Is there then a way to do this: x="os" if type(x)=="table" then print("hurra, the string is a…
Michelrandahl
  • 3,365
  • 2
  • 26
  • 41
17
votes
2 answers

Setting windows layout for a specific application in awesome-wm

How to config awesome so it would start new application with two windows aligned like this: ---------------- |xxxxxxxxxx####| |xxxxxxxxxx####| |xxxxxxxxxx####| |xxxxxxxxxx####| ---------------- where "x" is for example conversation window in pidgin…
klew
  • 14,837
  • 7
  • 47
  • 59
17
votes
12 answers

Which scripting language is better for embedding in multi-threaded C/C++ application

Considering the following requirementes: Must be supported on Windows. Preferably works also on other platforms. Must support multi threading. By that I mean that the engine can work in parallel in multiple threads. Readability is…
John
  • 5,561
  • 1
  • 23
  • 39
17
votes
2 answers

Lua: implicit table creation with string keys - why the extra brackets?

Say that you want to create a Lua table, and all its keys are valid lua identifiers. Then you can use the key=value syntax: local niceTable = { I=1, like=1, this=1, syntax=1 } If however your strings are not "identifiable", then you have to use the…
kikito
  • 51,734
  • 32
  • 149
  • 189
17
votes
3 answers

How do you throw Lua error up?

Is it possible to throw a Lua error from a function to be handled by the script calling the function? For example the following will throw an error at indicated comment local function aSimpleFunction(...) string.format(...) -- Error is indicated…
Puddler
  • 2,619
  • 2
  • 17
  • 26
17
votes
10 answers

Can I force Lua's table indexing to start from zero?

I have an issue with Lua. It uses one-based indexing. The language has a feature to set value at index 0, but the value won't be counted as a part of table length, and string manipulations are still one-based. Therefore, I think the feature is…
eonil
  • 83,476
  • 81
  • 317
  • 516
17
votes
4 answers

How catch ctrl-c in lua when ctrl-c is sent via the command line

I would like to know when the user from a command line presses control-c so I can save some stuff. How do I do this? I've looked but haven't really seen anything. Note: I'm somewhat familiar with lua, but I'm no expert. I mostly use lua to use the…
lars
  • 1,976
  • 5
  • 33
  • 47
17
votes
3 answers

Is there special meaning for ()() syntax in Lua

I see this type of syntax a lot in some Lua source file I was reading lately, what does it mean, especially the second pair of brackets An example, line 8 in https://github.com/karpathy/char-rnn/blob/master/model/LSTM.lua local LSTM = {} function…
sandwriter
  • 183
  • 7
17
votes
1 answer

Redis wildcard delete script using EVAL, SCAN, and DEL returns "Write commands not allowed after non deterministic commands"

So I'm on a quest to build a lua script that uses SCAN to find keys based on a pattern and Delete them (atomically). I first prepared the following script local keys = {}; local done = false; local cursor = "0" repeat local result =…
Billy
  • 886
  • 8
  • 18
17
votes
1 answer

Lua math.random not working

So I'm trying to create a little something and I have looked all over the place looking for ways of generating a random number. However no matter where I test my code, it results in a non-random number. Here is an example I wrote up. local lowdrops…
user2677006
  • 173
  • 1
  • 1
  • 4
17
votes
2 answers

Lua's package path in nginx

I am now programming in Lua with nginx. I write my Lua file and place it in a directory in /usr/local/nginx/lua. Then in nginx.conf I write a location, such as location /lua { lua_need_request_body on; content_by_lua_file…
freedoo
  • 691
  • 1
  • 5
  • 12
17
votes
4 answers

Greedy/Non-Greedy pattern matching and optional suffixes in Lua

In Lua, I'm trying to pattern match and capture: +384 Critical Strike (Reforged from Parry Chance) as (+384) (Critical Strike) where the suffix (Reforged from %s) is optional. Long version I'm trying to match a string in Lua using patterns (i.e.…
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219