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

How can I determine the OS of the system from within a Lua script?

Ok I need to determine the system's OS from a Lua script, but Lua as such has no API for this, so I use os.getenv() and query enviromental variables. On Windows checking the enviromental variable "OS" gives me the name of the system's OS, but is…
Robert Gould
  • 68,773
  • 61
  • 187
  • 272
23
votes
2 answers

How to delete the last character of the text?

I have the following code: text = "sometext" print( string.sub(text, ( #text - 1 )) ) I want delete the last character in text.
user3499641
  • 375
  • 2
  • 3
  • 9
23
votes
2 answers

First character uppercase Lua

Does Lua provide a function to make the first character in a word uppercase (like ucfirst in php) and if so, how to use it? I want keywords[1] to be first letter uppercase. I've read that string.upper does it but it made the whole word uppercase.
Tomek
  • 233
  • 1
  • 2
  • 5
23
votes
3 answers

Why use a do-end block in Lua?

I keep trying to find answers for this but fail to do so. I wanted to know, what is the do-end block actually used for? It just says values are used when needed in my book so how could I use this? Do I use it to reduce the scope of local variables…
Mayron
  • 2,146
  • 4
  • 25
  • 51
23
votes
3 answers

In Lua, is there a function that will tell me what current version I'm running?

Subject says it all. I would like to know if my host interpreter is running Lua 5.2 or 5.1
henryaz
  • 870
  • 1
  • 8
  • 18
23
votes
3 answers

Returning multiple values from functions in lua

I am experimenting with the following lua code: function test() return 1, 2 end function test2() return test() end function test3() return test(), 3 end print(test()) -- prints 1 2 print(test2()) -- prints 1 2 print(test3()) -- prints 1 3 I would…
Kara
  • 6,115
  • 16
  • 50
  • 57
22
votes
5 answers

Can Lua's require function return multiple results?

It is possible to create a Lua module which returns multiple results via the require function? I'm currently writing an extension to package.loaders and I want to know if I need to support such behavior. For example, take the following module, named…
GooseSerbus
  • 1,249
  • 11
  • 15
22
votes
6 answers

Getting return status AND program output

I need to use Lua to run a binary program that may write something in its stdout and also returns a status code (also known as "exit status"). I searched the web and couldn't find something that does what I need. However I found out that in…
AlexStack
  • 16,766
  • 21
  • 72
  • 104
22
votes
6 answers

get current working directory in Lua

What's the Lua to get the current working directory on Windows XP SP3 (or to get the directory of the currently-running Lua file)? I prefer not to use LuaFileSystem. I can't use os.execute("cd") because os.execute always starts from my home…
user600838
22
votes
3 answers

Store a Lua function?

Calling a Lua function from C is fairly straight forward but is there a way to store a Lua function somewhere for later use? I want to store user defined Lua functions passed to my C function for use on events, similar to how the Connect function…
Nick Van Brunt
  • 15,244
  • 11
  • 66
  • 92
22
votes
5 answers

How can one implement OO in Lua?

Lua does not have build in support for OO, but it allows you to build it yourself. Could you please share some of the ways one can implement OO? Please write one example per answer. If you have more examples, post another answer.
Łukasz Gruner
  • 2,929
  • 3
  • 26
  • 28
22
votes
5 answers

How to handle C++ exceptions when calling functions from Lua?

I have a working C++ function that I am able to call from Lua. To demonstrate my problem here is an example: int PushHello(lua_State *L){ string str("Hello"); lua_pushlstring(L, str.data(), str.length()); return 1; } Note: I know I…
Juraj Blaho
  • 13,301
  • 7
  • 50
  • 96
22
votes
4 answers

How do install libraries for both Lua5.2 and 5.1 using Luarocks?

I am writing a small Lua project and using Luarocks to install my 3rd-party dependencies. The default Lua version on my machine is 5.2 and up to this point everything is working just fine. However, today I have stumbled across a problem that is…
hugomg
  • 68,213
  • 24
  • 160
  • 246
22
votes
4 answers

Lua's bytecode specification

Can anyone tell me where to find Lua's bytecode specification? I've been searching for 15 minutes, and I can't find anything.
Wilfred Springer
  • 10,869
  • 4
  • 55
  • 69
22
votes
1 answer

How do I run another script from inside Lua?

I need to execute a Lua script from inside another Lua script. How many ways are there, and how do I use them?
SuperCheezGi
  • 857
  • 3
  • 11
  • 19