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
5 answers

Last Index of Character in String

How do you get the last index of a character in a string in Lua? "/some/path/to/some/file.txt" How do I get the index of the last / in the above string?
user177800
19
votes
8 answers

How do you construct a read-write pipe with lua?

I'd like to do the equivalent of: foo=$(echo "$foo"|someprogram) within lua -- ie, I've got a variable containing a bunch of text, and I'd like to run it through a filter (implemented in python as it happens). Any hints? Added: would really like to…
Anthony Towns
  • 2,864
  • 1
  • 19
  • 23
19
votes
2 answers

Lua table library removed?

I'm trying to learn the ropes on Lua, and I was going through the online tutorials. One problem I tried to solve was to examine a table local foo = {} to see how many elements it had. The tutorial gave the suggestion to use local length =…
Piotr
  • 541
  • 4
  • 19
19
votes
3 answers

counting number of string occurrences

I'm trying to count the number of times that " --" occurs in a string. So for instance, it occurs twice here 'a --b --c' I tried the following, but it gives me 4 instead of 2, any idea why? argv='a --b --c' count = 0 for i in string.gfind(argv, "…
Yaroslav Bulatov
  • 57,332
  • 22
  • 139
  • 197
19
votes
2 answers

Lua 5.2 LUA_GLOBALSINDEX Alternative

I have a program that embeds Lua and implements a form of lazy function lookup. The way it worked in Lua 5.1, whenever a symbol was undefined the interpreter would call a global function hook that would then resolve the symbol. This is a small…
jussij
  • 10,370
  • 1
  • 33
  • 49
18
votes
4 answers

https request in lua

I am trying to retrieve a page on my SSL enabled server with a lua script. Important to note that the server has a self-signed certificate. No problem with certificate issued by a trusted CA. local https = require("socket.http") local resp =…
ripat
  • 3,076
  • 6
  • 26
  • 38
18
votes
3 answers

Something like Apache Zookeeper with no java?

Is there some library or project out there that works like Zookeeper but has no java dependency? I'm looking at putting this on an embedded linux system, and need minimal footprint... something like a megabyte or less. I have Lua, C and C++…
Andrew McGregor
  • 31,730
  • 2
  • 29
  • 28
18
votes
3 answers

How to get the current buffer file path using the Neovim Lua API?

I am using Neovim 0.5 and want to write a custom function to use with telescope.nvim. I need to get the path of the file loaded in the current buffer before I can execute the function. I have been unable to find how to do this after reading the…
Smit Patel
  • 181
  • 1
  • 1
  • 3
18
votes
4 answers

Developing addins for World of Warcraft - Getting started?

As a long time World of Warcraft player, and a passionate developer I have decided that I would like to combine the two and set about developing some addins. Not only to improve my gameplay experience but as a great opportunity to learn something…
Martin
  • 39,569
  • 20
  • 99
  • 130
18
votes
2 answers

io.popen - how to wait for process to finish in Lua?

I have to use io.popen in Lua to run an executable which takes a command line argument. How to wait for a process to finish in the Lua so that expected output can be captured? local command = "C:\Program Files\XYZ.exe /all" hOutput =…
Chet
  • 193
  • 1
  • 1
  • 5
18
votes
8 answers

Why does Lua use a garbage collector instead of reference counting?

I've heard and experienced it myself: Lua's garbage collector can cause serious FPS drops in games as their scripted part grows. This is as I found out related to the garbage collector, where for example every Vector() userdata object created…
Garbage man
  • 189
  • 1
  • 1
  • 3
18
votes
5 answers

Is nested function efficient?

In programming languages like Scala or Lua, we can define nested functions such as function factorial(n) function _fac(n, acc) if n == 0 then return acc else return _fac(n-1, acc * n) end end return _fac(n,…
Khanetor
  • 11,595
  • 8
  • 40
  • 76
18
votes
1 answer

Which grammars can be parsed using recursive descent without backtracking?

According to "Recursive descent parser" on Wikipedia, recursive descent without backtracking (a.k.a. predictive parsing) is only possible for LL(k) grammars. Elsewhere, I have read that the implementation of Lua uses such a parser. However, the…
user200783
  • 13,722
  • 12
  • 69
  • 135
18
votes
7 answers

In Lua, how can you print the name of the current function, like the C99 __func__ identifier?

Something like this: function foo() print( __func__ ) ... end How can it be done?
x-x
  • 7,287
  • 9
  • 51
  • 78
18
votes
11 answers

What is the alternative for switch statement in Lua language?

I have this piece of code in C++ and i want to know how can i write some codes that replace switch statement in Lua because i face many problems and i need to use this statement. int choice; do // loop { cout<<"\n >>> The General Menu <<< \n"; …
zanaM
  • 189
  • 1
  • 1
  • 6