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
1 answer

Errors when including hyphens in table variables

I recently bought MaterialBoard from ScriptFodder. I am editing the groups list so it will show the capitalized & un-hyphened group names so instead of head-admin it would look like "Head Admin". Everything has worked so far but once it started…
JacobRocks12
  • 81
  • 1
  • 1
  • 7
5
votes
6 answers

Uploading a Lua script to NodeMCU using Wifi

Is it possible to upload a Lua script to a NodeMCU using the Wifi interface instead of serial? The tutorials and examples that I have found all use the serial interface, i.e. a cable, to program the NodeMCU, but I would like to change the program…
user2518618
  • 1,360
  • 13
  • 32
5
votes
1 answer

Lua table - two entries with same key

I'm not sure how, but we managed to create a table with two keys exactly same. When performing for loop over pairs of the table and printing keys and values we get: 1 true 1 true and we thought maybe it's a matter of different types or…
Krystian
  • 3,193
  • 2
  • 33
  • 71
5
votes
2 answers

Lua syntax highlighting latex for arXiv

I have a latex file which needed to include snippets of Lua code (for display, not execution), so I used the minted package. It requires latex to be run with the latex -shell-escape flag. I am trying to upload a PDF submission to arXiv. The site…
Nicholas Leonard
  • 2,566
  • 4
  • 28
  • 32
5
votes
2 answers

Call torch7 (Lua) function from python?

I have a program is written in python and I have model ConvNet trained using Toch7. I would like to call forward and backpro to the model from python program as I find difficult and hard to write it again in lua. Any idea please?
S.AMEEN
  • 1,461
  • 4
  • 16
  • 23
5
votes
2 answers

How do I convert a lua string to a C char*?

I've used the luajit ffi library to wrap a C library that contains a function to draw text on a ppm file: void drawText(frameBuffer *fb, int px, int py, char* text, pixel color) When I try to call it from lua using a string I get this error bad…
BarFooBar
  • 1,086
  • 2
  • 13
  • 32
5
votes
2 answers

Lua - Perlin Noise Generation - Getting bars rather than squares

I'm currently learning Löve 2d/Lua and trying my hand at generating noise using the Perlin Noise algorithm. I've adapted Ken Perlin's Improved Noise code here: Code edited with fixes per Doug's answer -- original code by Ken Perlin:…
GHandel
  • 172
  • 2
  • 3
  • 13
5
votes
3 answers

local variable cannot be seen in a closure across the file?

Suppose I have the following two Lua files: In a.lua: local x = 5 f = dofile'b.lua' f() In b.lua: local fun = function() print(x) end return fun Then if I run luajit a.lua in shell it prints nil since x cannot be seen in the function defined in…
peng sun
  • 51
  • 3
5
votes
1 answer

Asynchronous duplication request with nginx

How I can duplicate (or create and send) a request with the nginx web server. I can't use post_action, because it is a synchronous method. Also, I compiled nginx with Lua support, but if I try to use http.request with ngx.thread.spawn or coroutine,…
Dmitro
  • 1,870
  • 3
  • 16
  • 25
5
votes
1 answer

Why does my code only print nil once?

It's super-easy to fix; simply make it return nil, but why doesn't my code work without that line? function x(bool) if bool then return "!" end end print(x(true), x(false), x(false)) What makes it even more confusing, is that…
warspyking
  • 3,045
  • 4
  • 20
  • 37
5
votes
4 answers

Improving Lua error messages

Whenever an error occurs in a Lua script, I'd like it to write the values of all local and global variables to the screen/optionally to a file - in addition to the usual stack trace. How could I get this to be the default behavior for all errors?
proFromDover
  • 441
  • 5
  • 11
5
votes
1 answer

Reuse coroutine with different arguments per call in lua

I found it really useful to reuse a once created coroutine. I found a solution to that and it looks like so: co = coroutine.create(function (f, args) while f do f = coroutine.yield(f(args)) end end) function dummyFunc(data) print("XXX…
milkpirate
  • 267
  • 1
  • 18
5
votes
2 answers

Regular expressions in Lua using .gsub()

Ok, I think I overcomplicated things and now I'm lost. Basically, I need to translate this, from Perl to Lua: my $mem; my $memfree; open(FILE, 'proc/meminfo'); while () { if (m/MemTotal/) { $mem = $_; $mem =~…
OddCore
  • 1,534
  • 6
  • 19
  • 32
5
votes
1 answer

Redis Lua scripting with large loops

Which of the following loops will run quicker in a Redis Lua Script for 10,000 iterations. Or will they both run at the same speed. Does accessing a redis key inside a lua script take the same amount of time as accessing a local variable, e.g a…
Joe Andrews
  • 151
  • 2
  • 10
5
votes
1 answer

pcall with variable argument in lua

I am looking for a way to pcall a function which has variable arguments in lua5.3. I am hoping for something like this function add(...) local sum=arg + ... return sum end stat,err=pcall(add,...) thanks
bislinux
  • 193
  • 2
  • 3
  • 12