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

Why should we use lua_pushinteger()?

The current versions of Lua don't support integer numbers, only floats. (With the upcoming 5.3 this is changing, but let's ignore this.) So, my question is: what use there is in lua_pushinteger()? If the numbers get cast into a float, why not use…
Niccolo M.
  • 3,363
  • 2
  • 22
  • 39
5
votes
1 answer

Lua C API: Retrieve values from Lua function returning a table in C code

Despite searching hard, i couldn't find a valid Lua C API example for calling a Lua function returning a table. I'm new to Lua and the Lua C API, so don't assume too much. However i can read and have understood the principle of loading a Lua module…
Scrontch
  • 3,275
  • 5
  • 30
  • 45
5
votes
1 answer

How do you bind C++ member methods and member variables with the Lua C API?

All the googling I've done so far has turned up things that are very close but just aren't quite cutting it for what I'm trying to do. Let me describe this in the most basic way possible: Imagine you have a C++ class class A { public: int…
relaxok
  • 141
  • 8
5
votes
1 answer

Java to Lua socket communication error

Okay, so I have a project where I'm working with a Client (written in Lua) and a Server (written in Java). I'm using LuaSocket for the client and DatagramSockets for the server. The problem is when I send one string from the client in Lua, and…
5
votes
1 answer

Why can't I catch a luabind::error exception when my lua code throws an error?

When you call a LUA function from c++ and there is a runtime error LuaBind throws a luabind::error exception that you can catch and then read the stack to see what the error was. My debugger definitely catches this exception but when I let the…
Sean Dawson
  • 5,587
  • 2
  • 27
  • 34
5
votes
3 answers

Date after number of days in lua scripting

I am new to lua scripting. I have a startDate ("03-05-2014" as "dd-mm-yyyy") and a span in days (2) Can anyone help me how to get the endDate based on the startDate and span?. Example startDate span endDate --------- ----…
Vijay
  • 71
  • 1
  • 2
  • 11
5
votes
1 answer

Lua table access efficiency

I have a question about accessing data in a Lua table. Say, there is a large Lua table like following: tbl = { { blockIdx = 5, key1 = "val1", key2 = "val2", ... }, { …
Wayne Dimart
  • 85
  • 1
  • 8
5
votes
1 answer

In Lua, does indexing a table with a table as the key call the __eq metamethod?

I am wondering if table[key] where key is a table with a metatable will call the __eq metamethod. For instance, if the table has a key "a" and the __eq metamethod returns true if "a" is being compared to the metatable, will indexing the table with…
Hal
  • 219
  • 2
  • 12
5
votes
1 answer

Lua 'end' expected (to close 'function' at line near ''

I cannot find where the missing end is, iI have double checked and triple checked the syntax and its driving me mad. I have tested compilation online and locally so my specific question here is why is the error being thrown? Here is the error: line…
kyle
  • 129
  • 1
  • 3
  • 10
5
votes
2 answers

How does swapping of variable works in Lua?

In the below code, could anyone please explain how b,a = a,b internally works? -- Variable definition: local a, b -- Initialization a = 10 b = 30 print("value of a:", a) print("value of b:", b) -- Swapping of variables b, a = a, b print("value of…
Prabhakar
  • 402
  • 6
  • 20
5
votes
2 answers

Awesome WM: move/resize maximized floating windows

In a float-layout, or when having windows floating in any other layout, it is impossible to move/resize them when they're maximized. I would however like to be able to drag/resize them out of the maximized state. This doesn't seem to…
JorenHeit
  • 3,877
  • 2
  • 22
  • 28
5
votes
3 answers

how do I clean up my lua state stack?

I am using the lua C-API to read in configuration data that is stored in a lua file. I've got a nice little table in the file and I've written a query C-function that parses out a specific field in the table. (yay it works!) It works by calling a…
ohmyfromage
  • 133
  • 1
  • 5
5
votes
4 answers

How to obfuscate lua code?

I can't find anything on Google for some tool that encrypts/obfuscates my lua files, so I decided to ask here. Maybe some professional knows how to do it? (For free). I have made a simple game in lua now and I don't want people to see the code,…
user3036459
5
votes
1 answer

Add seconds to an existing date in Lua

I want to calculate time in Lua. For example: I want to get the current date (incl. at least seconds) and then I want to add seconds to this date that I get a date which is in the future.
Bioaim
  • 928
  • 1
  • 13
  • 26
5
votes
2 answers

Lua - Get current day?

I do not know where to ask about this kinda stuff so I thought why not ask Stackoverflow? I wonder if it's possible to get the current day somehow, with Lua? Something about os.date() but I have no idea how to do it. Or maybe os.time() ? like: local…
user3036459