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

Is it possible to execute a single lua statement from a host program?

I am trying to embed a lua-based script system into my game engine. I would like the scripting to be able to have both blocking and non-blocking commands, for example: character.walkTo(24, 359); // Blocks until character arrives c = 35; // Non…
Lake
  • 4,072
  • 26
  • 36
5
votes
3 answers

Is ipairs reliable on unsorted arrays?

I'm wondering if anyone can confirm whether you can trust ipairs() to; return all indices in order, for a table that's index-complete but unsorted. We have code all over our project that clones tables using pairs(), however any arrays cloned come…
CalvinE
  • 191
  • 1
  • 7
5
votes
3 answers

In Lua, how to pass vararg to another function while also taking a peek at them?

It seems that in Lua, I can either pass vararg on to another function, or take a peek at them through arg, but not both. Here's an example: function a(marker, ...) print(marker) print(#arg, arg[1],arg[2]) end function b(marker, ...) …
Roman Starkov
  • 59,298
  • 38
  • 251
  • 324
5
votes
8 answers

dyld: Library not loaded: /usr/local/lib/liblua.5.1.5.dylib

I got the following error while trying to invoke terminal Vim (terminal app from MacVim directory); after I updated homebrew, rvm & reinstalled a new version of Ruby. dyld: Library not loaded: /usr/local/lib/liblua.5.1.5.dylib Referenced from:…
Jikku Jose
  • 18,306
  • 11
  • 41
  • 61
5
votes
3 answers

In Lua, can I easily select the Nth result without custom functions?

Suppose I am inserting a string into a table as follows: table.insert(tbl, mystring) and that mystring is generated by replacing all occurrences of "a" with "b" in input: mystring = string.gsub(input, "a", "b") The obvious way to combine the two…
Roman Starkov
  • 59,298
  • 38
  • 251
  • 324
5
votes
2 answers

How to redirect stdout to file in Lua?

I'm trying to redirect stdout in Lua (5.1) to a file instead of to console. There is a third-party API (which I cannot modify) containing a function that prints out a serialized set of data (I do not know which function does the printing, assume…
cwbit
  • 88
  • 1
  • 6
5
votes
1 answer

Remove multiple elements from array in Lua

In Lua, I know there is table.remove(array, index) Is there a fast way to remove and return X elements from the array (without just repeated calls to table.remove)?
K2xL
  • 9,730
  • 18
  • 64
  • 101
5
votes
2 answers

Lua task scheduling

I've been writing some scripts for a game, the scripts are written in Lua. One of the requirements the game has is that the Update method in your lua script (which is called every frame) may take no longer than about 2-3 milliseconds to run, if it…
Martin
  • 12,469
  • 13
  • 64
  • 128
5
votes
4 answers

lua_newstate vs lua_newthread

I am trying to implement lua into my existing multi threaded application. I heard that lua was not thread safe I have been creating different lua_State(s) for different threads. Looking through the lua header files I found lua_newthread. How would…
user4175869
5
votes
1 answer

redis: reset counter every day

I am looking to reset a counter every day using Redis. I am new to Redis so I want to make sure I well understood how transactions and pipes work. Does the following code ensure that I will always get a unique couple of (date, number) while working…
Michael
  • 8,357
  • 20
  • 58
  • 86
5
votes
1 answer

Meaning of the `from` parameter of `lua_resume`

From Lua 5.2 Reference Manual: int lua_resume (lua_State *L, lua_State *from, int nargs); [...] The parameter from represents the coroutine that is resuming L. If there is no such coroutine, this parameter can be NULL. But it does not say much to…
Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
5
votes
1 answer

What is newproxy and how is it useful?

I was messing around with Lua yesterday and stumbled upon the 'newproxy' function. http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions#newproxy I kind of understand it, but I'm not sure how it is useful. I know it creates a blank…
David
  • 693
  • 1
  • 7
  • 20
5
votes
3 answers

table.insert/remove by value

I got two tables, for example: table1 = { element1, element2, element3, element4 } table2 = { element1, element3 } Table 2 refers to some elements of table1, but I don't know which exactly, nor I know their index. Now, for an specific element I…
jawo
  • 856
  • 1
  • 8
  • 24
5
votes
2 answers

More elegant, simpler way to convert code point to UTF-8

For this question I created the following Lua code that converts a Unicode code point to a UTF-8 character string. Is there a better way to do this (in Lua 5.1+)? "Better" in this case means "drastically more efficient, or—preferably—far fewer lines…
Phrogz
  • 296,393
  • 112
  • 651
  • 745
5
votes
1 answer

Lua C api: handling large numbers

I deal with picoseconds in my code (numbers are > 10^12). C code to pass data to Lua (atime and eventid are both of size_t type) lua_getglobal ( luactx, "timer_callback" ); lua_pushunsigned ( luactx, atime ); lua_pushunsigned ( luactx, eventid…
pugnator
  • 665
  • 10
  • 27