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

Lua - Local variable scope in function

I have the following function function test() local function test2() print(a) end local a = 1 test2() end test() This prints out nil The following script local a = 1 function test() local function test2() print(a) …
spurra
  • 1,007
  • 2
  • 13
  • 38
5
votes
1 answer

Lua script throws error "attempt to call a nil value (field 'deposit')"

I have this Lua script, which is supposed to create a new class, create an instance and call functions, but there's an error in which I actually call the methods. Account = { balance = 0, new = function(self,o) o = o or {} …
phriol
  • 101
  • 1
  • 1
  • 7
5
votes
0 answers

Windows: fatal error C1083: Cannot open include file: 'lua.h': No such file or directory

I have tried to some requirements for a python project in windows, using pip install -r requirements.txt, however this keeps failing. After some investigation I have found that it fails because of lupa. Running "pip install lupa" shows the same…
5
votes
1 answer

Cross compiling Lua and libs for embedded ARM device

Whats the best procedure to cross compile lua and libs (luasockets, orbit, etc) for an embedded arm device. Im able to succesfully cross compile lua interpreter, but from there im a little bit lost.
gipsh
  • 578
  • 1
  • 3
  • 20
5
votes
3 answers

Why is lua so slow in redis? Any workarounds?

I'm evaluating the use of lua scrips in redis, and they seem to be a bit slow. I a benchmark as follows: For a non-lua version, I did a simple SET key_i val_i 1M times For a lua version, I did the same thing, but in a script: EVAL "SET KEYS[1]…
Sam Lee
  • 9,913
  • 15
  • 48
  • 56
5
votes
1 answer

How to convert a Redis ArrayRedisResult into a C# array?

I would like to convert an array table returned by Redis to be used in my C# code. How can I do that ? After debugging the code, I can see that he returns an ArrayRedisResult string script = @"return redis.call('HGETALL', @key)"; LuaScript lScript…
eddy0223
  • 103
  • 1
  • 1
  • 7
5
votes
1 answer

Lua - Are numbers floats or doubles?

The Lua documentation says that Lua represents values of type number using a double, which allows all long integer values to be correctly represented using a floating point number. However I see in the code that lua_Number is actually a float. Which…
Virus721
  • 8,061
  • 12
  • 67
  • 123
5
votes
1 answer

Aerospike NodeJS UDF Aggregation Error

I've created an aggregate function which works in aerospike which works in AQL: AGGREGATE filter2.check_teamId('123', 0, 1456499994597) ON analytics.tracking WHERE teamId = '123' This returns results. I'm then trying to use the same UDF in…
TStu
  • 244
  • 3
  • 15
5
votes
2 answers

How to register C++ class constructor to Lua userdata and use it by default

Using the Lua C API, I registered a simple Object class to Lua, like this: // My C++ Object class class Object { private: double x; public: Object(double x) : x(x){} }; // Create and return instance of Object class to Lua int…
Erunehtar
  • 1,583
  • 1
  • 19
  • 38
5
votes
2 answers

How do you do the Fisher-Yates shuffle in Lua

I've been asking questions on random numbers, and I decide the Fisher-Yates shuffle would be the best option. I make a table 't' t = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Now, how would I even shuffle these and be able to use them individually, for…
ZackaryCW
  • 113
  • 1
  • 7
5
votes
1 answer

Torch / Lua, which neural network structure for mini-batch training?

I'm still working on implementing the mini-batch gradient update on my siamese neural network. Previously I had an implementation problem, that was correctly solved here. Now I realized that there was also a mistake in the architecture of my neural…
DavideChicco.it
  • 3,318
  • 13
  • 56
  • 84
5
votes
3 answers

Lua - Reseting the state of a script without reparsing it

I have an application that runs Lua scripts. Each Lua script is likely to run several times. Some scripts may even run every time a key is pressed. I would like these scripts to be "reset" between each run. I.e if a user sets a variable Foo, then…
Virus721
  • 8,061
  • 12
  • 67
  • 123
5
votes
1 answer

Lua error to create a class

I'm trying to create a class for my game and I got this error (shown in love2d): attempt to index upvalue 'World' (a boolean value) This is my World file I made: local World = {} World.__index = World function World:new(meter, gravity) …
Jazzguy
  • 147
  • 1
  • 11
5
votes
4 answers

how to write private function in lua class

I'm trying to write a lua "class" with a private function like this: local myTable = {} function myTable.func() private() end local function private() print(":O") end return myTable Let's say I'll require myTable and then run…
user1191220
5
votes
3 answers

Accessing Lua Functions On Other Files

I want to separate my Lua file into two files: one that holds my functions and one that can call them. I have done a lot of research on this and all the resources I find do not explain this process very in depth. They typically say to use: require…
OT2O
  • 129
  • 2
  • 3
  • 8