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

embedding multiple lua instances in a multiple threaded program

I have a program with 4 threads. Within each thread, I do a luaL_newstate(); Each thread only has access to it's own lua instance. Is there anything I need to worry about? [I.e. is there some hidden state that all lua instances share behind my…
anon
  • 41,035
  • 53
  • 197
  • 293
16
votes
1 answer

How to embed iPhone-Wax into app

I have just learnt about iPhone-Wax (thanks to SO). Now the documentation is rather sparse for what I am trying to do. I want to embed it into an Objective-C app. I don't want it to be the main app. Has anyone done it and how can I achieve it? I…
John Smith
  • 12,491
  • 18
  • 65
  • 111
16
votes
2 answers

Writing multiline text files in Lua

I would like to know the best way to make my script write something into a file (lets say text.txt) in a way that would always add a line break at the end. When I append text using file = io.open("test.txt", "a") file:write("hello") twice, the file…
user2999071
  • 173
  • 1
  • 1
  • 6
16
votes
1 answer

Creating a temporary file in lua

I've looked the LuaFileSystem doc and didn't really understood how I could create a temporary file and write in it. Also, I'm not sure exactly where I can find the temp file I create.. In /tmp? Here's how my function would look like: do function…
hy0shi
  • 271
  • 4
  • 12
16
votes
2 answers

How to embed lua (or some other scripting language) in a C# 5.0 application

First of all, I'd like to appoligize in advance for my English. My question is specifically about what do I need to have in a C# application to be able to interpret a Lua script fed to said application. The Lua scripts must be able to have access…
user3251430
  • 213
  • 1
  • 2
  • 10
16
votes
2 answers

How to convert a Lua string to float

I am writing a simple Lua script to calculate a median from a Sorted Set (http://redis.io/commands/#sorted_set) within Redis 2.8. The script is below local cnt = redis.call("ZCARD", KEYS[1]) if cnt > 0 then if cnt%2 > 0 then …
Adil
  • 2,092
  • 3
  • 25
  • 35
16
votes
2 answers

What is the meaning of 'attempt to index upvalue'

I am taking my first steps programming in Lua and get this error when I run my script: attempt to index upvalue 'base' (a function value) It's probably due to something very basic that I haven't grasped yet, but I can't find any good information…
Cactuar
  • 395
  • 2
  • 6
  • 14
16
votes
3 answers

How to keep the order of a Lua table with string keys?

Here's an example local query = {} query['count'] = 1 query['query'] = 2 for k,v in pairs(query) do print(k) end The above will print first query then count. How can I make sure without adding an int index key that the key strings keep their…
steven
  • 662
  • 1
  • 6
  • 13
16
votes
4 answers

How to create a directory in Lua?

Is it possible to create a directory in lua ? If so, how ?
Wookai
  • 20,883
  • 16
  • 73
  • 86
16
votes
7 answers

In Lua, how should I handle a zero-based array index which comes from C?

Within C code, I have an array and a zero-based index used to lookup within it, for example: char * names[] = {"Apple", "Banana", "Carrot"}; char * name = names[index]; From an embedded Lua script, I have access to index via a getIndex() function…
user200783
  • 13,722
  • 12
  • 69
  • 135
16
votes
2 answers

Lua For Variable In Range

I can't seem to get this to work. I come from Python, so I tried using the same syntax for the hell of it, but it unsurprisingly wouldn't work: var = 4 for var in range(2,20) do print ("var is in range") end
azonicrider
  • 189
  • 1
  • 1
  • 5
16
votes
8 answers

How to implement a scripting language into a C application?

I have a C application and I want to include a Scripting Language to put certain functionality into scripts. I just have no experience with that and don't know exactly where to start (Still learning C and trying to understand the application). How…
Michael Stum
  • 177,530
  • 117
  • 400
  • 535
16
votes
3 answers

How to generate random float in lua?

I need to generate random float in Lua. It needs to be > 1, so math.random() is not a solution. How can I do this?
user0103
  • 1,246
  • 3
  • 18
  • 36
16
votes
2 answers

Lua - find out calling function

In Lua, is it possible to know which function has called the current function. For instance function a() get_calling_function() --Should print function b end function b() a() end Is something like this possible? Does the debug…
SatheeshJM
  • 3,575
  • 8
  • 37
  • 60
16
votes
6 answers

Lua indentation code in Lua

Does there exist Lua code to indent Lua code? I have a lot of lua code where indenting it would help, and its in a pure lua environment. In defence of my question: For some of you here the situation here sounds impossible. It is very similar to…
John Smith
  • 12,491
  • 18
  • 65
  • 111