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

"For each" loop in a lua table with key value pairs

Say I have a table defined like this: myTable = { myValue = nil, myOtherValue = nil} How would I iterate through it in a for each fashion loop like this? for key,value in myTable do --pseudocode value = "foobar" end Also, if it helps, I…
sFuller
  • 1,305
  • 2
  • 14
  • 23
26
votes
1 answer

luaL_openlib replacement for Lua 5.2

I am adapting a library written for Lua < 5.2 and got to a call I don't know the equivalent of: luaL_openlib(L, "Polycore", polycoreLib, 0); Where polycoreLib is a static const struct luaL_Reg polycoreLib [] How can I replace the call to…
Appleshell
  • 7,088
  • 6
  • 47
  • 96
10
votes
2 answers

How to use Lua 5.2 with luasocket 3

I am trying to compile luasocket 3 that I found on GitHub with lua 5.2. Problem is, I'm not sure how to bind together Lua with luasocket. Do I need to compile luasocket as DLL and then reference if somewhere in lua code, or should I just call it…
miller
  • 1,636
  • 3
  • 26
  • 55
9
votes
5 answers

How to dump lua function chunk to string?

How to dump lua function chunk to string ? function test(a, b) local c = a + b return c end print( type(test) ) --> function print( test ) --> function: 0053B108 print( dumpToString(test) ) I wish dumpToString result is…
Flash
  • 1,615
  • 4
  • 17
  • 23
7
votes
3 answers

Recommended way to have 2+ modules recursively refer to each other in Lua 5.2

Is there a way to have Two Lua modules (let's call them A and B) Each module uses functions from the other, so they must require each other A third module (let's call it C) can use A but not B e.g. C.lua: local A = require 'A' --…
finnw
  • 47,861
  • 24
  • 143
  • 221
7
votes
2 answers

what is actual implementation of lua __pairs?

Does anybody know actual implementation of lua 5.2. metamethod __pairs? In other words, how do I implement __pairs as a metamethod in a metatable so that it works exactly same with pairs()? I need to override __pairs and want to skip some dummy…
user2872907
  • 71
  • 1
  • 2
7
votes
1 answer

Call a Lua function from C++

I have google high and low and found examples, but none of them seems to work (Lua 5.2). I have a simple function in Lua function onData ( data ) print ( data ) end I want to call onData from C++ and tried this: // Create new Lua state L =…
Max Kielland
  • 5,627
  • 9
  • 60
  • 95
6
votes
1 answer

Porting to Lua 5.2, LUA_GLOBALSINDEX trouble

In the code example: http://lua-users.org/wiki/SimplerCppBinding There is the code: lua_pushstring(L, T::className); lua_pushvalue(L, methods); lua_settable(L, LUA_GLOBALSINDEX); //<--- LUA_GLOBALSINDEX removed in Lua 5.2 lua_pushliteral(L,…
Jamin Grey
  • 10,151
  • 6
  • 39
  • 52
6
votes
1 answer

Loop through all Lua global variables in C++

I have been searching for quite a while now and I haven't found a way to fetch all the global variables from C++. Consider this small Lua test script. myGlobal1 = "Global 1" myGlobal2 = 2 function test() local l1=0 print…
Max Kielland
  • 5,627
  • 9
  • 60
  • 95
6
votes
2 answers

Lua 5.2 issue: 'attempt to call a nil value' from lua_pcall

I'm having problems getting a Lua 5.2 function to get called from C++. This is the Lua chunk (named test.lua): function testFunction () print "Hello World" end And this is the C++: int iErr = 0; //Create a lua state lua_State *lua =…
user2795503
  • 198
  • 2
  • 7
6
votes
2 answers

Debugging embedded Lua 5.2.2 code

How can I debug Lua 5.2.2 code that is embedded inside of my C++ application? I have already taken a look at this question and all the IDEs provided in it deal with 5.1 and lower and when I try to use them with 5.2.2 they crash.
Caesar
  • 9,483
  • 8
  • 40
  • 66
5
votes
1 answer

Loading a file and returning its environment

I'm attempting to do the following : (include() code below) File1.lua A = 5 File2.lua file1 = include(File1.lua) A = 1 print(A) -- 1 print(file1.A) -- 5 i've found exactly what i'm looking for but in lua 5.1 here : Loadfile without polluting…
TomB
  • 53
  • 3
5
votes
1 answer

Calling Lua 5.2 function from C++

I'm pretty new to Lua. I've been looking at some sample code for how to call a Lua function from C++, but the sample code uses 5.1, and I'm trying to get this to work with 5.2. Here is the sample code in question with my comments: lua_State…
user2135428
  • 61
  • 1
  • 4
4
votes
4 answers

Lua How to tell 1 from 1.0

I have a configuration script where the user can enter values either as an absolute value or a percentage value. Absolute values are written as a value between 0.0 and 1.0 while percentage value are written as 0 to 100. How can I distinguish 1 from…
Max Kielland
  • 5,627
  • 9
  • 60
  • 95
4
votes
1 answer

Porting from Lua 5.1 to 5.2

I'm having some issues porting some older Lua 5.1 code to Lua 5.2. I would like to be able to use the stock Lua 5.2 dll/lib, so any porting would need to be completed using the existing API for Lua 5.2. To make it a little more complicated, I'm…
SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
1
2 3 4 5