Questions tagged [lua-5.3]

A lightweight multi-paradigm programming language designed as a scripting language with extensible semantics as a primary goal.

Lua (/ˈluːə/ LOO-ə, from Portuguese: lua [ˈlu.(w)ɐ] meaning moon; explicitly not "LUA") is a lightweight multi-paradigm programming language designed as a scripting language with extensible semantics as a primary goal. Lua is cross-platform since it is written in ANSI C.

Lua has a relatively simple C API.

Wikipedia: http://en.wikipedia.org/wiki/Lua_%28programming_language%29

49 questions
3
votes
1 answer

Should we explicitly cast from Lua's luaL_checkinteger() et al?

Lua 5.3 deprecates luaL_checkint, luaL_checklong, luaL_optint, luaL_optlong, which were just convenience macros calling luaL_{check|opt}integer. While we can still use them (because of -DLUA_COMPAT_5_2), they aren't mentioned in the user manual and…
Niccolo M.
  • 3,363
  • 2
  • 22
  • 39
2
votes
1 answer

Why lua require won't search current directory?

say I've two files test.lua and m.lua in a folder, in test.lua as: require("m") then I run this file, howerver it raise an error: lua: /Users/xx/works/scripts/test.lua:43: module 'm' not found: no field package.preload['m'] no file…
tcpiper
  • 2,456
  • 2
  • 28
  • 41
2
votes
1 answer

Managing Lua 5.3 ".0" behavior

In Lua 5.3, when a number is a float without any decimal part, printing it adds ".0" to the end of it, giving me the wrong answer in golf and speed competitions. Rounding or ~~x or x|0 forces it to be an integer type, but for a problem like "find…
Waffle
  • 190
  • 9
2
votes
2 answers

Why isn't my LUA interpreter able to handle string key values?

When testing code with both a predefined script and the LUA runtime environment, LUA will not take any form of string key values. However, if a numerical value key is used LUA will work with it as intended. The exception to this rule when I am using…
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

Why is lua not respecting my SIGINT signal

I'm running a Lua code. (attached below). The code runs fine but when I try to send a SIGINT using CTRL + C it does not respect it. local ltn12 = assert(require('ltn12')) local cjson = assert(require('cjson')) local http =…
Ratatouille
  • 1,372
  • 5
  • 23
  • 50
2
votes
1 answer

Get Reference to Calling Function in Lua

I know I can use debug.getinfo(1, "n").name to get the calling function's name, but I would like to get a reference to that function pointer itself. For debug.getlocal(), the f parameter is the stack position so I can easily get the locals for the…
Moop
  • 3,414
  • 2
  • 23
  • 37
2
votes
1 answer

utf8.offset: how to specify starting positions?

How can I use utf8.offset(s, n, i) to find the offset of the character at n starting from specific byte and character positions? The i parameter is documented as: Returns the position (in bytes) where the encoding of the n-th character of s…
user5066707
2
votes
1 answer

Arguments that I pass to a lua script are nil

I am writing a Lua 5.3 program and it requires arguments to be passed to it. I use the arg table to get the first argument: arg[1], but the 1st argument, according to the script, is nil even though I have passed an argument to the file. Here's the…
2
votes
2 answers

How to correctly redefine print in Lua 5.3?

I frequently use print function for debugging in conjunction with os.exit(). I don't want to type os.exit() each time I use print, so I want to redefine this function. > function pprint(...) >> for _,a in ipairs(arg) do >> print(a) >> end >>…
minerals
  • 6,090
  • 17
  • 62
  • 107
2
votes
1 answer

Execute Loaded Lua files in a certain scope

I'm using Lua as a configuration format for a project mine. Let's suppose I have the following contrived example, we'll call conf.lua: title = "Lorem Ipsum" author = "John Doe" date = "01 January 2000" Now, trivially, I can of course load this file…
junius
  • 570
  • 3
  • 14
2
votes
1 answer

Lua: Local package.path

In Lua is there a way to define package.path to apply only to a local scope? I understand I could store the package.path in a local variable and restore it before my script ends as in the example below but is there a cleaner way? local…
Puddler
  • 2,619
  • 2
  • 17
  • 26
2
votes
2 answers

Factory function unable to return the local iterator to for loop in lua?

Why can't the factory function fromto return the local function iter as an iterator to the for loop? function fromto(from,to) return iter,to,from-1 end local function iter(to,from)--parameter:invariant state, control variable from = from +…
a wei
  • 75
  • 2
  • 9
2
votes
1 answer

luaL_setmetatable() overrides metatables from other values

I have different metatables in my project. But if I create a value A and assign the metatable "X" and creates a second value B and attach metatable "Y", A gets the Y metatable, too! Here is a simplified C function for demonstration: #include…
cytrinox
  • 1,846
  • 5
  • 25
  • 46
2
votes
1 answer

lua metatable bug or feature?

If I have this construct: a.key = b and both a has a metatable attached and b has a metatable attached. Then b's metatable setter will be called to set key to b. Is this a bug of lua 5.3.0? EDIT: a and b are strings.
user1095108
  • 14,119
  • 9
  • 58
  • 116