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
18
votes
3 answers

Logical 'or' in Lua patterns?

Is it possible to achieve in Lua? local noSlashEnding = string.gsub("slash\\ending\\string\\", "\\|/$", "") -- noSlashEnding should contain "slash\\ending\\string" local noSlashEnding2 = string.gsub("slash/ending/string/", "\\|/$", "") --…
Yuri Ghensev
  • 2,507
  • 4
  • 28
  • 45
18
votes
1 answer

Luaj: How to Import or Require a Lua Function Library

In the Java LuaJ library I would like to know how to require or import a lua script of functions in another lua script called by a lua closure through Java. For example this does not work: public static LuaValue runInputStreamLua(InputStream…
David Williams
  • 8,388
  • 23
  • 83
  • 171
18
votes
1 answer

Bizzare "attempt to call a table value" in Lua

The following code snippet: for weight, item in itemlist do weight_total=weight_total+weight end is causing the error "attempt to call table value" on the first line in that snippet. Why? Itemlist is a table of tables of weights and strings,…
Schilcote
  • 2,344
  • 1
  • 17
  • 35
18
votes
3 answers

How can I manipulate the JSON body of a POST request using Nginx and Lua?

I am doing a proof of concept to demonstrate how we might implement 3scale in our stack. In one example I want to do some POST request body manipulation to create an API façade that maps what might be a legacy API format to a new internal one. Eg.…
Jesse
  • 297
  • 1
  • 3
  • 9
18
votes
1 answer

How to check if nginx uses LuaJit and not Lua?

I installed http-lua-module with nginx, made a script that works perfectly fine, but now I want to be sure that nginx uses LuaJit instead of Lua (because my research shows that LuaJit is faster). I added to the .bushrc those lines of code : export…
Vor
  • 33,215
  • 43
  • 135
  • 193
18
votes
6 answers

Lua - get command line input from user?

In my lua program, i want to stop and ask user for confirmation before proceeding with an operation. I'm not sure how to stop and wait for user input, how can it be done?
RCIX
  • 38,647
  • 50
  • 150
  • 207
18
votes
5 answers

How can I make an GUI Application in Lua

First I'll show you an example of what I am talking about: GUI Example I've been studying Lua for around a week now, and I'm really curious of how I would do this. Basically (for now, and learning purposes), I just want to make a GUI with 2 buttons,…
Donavon Decker
  • 443
  • 2
  • 5
  • 6
18
votes
3 answers

Getting a part of a list or table in Lua

I know it's very easy to do in Python: someList[1:2] But how do you this in Lua? That code gives me a syntax error.
sdamashek
  • 636
  • 1
  • 4
  • 13
18
votes
2 answers

How to inspect userdata in lua

I am using inspect.lua to inspect table to string. But, if the value is a userdata, it returns just I really need to know what the userdata type is, what the userdata value is, it's very important for debuging, I don't want do it in any…
guilin 桂林
  • 17,050
  • 29
  • 92
  • 146
18
votes
3 answers

Attempt to index local 'self' (a nil value)

I have a problem with classes. I got below error: Attempt to index local 'self' (a nil value) When I call the getter method of below class. Item.lua file: require "classlib" Item = class("Item") function Item:__init() self.interval =…
zontragon
  • 780
  • 1
  • 9
  • 27
18
votes
1 answer

Lua Wrapper for C#?

I am looking to embed Lua into my C# application and i thought there was a wrapper around the lua API for C#, but don't remember what it is. Can someone point me in it's direction?
RCIX
  • 38,647
  • 50
  • 150
  • 207
18
votes
1 answer

lua: iterate through all pairs in table

I have a sparse lua table and I need to iterate over it. The Problem is, it seems that lua begins the iteration at 1, and terminates as soon as it finds a nil value. Here's and example: > tab={} > tab[2]='b' > tab[5]='e' > for i,v in ipairs(tab)…
ewok
  • 20,148
  • 51
  • 149
  • 254
18
votes
2 answers

How can I print a huge number in Lua without using scientific notation?

I'm dealing with timestamps in Lua showing the number of microseconds since the Epoch (e.g. "1247687475123456"). I would really like to be able to print that number in all its terrible glory, but Lua insists on printing it in scientific notation.…
zslayton
  • 51,416
  • 9
  • 35
  • 50
18
votes
2 answers

How to get the file size and delete file in Lua?

I have problem in getting the size of the file using Lua. I am creating a function method that if the file size of the file is 743 bytes, then the file will be deleted. Here is my code : local getDLFile = function(fileToDL) local path =…
gadss
  • 21,687
  • 41
  • 104
  • 154
17
votes
9 answers

Example usage where Lua fits much better than C/C++

I'm currently embedding Lua and using it as a glorified intelligent config file. However, I think I'm missing something since people rave about the uses of Lua. For example, I can easily explain why you might use shell scripting instead of C by…
bugmenot77
  • 621
  • 3
  • 6
  • 14