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

Making all the characters in a string lowercase in Lua

Here is the thing. I am trying to convert a string in lowercase in Lua, but it's not working. I have done this String = String:lower() but it doesn't like it. I am sure that is the way to do it, I've seen it done before. A few sites suggest it…
OddCore
  • 1,534
  • 6
  • 19
  • 32
46
votes
3 answers

How to quickly initialise an associative table in Lua?

In Lua, you can create a table the following way : local t = { 1, 2, 3, 4, 5 } However, I want to create an associative table, I have to do it the following way : local t = {} t['foo'] = 1 t['bar'] = 2 The following gives an error : local t = {…
Wookai
  • 20,883
  • 16
  • 73
  • 86
46
votes
2 answers

Lua multiline comments past ]]'s

I'm trying to find out a way to use a multiline comment on a batch of code, but it keeps mistaking some syntax in it as a ]] and thinking I want it to end there, which I don't! --[[ for k,v in pairs(t) do local d = fullToShort[k] local col…
Jonathan Picazo
  • 975
  • 3
  • 13
  • 23
46
votes
4 answers

is there any keyword like const or anything else which does the same job with it in lua?

Is there a const keyword in lua ? Or any other similar thing? Because i want to define my variables as const and prevent change of the value of the variables. Thanks in advance.
oiyio
  • 5,219
  • 4
  • 42
  • 54
45
votes
2 answers

How to compile Lua scripts into a single executable, while still gaining the fast LuaJIT compiler?

How can I compile my Lua scripts into a single executable file, while also gaining the super fast performance benefits of LuaJIT? Background: My Lua scripts are for a web application I created (e.g. to host http://example.com) My current technology…
nickb
  • 9,140
  • 11
  • 39
  • 48
44
votes
6 answers

Lua replacement for the % operator

I want to check, if a number is divisible by another number: for i = 1, 100 do if i % 2 == 0 then print( i .. " is divisible.") end end This should work without any problems, but with the Lua in my server the script doesn't run if…
Cyclone
  • 14,839
  • 23
  • 82
  • 114
43
votes
3 answers

Difference between ' and " within Lua

I just have a general question. Is there any difference using single and double quote marks within Lua? Example: require('test.lua') require("test.lua") When I programmed in PAWN, a language similar to C, single quote marks could be used for…
Bicentric
  • 1,263
  • 3
  • 12
  • 12
42
votes
6 answers

Choose a random item from a table

My goal is to pick out a random item from a table in Lua. This is what I've got so far, but it currently does not work: local myTable = { 'a', 'b', 'c', 'd' } print( myTable[ math.random( 0, #myTable - 1 ) ] ) How can I fix the above code so that…
Zen
  • 421
  • 1
  • 4
  • 3
42
votes
0 answers

Awesome WM: Move window from one screen to another

How can I program the rc.lua file to enable a keyboard shortcut to move a window from one tag on one screen to a tag that is on a different screen? I know the modkey + shift + [tag number] shortcut, but that moves the window only to a different tag…
Nyquist
  • 609
  • 1
  • 6
  • 7
41
votes
7 answers

Creating standalone Lua executables

Is there an easy way to create standalone .exe files from Lua scripts? Basically this would involve linking the Lua interpreter and the scripts. I believe it is possible (PLT Scheme allows the creation of standalone executables in the same way), but…
h3rald
  • 903
  • 1
  • 7
  • 16
40
votes
5 answers

interactive lua: command line arguments

I wish to do lua prog.lua arg1 arg2 from the command line Inside prog.lua, I want to say, for instance print (arg1, arg2, '\n') Lua doesn't seem to have argv[1] etc and the methods I've seen for dealing with command line arguments seem to be…
mr calendar
  • 945
  • 5
  • 11
  • 21
40
votes
14 answers

Lua: Rounding numbers and then truncate

Which is the best efficient way to round up a number and then truncate it (remove decimal places after rounding up)? for example if decimal is above 0.5 (that is, 0.6, 0.7, and so on), I want to round up and then truncate (case 1). Otherwise, I…
Willy
  • 9,848
  • 22
  • 141
  • 284
39
votes
1 answer

Compile lua code, store bytecode then load and execute it

I'm trying to compile a lua script that calls some exported functions, save the resulting bytecode to a file and then load this bytecode and execute it, but I haven't found any example on how to do this. Is there any example available on how to do…
WoLfulus
  • 1,948
  • 1
  • 14
  • 21
39
votes
4 answers

Can I check strings equality in lua?

Just a straight forward beginner question, I am coding Lua stuff for Garrys Mod, learning by reading wiki and other codings. if (self.Owner:SteamID( ) == "STEAM_0:1:44037488" ) then the above is the code I want to use, to check to see if the STEAM…
Howard Sun
  • 399
  • 1
  • 3
  • 3
39
votes
11 answers

Lua as a general-purpose scripting language?

When I see Lua, the only thing I ever read is "great for embedding", "fast", "lightweight" and more often than anything else: "World of Warcraft" or in short "WoW". Why is it limited to embedding the whole thing into another application? Why not…
user32756
  • 739
  • 3
  • 12
  • 15