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

Match repeatable string as a "whole word" in Lua 5.1

My environment: Lua 5.1 Absolutely no libraries with a native component (like a C .so/.dll) can be used I can run any arbitrary pure Lua 5.1 code, but I can't access os and several other packages that would allow access to the native filesystem,…
allquixotic
  • 1,481
  • 2
  • 18
  • 37
3
votes
2 answers

Decode UDP message with LUA

I'm relatively new to lua and programming in general (self taught), so please be gentle! Anyway, I wrote a lua script to read a UDP message from a game. The structure of the message is: DATAxXXXXaaaaBBBBccccDDDDeeeeFFFFggggHHHH DATAx = 4 letter ID…
3
votes
3 answers

Can I use Lua's require to set environment of the calling file?

Is there a way to call require in a Lua file, and have the module set the environment of the file that calls it? For example, if I have a DSL (domain specific language) that defines the functions Root and Sequence defined in a table, can I have…
Azure Heights
  • 271
  • 2
  • 8
3
votes
1 answer

Metatable is not indexed, even though setmetatable is used

According to the Lua manual, setmetatable still works the same as in Lua 5.0. Yet for some reason, when I try this code in Lua 5.1.5 and 5.3.1, it appears that the metatable is not accessed: ClassTable = {} ClassTable.getString = function(self) …
stands2reason
  • 672
  • 2
  • 7
  • 18
3
votes
1 answer

Lua environments when calling function within setfenv function

So I have a Lua script in which I set the environment of a function and define other functions that I make available in the environment. The issue is that when I call the function I did setfenv on, any function it calls within the environment uses…
Ford
  • 2,559
  • 1
  • 22
  • 27
3
votes
1 answer

Lua's string.find won't find pattern

I'm currently working on a program for my webpage in Lua 5.1 and got stuck in some strange stuff. file=io.open("articles/" .. string.sub(string,1) .. "_1250.html") fContent=file:read("*a") nic,start=string.find(fContent,"

string

IsawU
  • 430
  • 3
  • 12
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

Lua setfenv on threads doesnt seem to work

I want to load some functions on a lua state, and then be able to invoke the functions from lua threads. I am trying to setfenv on the threads, so that the variables created by them are confined to the threads and not appear in the global env.…
Ani
  • 1,448
  • 1
  • 16
  • 38
2
votes
1 answer

Resetting package.loaded after a test in Lua

I am developing unit tests in Lua and a major part of these tests is changing package.loaded. This goes from a = require "parser" a.b = nil to package.loaded["checker"] = function() return true end And the situation where I modify an entry of…
Cheiron
  • 3,620
  • 4
  • 32
  • 63
2
votes
2 answers

Why was Lua's newproxy deprecated and removed?

So in 5.1 of Lua, newproxy was deprecated. In 5.2, it got removed. But why? What should I use now to construct a userdata? I'm trying to implement pseudo-classes for fun and userdatas are way easier. They make implementing immutability and…
incapaz
  • 349
  • 1
  • 3
  • 11
2
votes
1 answer

Storing nested tables in nginx shared memory

I am working with open-resty and lua to create a server for redirecting requests. Redirects are done based on some data from a lua datatree structure (nested tables) I am looking for a way to populate this data once on startup and after that share…
djulb
  • 375
  • 1
  • 3
  • 19
2
votes
1 answer

LUA: Insert object to a table overrides other members of table

I need to create a table of objects in Lua. But when I insert a object into a table all members inserted before will change values. Hash code of all off these objects is different Rectangle = {area = 0, length = 0, breadth = 0} function…
djulb
  • 375
  • 1
  • 3
  • 19
2
votes
1 answer

Call to String.pack returns pack method not found

I'm running Zerobrane 1.8 and LUA 5.3. However, in the interpreter the string function does not have "pack()" method/sub-function, i.e., print(string.pack("
Shejo284
  • 4,541
  • 6
  • 32
  • 44
2
votes
1 answer

Lua 5.1 dll error: equals sign expected on line 1?

I have the following code: int luaopen_Library() { return 0; } Attempting to call require "Library" throws the following error: Library.dll:1: '=' expected How can I fix this? Please let me know if more information is needed; I am new to…
NetherGranite
  • 1,940
  • 1
  • 14
  • 42
2
votes
1 answer

How do I compile code that uses Lua 5.1's C API?

I have code that #includes the files lua.h, lapi.h, lualib.h, and lauxlib.h from Lua's source. Now I have to actually compile this code. My first thought is to include all of the .c files in the Lua's source code or just figure out which of those .c…
NetherGranite
  • 1,940
  • 1
  • 14
  • 42