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

Does lua have something like python's slice

Like in python I can use slice. Like following b=[1,2,3,4,5] a=b[0:3] Can I do that kind of operation in Lua without a loop. Or Loop is the most efficient way to do that
Samuel
  • 5,977
  • 14
  • 55
  • 77
27
votes
4 answers

Generating uniform random numbers in Lua

I am working on programming a Markov chain in Lua, and one element of this requires me to uniformly generate random numbers. Here is a simplified example to illustrate my question: example = function(x) local r = math.random(1,10) print(r) …
Starfish_Prime
  • 287
  • 1
  • 3
  • 5
27
votes
1 answer

How do I run a .lua script?

I need to execute a .lua script using windows command line (cmd). I've got my .lua file in the same folder in which my lua.exe is. I've tried several ways of running the file but I can't figure out how to do it. =( (I also have the same script with…
matheusesp
  • 313
  • 2
  • 4
  • 6
27
votes
4 answers

Lua: How to find out if an element is a table instead of a string/number?

As the title says, what function or check can I do to find out if a lua element is a table or not? local elem = {['1'] = test, ['2'] = testtwo} if (elem is table?) // <== should return true
unwise guy
  • 1,048
  • 8
  • 18
  • 27
26
votes
2 answers

In Lua, what is the right way to handle varargs which contains nil?

I'm trying to create a debug print function which takes a file handle as the first argument. First, I write a function like this: function fprint (f, ...) for i, v in ipairs{...} do f:write(tostring(v)) f:write("\t") end …
torus
  • 1,039
  • 2
  • 11
  • 26
26
votes
6 answers

How to solve treesitter/highlighter: Error executing lua problem in neovim config

I'm currently using Neovim 6.0. And I also use the following neovim-config : https://github.com/rafi/vim-config. After installation, I created a python program to test and a problem encountered which are as follows: treesitter/highlighter: Error…
Mitchell
  • 421
  • 2
  • 5
  • 6
26
votes
2 answers

Embedded language: Lua vs Common Lisp (ECL)

Does anybody here have a experience with Common Lisp as a embedded language (using ECL)? If so, how good is ECL compared to Lua?
linkit
  • 269
  • 1
  • 3
  • 3
26
votes
6 answers

What is the standard (or best supported) big number (arbitrary precision) library for Lua?

I'm working with large numbers that I can't have rounded off. Using Lua's standard math library, there seem to be no convenient way to preserve precision past some internal limit. I also see there are several libraries that can be loaded to work…
Jon 'links in bio' Ericson
  • 20,880
  • 12
  • 98
  • 148
26
votes
9 answers

Lua, game state and game loop

Call main.lua script at each game loop iteration - is it good or bad design? How does it affect on the performance (relatively)? Maintain game state from a. C++ host-program or b. from Lua scripts or c. from both and synchronise them? (Previous…
topright gamedev
  • 2,617
  • 7
  • 35
  • 53
26
votes
5 answers

Nancy (C#): How do I get my post data?

I'm using Corona SDK to post data to my C# server: headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "color=red&size=small" local params = {} params.headers = headers params.body =…
Westerlund.io
  • 2,743
  • 5
  • 30
  • 37
26
votes
1 answer

luaL_openlib replacement for Lua 5.2

I am adapting a library written for Lua < 5.2 and got to a call I don't know the equivalent of: luaL_openlib(L, "Polycore", polycoreLib, 0); Where polycoreLib is a static const struct luaL_Reg polycoreLib [] How can I replace the call to…
Appleshell
  • 7,088
  • 6
  • 47
  • 96
26
votes
4 answers

Lua string.format options

This may seem like a stupid question, but what are the symbols used for string replacement in string.format? can someone point me to a simple example of how to use it?
RCIX
  • 38,647
  • 50
  • 150
  • 207
26
votes
1 answer

Does Lua have OR comparisons?

I'm just starting out using Lua, and I was wondering (because I can't find it on the website) if Lua has a OR operator, like how in other languages there is ||: if (condition == true || othercondition == false) { somecode.somefunction(); } whereas…
Polyov
  • 2,281
  • 2
  • 26
  • 36
25
votes
1 answer

How do I convert string of hex digits to value it represents in Lua

I'm reading in a lot of lines of hex data. They come in as strings and I parse them for line_codes which tell me what to do with the rest of the data. One line sets a most significant word of an address (MSW), another line sets the least significant…
Sambardo
  • 714
  • 2
  • 9
  • 15
25
votes
3 answers

Convert JSON String to Lua Table?

I need to convert a Json String to a table data structure in Lua. I am using the following code. local json = require "json" local t = { ["name1"] = "value1", ["name2"] = { 1, false, true, 23.54, "a \021 string" }, name3 =…
user3213851
  • 1,068
  • 2
  • 12
  • 24