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
5
votes
1 answer

Lua session with limited C/C++ stack

I have to run Lua session safely in an embedded multithreading environment where the thread stack is pre-allocated and of a fixed size. It is allowed to have the script failed at Lua level due to high C/C++ stack consumption. It it not allowed to…
dlask
  • 8,776
  • 1
  • 26
  • 30
5
votes
2 answers

Refactor C++ code to use a scripting language?

Background: I have been working on a platformer game written in C++ for a few months. The game is currently written entirely in C++, though I am intrigued by the possibility of using Lua for enemy AI and possibly some other logic. However, the…
Justin Ardini
  • 9,768
  • 2
  • 39
  • 46
5
votes
1 answer

Torch tensor equivalent function to matlab's "find"?

In a nutshell, I would like to know if there is a tensor command in torch that gives me the indices of elements in a tensor that satisfy a certain criteria. Here is matlab code that illustrates what I would like to be able to do in torch: my_mat =…
elpiloto
  • 53
  • 1
  • 3
5
votes
2 answers

Lua ignore Escape Sequence

Currently Lua has the following Escape Sequences: \a: Bell \b: Backspace \f: Form feed \n: Newline \r: Carriage return \t: Tab \v: Vertical tab \\: Backslash \": Double quote \': Single quote \nnn: Octal value (nnn is 3 octal digits) \xNN: Hex…
Bernardo Meurer
  • 2,295
  • 5
  • 31
  • 52
5
votes
1 answer

How to permanently add directory to Lua search path?

What's a simple way to permanently add a directory to the Lua search path?
sudo-nim
  • 408
  • 3
  • 14
5
votes
2 answers

lua-socket: unix domain sockets?

I'm using lua-socket 3.0rc1.3 (that comes with Ubuntu Trusty) and lua 5.1. I'm trying to listen on a unix domain socket, and the only example code I can find is this -- send stdin through unix socket socket = require"socket" socket.unix =…
user1569030
5
votes
3 answers

Lua - read one UTF-8 character from file

Is it possible to read one UTF-8 character from file? file:read(1) return weird characters instead, when i print it. function firstLetter(str) return str:match("[%z\1-\127\194-\244][\128-\191]*") end Function returns one UTF-8 character from…
Hrablicky
  • 143
  • 1
  • 9
5
votes
2 answers

Lua: attempt to compare boolean with number

I came across an error: attempt to compare boolean with number with the following code: local x = get_x_from_db() -- x maybe -2, -1 or integer like 12345 if 0 < x < 128 then -- do something end What causes this error? Thanks.
fannheyward
  • 18,599
  • 12
  • 71
  • 109
5
votes
2 answers

Lua - make bytecode

So, I've been asked to make a bytecode for the simpliest code: print("Hello, world!") But I have no idea how and I can't seem to find any information on how to make one... Can someone please help? I use Lua for Windows as a compiler. Thanks a lot
Oti Na Nai
  • 1,327
  • 4
  • 13
  • 20
5
votes
5 answers

HTTP Server Using Lua/ Torch7

I'm starting to learn Torch7 to get into the machine learning/ deep learning field and I'm finding it fascinating (and very complicated haha). My main concern, however, is if I can turn this learning into an application - mainly can I turn my Torch7…
Rob
  • 7,028
  • 15
  • 63
  • 95
5
votes
1 answer

How to count the amount of words in a text file in Lua

I was wanting to ask what the steps are to creating a Lua program that would count the amount of words in a .txt file? I'm only familiar with how to count characters and not strings.
Alex111
  • 167
  • 1
  • 4
  • 14
5
votes
1 answer

Lua String Append

So I created a function that all strings can use and it's called append. local strmt = getmetatable("") function strmt.__index.append(self, str) self = self..str return self end The function is then used like this: self =…
Lee Yi
  • 517
  • 6
  • 17
5
votes
1 answer

How do I provide multiple members to a Redis set using Lua when number of members is unknown until run-time?

For example, it's possible to add multiple members to some set in Redis using the sadd command this way: sadd myset 38 484 2 92 1 In Lua, I've found I can perform the same operation as follows: redis.call("SADD", "myset", "38", "484", "2", "92",…
Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
5
votes
8 answers

Compact web server with Lua support?

I need to find a very compact, cross-platform web server that can run Lua scripts, ie. either a regular web server like Mongoose that will forward queries to a Lua program in eg. FastCGI, or a web server itself written in Lua which will save the…
Gulbahar
  • 5,343
  • 20
  • 70
  • 93
5
votes
4 answers

Explanation about “local foo = foo” idiom in Lua

In Programming in Lua (3rd Ed.) by Roberto Ierusalimschy it is stated that A common idiom in Lua is local foo = foo This code creates a local variable, foo, and initializes it with the value of the global variable foo. (The local foo becomes…
Pier Paolo
  • 878
  • 1
  • 14
  • 23