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
20
votes
9 answers

Beginning in Lua for Corona SDK

I have started working on Corona SDK.As you all know it uses Lua as the programming language,i wanted to know some good links or ebooks which i can refer to begin development.I am an iPhone developer and working on objective C since last 1 year. Any…
Aditya
  • 4,414
  • 5
  • 29
  • 40
20
votes
1 answer

Loadstring function replacement in latest version

I updated from lua 5.1 to 5.3.2 , One of my scripts didn't work cause of attempt to call a nil value (global 'loadstring') So, did they replace it with a new function? There you can find the function https://www.lua.org/pil/8.html There you can test…
Slavi
  • 576
  • 1
  • 3
  • 18
20
votes
1 answer

Why do we need to call Lua's collectgarbage() twice?

I have encountered several places where people call collectgarbage() twice to finalize all unused objects. Why is that? Why isn't a single call enough? Why not three calls? When I try the following code (on Lua 5.2), the object gets finalized…
Niccolo M.
  • 3,363
  • 2
  • 22
  • 39
20
votes
5 answers

Does Lua support Unicode?

Based on the link below, I'm confused as to whether the Lua programming language supports Unicode. http://lua-users.org/wiki/LuaUnicode It appears it does but has limitations. I simply don't understand, are the limitation anything big/key or not a…
TimK
  • 779
  • 2
  • 6
  • 5
20
votes
3 answers

Does Lua optimize the ".." operator?

I have to execute the following code: local filename = dir .. "/" .. base thousands of times in a loop (it's a recursion that prints a directory tree). Now, I wonder whether Lua concatenates the 3 strings (dir, "/", base) in one go (i.e., by…
Niccolo M.
  • 3,363
  • 2
  • 22
  • 39
20
votes
3 answers

Iterating through a Lua table from C++?

I'm trying to load tables from Lua to C++ but I'm having trouble getting it right. I'm getting through the first iteration just fine but then at the second call to lua_next it crashes. Any ideas? Lua file: level = { 1, 2, 3, } C++ file - First…
Jonas
  • 1,532
  • 3
  • 16
  • 20
20
votes
13 answers

Check if directory exists in lua?

How do I check if a directory exists in lua, preferably without using the LuaFileSystem module if possible? Trying to do something like this python line: os.path.isdir(path)
Dan
  • 33,953
  • 24
  • 61
  • 87
20
votes
5 answers

Casting between void * and a pointer to member function

I'm currently using GCC 4.4, and I'm having quite the headache casting between void* and a pointer to member function. I'm trying to write an easy-to-use library for binding C++ objects to a Lua interpreter, like so: LuaObject lobj =…
Rob Hoelz
20
votes
4 answers

Print stacktrace from C code with embedded lua

If I understand this correctly, Lua by default will call the debug library "debug.traceback" when an error occurs. However, when embedding Lua into C code like done in the example here: Simple Lua API Example We only have available the error message…
hookenz
  • 36,432
  • 45
  • 177
  • 286
20
votes
2 answers

Case-insensitive Lua pattern-matching

I'm writing a grep utility in Lua for our mobile devices running Windows CE 6/7, but I've run into some issues implementing case-insensitive match patterns. The obvious solution of converting everything to uppercase (or lower) does not work so…
Nubbychadnezzar
  • 203
  • 1
  • 2
  • 4
20
votes
4 answers

How to check if a value is empty in Lua?

What is the proper way to make a conditional which checks of something is or is not empty in Lua? if x == "" and f x ~= "" does not seem to work.
Village
  • 22,513
  • 46
  • 122
  • 163
19
votes
1 answer

Empty variable check

I'm just learning lua, this is my first script with it. How can I check to see if a variable is empty or has something like a line feed in it?
Anthony Kernan
  • 301
  • 1
  • 3
  • 5
19
votes
7 answers

Statically typed Lua

I am looking for a Lua front-end compiler that is type-checked at compile time, but outputs standard Lua 5.1 byte-code (that has only run-time types). What I want is a decent amount of static, compile-time syntactic analysis and optional typing, to…
Armentage
  • 12,065
  • 8
  • 33
  • 33
19
votes
2 answers

Inserting Key Pairs into Lua table

Just picking upon Lua and trying to figure out how to construct tables. I have done a search and found information on table.insert but all the examples I have found seem to assume I only want numeric indices while what I want to do is add key…
Dayo
  • 12,413
  • 5
  • 52
  • 67
19
votes
1 answer

Simulate += in Lua, is it possible?

Someone had told me about overloading the operators, but I'm not even sure how I would begin to do that. What I'm attempting to do is change: table["key"]=table["key"]+12345 into table["key"]+=12345 Or even using a function, that would be…
Josh
  • 3,225
  • 7
  • 30
  • 44