Questions tagged [lua-5.2]

Some new features are yieldable pcall and metamethods, new lexical scheme for globals, ephemeron tables, finalizers for tables etc.

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.

Lua 5.2 was released on 16 Dec 2011. More info on Lua's version history can be checked here. A list of new features in Lua 5.2 is as follows:

  • Yieldable pcall and metamethods.
  • New lexical scheme for globals.
  • Ephemeron tables.
  • New library for bitwise operations.
  • Light C functions.
  • Emergency garbage collector.
  • goto statement.
  • Finalizers for tables.
69 questions
4
votes
2 answers

Get n-th element from end of list (table)

If I have a list (table): local list = {'foo', 'bar', 'baz', 'qux'} How do I get the n-th item from the end? (e.g., the last or second to last)
Uyghur Lives Matter
  • 18,820
  • 42
  • 108
  • 144
4
votes
2 answers

Build Lua 5.2.2 in Windows

I already have Lua For Windows installed but as I read about the latest version of Lua which is 5.2.2, I noticed that Lua For Windows is using an old version of Lua which is 5.1. I want to build the latest lua version to my windows 7 pc, but I…
Netorica
  • 18,523
  • 17
  • 73
  • 108
4
votes
2 answers

Hiding a Lua metatable and only exposing an object's attributes

How do you create a Lua object that only exposes its attributes and not its methods? For example: local obj = { attr1 = 1, attr2 = 2, print = function(...) print("obj print: ", ...) end, } Produces: > for k,v in pairs(obj) do print(k,…
Sean
  • 9,888
  • 4
  • 40
  • 43
4
votes
0 answers

Adding an SQL extension to a precompiled Lua 5.2 project

I have looked into at least 6 different SQL Lua extensions, and they all seem to have their latest version compatible with up to version 5.1 of Lua. I have had zero success in implementing any of them into my current project which uses Lua 5.2, with…
RectangleEquals
  • 1,825
  • 2
  • 25
  • 44
3
votes
1 answer

Lua 5.2 metatables and environment

I've got a structure like this: context = { pi = math.pi, sin = math.sin, cos = math.cos, tan = math.tan, print = print } modules = { m1 = { variables = { x = 1 }, update = function(self) local _ENV = self.variables …
Tom
  • 7,269
  • 1
  • 42
  • 69
3
votes
1 answer

Execute Lua 5.1 Code in a Lua 5.2 Environment

I am in a pure Lua 5.2 environment and I need to execute Lua 5.1 code. This code is arbitrary code from the user, so I can't port to Lua 5.2 in advance. As far as I can see, this would entail reimplementing getfenv/setfenv, changing the _VERSION…
programmedpixel
  • 368
  • 1
  • 3
  • 8
3
votes
1 answer

Lua5.2 embedded in C++

I'm trying for the first time to have Lua embedded in C++. I've been searching for 2 days now, but most of internet tutos use lua5.1, which is incompatible with lua5.2. So I read a bit of lua documentation, example source code, and I end up with…
Vulpo
  • 873
  • 1
  • 9
  • 25
3
votes
2 answers

How to return C++ object to lua 5.2?

How to return C++ object to lua? My C++ code is following: class MyClass { public: void say() { print("Hello\r\n"); } }; int test(lua_State* l) { MyClass* obj = new MyClass(); lua_pushlightuserdata(l, obj); return 1; } Lua Test is…
Flash
  • 1,615
  • 4
  • 17
  • 23
3
votes
2 answers

Possible match for (seemingly) invalid Lua-pattern

I know that you can't repeat match groups in Lua. For example, if I wanted to match the two successive "45"'s, I can't do: print(string.find("some 4545 text", "(%d%d)+")) which will print nil (no match found). However, since find(...) doesn't…
Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
2
votes
1 answer

Calling Lua Function from C: Minimal example results in LUA_ERRRUN

I want to call an external lua_5.2 function from C, so I made a minimal example to try it out. The minimal testfile: --- filename: play.lua function hello() print("Hello World!\n") end Trying to call this function from C: #include…
kollie
  • 86
  • 5
2
votes
1 answer

Lua c API change library after creation

I am trying to wrap ncurses in Lua using the C API. I am working with the stdscr pointer: This is NULL before initscr is called, and initscr is called from Lua by design of my bindings. So in the driver function I do this: // Driver…
AlgoRythm
  • 1,196
  • 10
  • 31
2
votes
1 answer

Storing and Returning Lua Userdata

I have the following classes in C++ class B; class A { B* GetB(); void SetB(B*& b) { _b = b;}; private: B* _b; } And part of the lua binding code: int A::setB(lua_State* L) { A* a = checkA(L,1) // Macro for luaL_checkudata B*…
Moop
  • 3,414
  • 2
  • 23
  • 37
2
votes
1 answer

Amusing behavior '...' in Lua

It's not a problem. Just Lua is amazing. t = {1, 2, 3} print(table.unpack(t)) -->1 2 3 print(0, table.unpack(t)) -->0 1 2 3 print(table.unpack(t), 4) -->1 4 What?
Bogdan
  • 43
  • 3
2
votes
2 answers

Cannot get a Lua function to reference 'self'

I'm trying to create a simple class with a member function that would print out some member values, but I'm getting errors when I try to reference 'self': attempt to index global 'self' (a nil value) Here's the script I'm trying to run: Test =…
manabreak
  • 5,415
  • 7
  • 39
  • 96
2
votes
0 answers

How pass a table parameter from a lua function to a C function

I would like to know how I can pass a parameter table from a lua function to a C function. I found some example but they didn't explain how we can get back our table in our C function. If we pass a number from lua to C, we use luaL_checkint it's…
Subas
  • 65
  • 6