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
4 answers

What's the difference between these two Lua examples? Is one better?

I'm just getting started with Lua. In the example I'm learning from (the Ghosts & Monsters Corona open source), I see this pattern repeatedly. local director = require("director") local mainGroup = display.newGroup() local function main() …
5
votes
3 answers

Caching expensive table calculation on strings between separate function calls in Lua

I have a number of functions operating on strings to extract interesting properties from those strings. One particular function which is called by many of those functions is very expensive and ultimately generates a table of values: local function…
ruser9575ba6f
  • 258
  • 1
  • 10
5
votes
3 answers

How to asynchronously load and train batches to train a DeepLearning model?

I have 3TB dataset and 64GB RAM and a 12 core CPU and one 12GB GPU. would like to train a deep learning model on this dataset. How do I have asynchronous load of batches and training of the model? I want to make sure disk load of data doesn't block…
Morteza Shahriari Nia
  • 1,392
  • 18
  • 24
5
votes
2 answers

Parsing a JSON string that is bigger than the memory

The platform I'm working on has pretty tight memory constraints and I'm trying to find a way to parse big JSON strings without ever loading more than a few hundred bytes at max into the memory. The JSON string is stored in a file on a much bigger…
Forivin
  • 14,780
  • 27
  • 106
  • 199
5
votes
1 answer

Is it possible to load .net dll from Lua code?

I know how to load a C library from Lua: -- Lua require("your_dll_name"); // C extern "C" __declspec(dllexport) LUALIB_API int luaopen_your_dll_name(lua_State *L) {...} But is it possible to load .net libraries from Lua?
sibvic
  • 1,622
  • 2
  • 12
  • 19
5
votes
1 answer

wrk how to install additional lua modules

I am using mac OSX. I have Lua installed through brew and Luarocks. I have the lua sockets package installed too. When I call local http = require("socket") from the terminal lua command line interface, the module loads fine. However when I include…
Sakib
  • 1,503
  • 4
  • 26
  • 39
5
votes
1 answer

NodeMCU UDP DNS request format

I am looking at this example of a captive portal built on a NodeMCU platform, and I am trying to understand how DNS requests work. (The relevant file is dns-liar.lua) I have more or less decoded what the response is, but have no idea what each part…
Aaron
  • 10,133
  • 1
  • 24
  • 40
5
votes
4 answers

What is the proper Lua pattern for quoted text?

I've been playing with this for an hour or tow and have found myself at a road block with the Lua pattern matching utilities. I am attempting to match all quoted text in a string and replace it if needed. The pattern I have come up with so far is:…
Wolftousen
  • 147
  • 2
  • 8
5
votes
2 answers

Lua - understanding setmetatable

I am trying to build a CNN using Torch 7. I am very new to Lua. I was trying to follow this link. I encountered something called setmetatable in the following code block: setmetatable(train_set, { __index = function(t, i) return {t.data[i],…
skr
  • 914
  • 3
  • 18
  • 35
5
votes
1 answer

Checking for items in tables Lua

I have an input file Corn Fiber 17 Beans Protein 12 Milk Protien 15 Butter Fat 201 Eggs Fat 2 Bread Fiber 12 Eggs Cholesterol 4 Eggs Protein 8 Milk Fat 5 This is loaded into a table. I can then run commands to check the value of the items. For…
Reubens4Dinner
  • 343
  • 4
  • 15
5
votes
3 answers

Pattern not matching *(%(*.%))

I'm trying to learn how patterns (implemented in string.gmatch, etc.) do work in Lua 5.3, from the reference manual. (Thanks @greatwolf for correcting my interpretation about the pattern item using *.) What I'm trying to do is to match '(%(.*%))*'…
user5066707
5
votes
1 answer

Passing a C# object into a lua function with moonsharp.

I'm having issues using Moonsharp in Unity3d. I'm trying to pass 'AppletMessage' objects: [MoonSharpUserData] public class AppletMessage { public string Name; public string[] Args; public AppletMessage(string _name, string[] _args) { …
T--
  • 53
  • 6
5
votes
2 answers

How to parse protobuf packets in Wireshark

My goal is to have a plugin/dissector that can parse a protocol based on protobuf (UDP). I found on the web an Auto-generate Wireshark/Ethereal dissector plugins for Protocol Buffer messages:…
B. Nir
  • 109
  • 2
  • 3
  • 12
5
votes
1 answer

How to pass a tuple as arguments to a Lua function?

Is there a way to pass a tuple as the parameters of a Lua function? For example, I have a function that returns multiple values function f(a,b) return b,a end and I want this function f to be repeatedly applied, so I can write: f (f ...…
thor
  • 21,418
  • 31
  • 87
  • 173
5
votes
1 answer

HAproxy+Lua: Return requests if validation fails from Lua script

We are trying to build an incoming request validation platform using HAProxy+Lua. Our use-case is to create a LUA scripts that will essentially make a socket call to a Validation API, and based on the response from Validation API we want to redirect…
Geek
  • 1,369
  • 1
  • 14
  • 25