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
2
votes
2 answers

Create new C library in lua

I want to know how i can create and use a new C library in lua 5.2.3. I can't use dynamic library (require, shared library, ...) due to I am on an embedded system. I found an answer but it is for lua 5.0 (http://www.lua.org/pil/26.2.html) and so it…
Subas
  • 65
  • 6
2
votes
2 answers

How to tell if a Lua line number is a valid execution point (from C/C++)?

How Can I tell if line number x in a Lua script will respond to the Lua line hook? Example: 1 first = 1 2 3 function test ( data ) 4 if first == 0 then 5 print ("\r\n") 6 end 7 print(data) 8 --[[ 9 first = 0 10 ]] 11 end 12 13…
Max Kielland
  • 5,627
  • 9
  • 60
  • 95
2
votes
2 answers

How to filter out user defined globals in Lua from C++?

Consider this small Lua test script. g1 = "Global 1" g2 = "Global 2" function test () local l1 print(g1,g2,l1) end test() Assume you pause the execution at print(g1,g2,l1) and from C++ get all the global variables with this C…
Max Kielland
  • 5,627
  • 9
  • 60
  • 95
2
votes
1 answer

Lua 5.2 redirecting the print function

Possible Duplicate: Redirecting/redefining print() for embedded Lua I am new to Lua and rather confused. I have seen this but Im not sure it works for 5.2. I have read about _ENV table(?) but again not sure if this has anything to do with it. So…
alfred
  • 639
  • 1
  • 6
  • 11
2
votes
3 answers

Why does 'if a == 40 or 42' evaluate as 'true' when 'a' is 47?

I am new to Lua, and trying to get something of this type done in my code, but its not working. Here the syntax and all is absolutely correct, but the elseif condition is going for a toss, and the conditional check is going wrong. So for this the…
ashutosh
  • 79
  • 3
  • 8
1
vote
1 answer

Is it safe to use "type" as a name/identifier in Lua?

OK, accordingly to PiL 2.1 – Lexical Conventions it should be possible since it's not listed as reserved keyword, but it's indeed used to return elements type like this type("whatever") and VS Code sometimes colorizes it and sometimes not depending…
Rai
  • 314
  • 1
  • 2
  • 9
1
vote
1 answer

Is there a way to pass/access global variables between different Lua environments created by the host program?

OK, first off, all this Lua environments concept is something I didn't thought I had to deal with, so I'm very green treating to speak about them, but I'll try to do my best... Until now, I've not had to deal with all this because most of the…
1
vote
2 answers

Why Lua's ternary operator is preventing my function to return several values?

As summary states. Lets say I want o resolve my ReturnFunction in a ternary operator fashion. Well, as far as I know, as long as my function returning several values (ReturnThreeValues) is placed at LAST position after ReturnFunction's return, the…
Rai
  • 314
  • 1
  • 2
  • 9
1
vote
1 answer

Lua userdata not available

I have some relatively simple Lua code, which links to some C and some Lua. local messages = {"Hello World!", "This is some test text", "This is a very long piece of test text with no sense of punctuation or common decency because I want to line…
James
  • 2,483
  • 2
  • 24
  • 31
1
vote
1 answer

How to call managed c++ dll functions in lua cpp module

Description: All my functions are defined in C# dll project.Then I wrap the c# functions in a cpp library project,Now I want to write a lua module using c++ and call the wrapper function. Question: How to call the wrapper functions in lua cpp…
ArisHu
  • 48
  • 1
  • 6
1
vote
1 answer

Emulating c++ 'using namespace' via _ENV

if I have a file foo.lua: local foo = {} foo.add = function(a, b) return a+b end foo.sub = function(a, b) return a-b end foo.multiply = function(a, b) return a*b end return foo and in bar.lua I make heavy use of code from foo.lua I am bothered by…
Ace shinigami
  • 1,374
  • 2
  • 12
  • 25
1
vote
0 answers

luaedit 3..0.10 will not show output from simple script

I am trying to get output from my first script in luaedit 3.0.10 and not having much success. I'm using the sample script from the online tutorial at http://lua.gts-stolberg.de/en/Mathe.php to wit: a = 2 + 1 print (a) I'm running luaedit under…
1
vote
1 answer

How to store a value type in a userdata?

This SO article is the same thing, but the answer is unhelpful because the answer was in Lua and the question was about the C-API. So I'm asking again. Hopefully, others will benefit from this question. I'm actually having 2 problems (I can't get…
101010
  • 14,866
  • 30
  • 95
  • 172
1
vote
1 answer

Read data before executing lua file

I want to read a table inside a Lua file before executing it. Is there a way to do this with loadfile. It returns only a function and I can't seem to be able to read what is inside (what is declared but not executed). The other option I tried is…
Gopoi
  • 113
  • 7
1
vote
1 answer

How do i read and write from/to a file in another directory?

I am trying to make a program that will write data to a file for another program to be able to read the data from it. The problem is that I can't figure out a way to do this when the file i am reading and writing from is in another directory than…