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

Jump to a specific time in a file?

I'm trying to make a VLC script that checks if the "random" button is on, and if so when it jumps to a random file, instead of starting at time=0, it starts at a random time. So far, it's looking to me like it should be a playlist script and I can…
Paul
  • 10,381
  • 13
  • 48
  • 86
19
votes
7 answers

Begin Lua-scripting

I'm at a stage where I am forced to learn Lua, so do you have any suggestions on how I do this? I don't have a lot of experience with any other scripting languages than PHP. So, some suggestions on "head start Lua"-pages? EDIT As an addition to the…
Filip Ekberg
  • 36,033
  • 20
  • 126
  • 183
19
votes
7 answers

How to configure indentation in emacs lua-mode?

Complete emacs newbie here. I'm using emacs 23.1.1 on Ubuntu with emacs starter kit. I primarily work in the lua-mode (installed with package-install lua-mode). I need to tune how indentation works, so it would match my coding guidelines. The…
Alexander Gladysh
  • 39,865
  • 32
  • 103
  • 160
19
votes
2 answers

Extracting the last N characters of string in Lua?

I would like to extract the last N characters from a Lua string. What way I could use to achieve this?
DreTaX
  • 760
  • 2
  • 9
  • 22
19
votes
5 answers

Redirecting/redefining print() for embedded Lua

I have embedded Lua in my C++ application. I want to redirect print statements (or maybe simply redefine the print function?), so that I can display the evaluated expression somewhere else. What is the best way to do this: redirect or redefining the…
skyeagle
  • 6,925
  • 16
  • 56
  • 71
19
votes
4 answers

Torch: How to shuffle a tensor by its rows?

I am currently working in torch to implement a random shuffle (on the rows, the first dimension in this case) on some input data. I am new to torch, so I have some troubles figuring out how permutation works.. The following is supposed to shuffle…
DaveTheAl
  • 1,995
  • 4
  • 35
  • 65
19
votes
12 answers

Call Python or Lua from C++ to evaluate an expression, calculating unknown variables only if needed

I have an expression/formula like this std::string expr="((A>0) && (B>5 || C > 10))"; I have done some research and it seems that if A,B,C values are known, by embedding Lua or Python in a C++ program, there are eval functions that can substitute…
cateof
  • 6,608
  • 25
  • 79
  • 153
19
votes
2 answers

variable _ in lua has a special meaning?

I am a newbie to lua / torch. I notice that the variable _ is used a lot, especially in iterators. Example: for _, node in ipairs(protos.rnn.forwardnodes) do a, b = whatever(a,b) end this 'variable naming convention' (so to speak) is used in…
Alejandro Simkievich
  • 3,512
  • 4
  • 33
  • 49
19
votes
5 answers

Redis lua when to really use it?

I've started to research and play a bit with lua and have found it to be great when wanting to grab ranges of keys. Ex: business:5:visits:2013-11-12 business:5:visits:2013-11-13 etc With lua I only have to send one command to redis instead of the…
Alosyius
  • 8,771
  • 26
  • 76
  • 120
19
votes
2 answers

proxy_pass does not resolve DNS using /etc/hosts

In nginx the proxy_pass directive is not resolving DNS using the /etc/hosts file. Any way to enable this possibility (maybe by leveraging Lua as a last resort)?
Mark
  • 67,098
  • 47
  • 117
  • 162
19
votes
2 answers

Is there a pass statement in Lua like in Python?

In Python, one can use the pass keyword as a placeholder inside empty functions/code blocks. For example: def calc(): pass Is there an equivalent for in Lua? For example, I want to write something like: if connect then pass end
Prashant Gaur
  • 9,540
  • 10
  • 49
  • 71
19
votes
9 answers

Lua vs. XML for data storage

Many of us have been indoctrinated in using XML for storing data. It's benefits and drawbacks are generally known, and I surely don't want to discuss them here. However in the project I'm writing in C++, I'm also using Lua. I've been very surprised…
Kornel Kisielewicz
  • 55,802
  • 15
  • 111
  • 149
19
votes
1 answer

lua socket POST

I have a hard time using lua socket generic POST. I'm trying to POST to a web along with a body. But the body output i got is 1. Here's my code local http = require "socket.http" local ltn12 = require "ltn12" local util = require "util" local…
user1817517
  • 349
  • 1
  • 5
  • 16
19
votes
2 answers

How to pass a function as a parameter in Lua?

Bit confused by all this; so here's what I am attempting to do! Have a def thus: block_basic_DEF = { image = "button.png", name = "basic block", obj_table = this_obj_table.common_objects_table, startup = function() init(), <-----…
Mark Hula
  • 303
  • 1
  • 2
  • 4
19
votes
4 answers

What does (^?)* mean in this regex?

I have this regex: ^(^?)*\?(.*)$ If I understand correctly, this is the breakdown of what it does: ^ - start matching from the beginning of the string (^?)* - I don't know know, but it stores it in $1 \? - matches a question mark (.*)$ - matches…
doremi
  • 14,921
  • 30
  • 93
  • 148