Questions tagged [lua-5.1]

The v5.1 of the Lua scripting language.

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.

Lua is an extension programming language designed to support general procedural programming with data description facilities. It also offers good support for object-oriented programming, functional programming, and data-driven programming. Lua is intended to be used as a powerful, light-weight scripting language for any program that needs one. Lua is implemented as a library, written in clean C (that is, in the common subset of ANSI C and C++).

Being an extension language, Lua has no notion of a "main" program: it only works embedded in a host client, called the embedding program or simply the host. This host program can invoke functions to execute a piece of Lua code, can write and read Lua variables, and can register C functions to be called by Lua code. Through the use of C functions, Lua can be augmented to cope with a wide range of different domains, thus creating customized programming languages sharing a syntactical framework. The Lua distribution includes a sample host program called lua, which uses the Lua library to offer a complete, stand-alone Lua interpreter.

Lua is free software, and is provided as usual with no guarantees, as stated in its license. The implementation described in this manual is available at Lua's official web site.

70 questions
8
votes
1 answer

Eval function in LUA 5.1

I want to use an eval function in Lua, Can't make it work. Did not find documentation on it, does Lua even have an eval function ? Code tried : a=1 print(a) eval('print(a)') eval 'print(a)' Official Lua demo interpreter :…
Eli O.
  • 1,543
  • 3
  • 18
  • 27
7
votes
3 answers

Convert signed IEEE 754 float to hexadecimal representation

I'm using a front-end of Lua which is unfortunately outdated, so I'm stuck with version 5.1 here, meaning the bit32 library is out of reach (which I probably could have used to convert this). So I'm wondering if anyone knows of a way I could…
user966939
  • 692
  • 8
  • 27
6
votes
2 answers

Get Lua table size in C

How can I get a size of a Lua table in C? static int lstage_build_polling_table (lua_State * L) { lua_settop(L, 1); luaL_checktype(L, 1, LUA_TTABLE); lua_objlen(L,1); int len = lua_tointeger(L,1); printf("%d\n",len); …
briba
  • 2,857
  • 2
  • 31
  • 59
6
votes
2 answers

Behavior of load() when chunk function returns nil

From the Lua 5.1 documentation for load(): Loads a chunk using function func to get its pieces. Each call to func must return a string that concatenates with previous results. A return of an empty string, nil, or no value signals the end of the…
cdhowie
  • 158,093
  • 24
  • 286
  • 300
5
votes
2 answers

Parsing a JSON string that is bigger than the memory

The platform I'm working on has pretty tight memory constraints and I'm trying to find a way to parse big JSON strings without ever loading more than a few hundred bytes at max into the memory. The JSON string is stored in a file on a much bigger…
Forivin
  • 14,780
  • 27
  • 106
  • 199
4
votes
4 answers

Is using lua's error(.., level) an anti pattern?

Lua 5.1's API provides an error() function, which accepts a string (the error message) and a "level". My understanding is that level, lets you move up the call stack, so you can provide nicer error reporting, especially when delivering a module as…
4
votes
2 answers

How to make lua search modules that are in the same folder with the module in which require is called first?

say I've a project folder like: mxn:lab axn$ tree . . ├── lib │ ├── a.lua │ └── b.lua └── main.lua where main.lua: require("lib.a") and in a.lua I just use the string "b", trying to tell lua - find a file whose name is b.lua in the same folder…
tcpiper
  • 2,456
  • 2
  • 28
  • 41
4
votes
1 answer

How to create table in table in Lua 5.1 using C-API?

I need to create construction like this in Lua 5.1 C-API, not in Lua 5.2 and above a = {["b"] = {["c"] = {["d"] = {["e"] = "GOOD"}}}} print(a.b.c.d.e); Expected Result: GOOD Thanks for answers!
BORSHEVIK
  • 794
  • 1
  • 8
  • 12
4
votes
2 answers

add luasocket to program (bizhawk) shipped with own lua environment

I am trying to get luasocket working in the lua scripting environment of Bizhawk, but so far without luck. I downloaded the vc8 version of luasocket here, made sure I have vc8 installed, and checked the lua version that came with bizhawk: 5.1 But,…
Felk
  • 7,720
  • 2
  • 35
  • 65
4
votes
1 answer

Lua 5.1 workaround for __gc metamethod for tables

I'm currently facing the problem that you can't use the __gc method for tables in Lua 5.1, as they are implemented in Lua 5.2. However, I want to release allocated native resources once the lua table gets collected. Is it possible to make a…
Turakar
  • 180
  • 2
  • 13
4
votes
1 answer

Check for valid domain

I want to add to this function Domain checking: GetType = function(ip) local Split = function(s,sep) local t={};i=1 for str in string.gmatch(s,"([^"..sep.."]+)") do t[i] = str i = i + 1 end return t end local R =…
Col_Blimp
  • 779
  • 2
  • 8
  • 26
4
votes
1 answer

Adding SASL Auth in IRC Bot

How could i add sasl authentication on my Lua 5.1 IRC Bot? Right now it sends a message to Nickserv to identify. Is there any way at all to add SASL authentication? I use the lua socket module to connect to IRC. The complete source can be found at…
wolfy1339
  • 784
  • 2
  • 7
  • 23
4
votes
1 answer

Why is 'name' nil for debug.getinfo(1)

I'm trying to put together a lua testing framework that lets you know the function that had the problem, but when I switched from loadstring to _G, (I switched so my test harness could see the results of the function call) my functions started using…
Joshua Olson
  • 3,675
  • 3
  • 27
  • 30
4
votes
2 answers

Is the lua_State pointer passed to lua_CFunctions guaranteed to point to the same state as was used to invoke the function?

Context: I am working on a set of bindings, and many of my functions reference the "global" Lua state. (It's not actually global in the code I am developing, but local to the particular runtime instance, so global in that all of the callback…
cdhowie
  • 158,093
  • 24
  • 286
  • 300
3
votes
2 answers

Include empty matches when using string.gmatch to split a string in lua 5.1

I have a comma seperated input string that needs to support empty entries. So a string like a,b,c,,d should result in a table with 5 entries, where the 4'th is an empty value. A simplified example str="a,b,c,,d" count=0 for v in string.gmatch(str,…
Daniel
  • 10,641
  • 12
  • 47
  • 85
1
2 3 4 5