Missing functions in Table Library in Lua - lua

When I run table.maxn() or table.getn() in Lua I get the errors below:
> table.maxn(a)
stdin:1: attempt to call a nil value (field 'maxn')
stack traceback:
stdin:1: in main chunk
[C]: in ?
> table.getn(a)
stdin:1: attempt to call a nil value (field 'getn')
stack traceback:
stdin:1: in main chunk
[C]: in ?
When I try to explore the contents of the table object I get the results below. It is almost as though some functions are missing from the library.
> for k,v in pairs(table) do
>> print (k)
>> end
remove
insert
move
sort
concat
unpack
pack
>
I am using Lua5.3 - from downloaded win32 binaries > Lua53.exe
I have confirmed that I did not alter / affect the table object in any way. The results above were obtained after restarting the Interpreter afresh.
What could the issue be?

You are using lua 5.3 but:
table.getn was deprecated in lua 5.1 (ref)
table.maxn was deprecated in lua 5.2 (ref)
You need to write valid code for the version of lua you are targetting.

Related

Loadstring Error: attempted to call a nil value

loadstring("
\45\45\32\80\117\116\32\115\99\114\105\112\116\32\104\101\114\101\10\112\114\105\110\116\40\34\104\105\34\41\10")()
I keep getting an error stating this:
lua: /tmp/044957038/main.lua:12: attempt to call a nil value (global 'loadstring')
stack traceback:
/tmp/044957038/main.lua:12: in main chunk
[C]: in ?
Can anyone help me? (I’m using glot.io to run my script.)
Based on the comments and some testing in glot, this should work (the print() is just for reference):
print("\45\45\32\80\117\116\32\115\99\114\105\112\116\32\104\101\114\101\10\112\114\105\110\116\40\34\104\105\34\41\10")
load("\45\45\32\80\117\116\32\115\99\114\105\112\116\32\104\101\114\101\10\112\114\105\110\116\40\34\104\105\34\41\10")()
Output
-- Put script here
print("hi")
hi

Mediawiki scribunto lua module do not know builtin functions

I am having a problem with calling Lua built-in functions using Scribunto.
I created basic module Module:Item
local p = {};
function p.test(frame)
print("Hello World!")
end
return p
Which I call in different page as {{#invoke: Item | test}}
and I receive a following error:
Lua error in Module:Item at line 3: attempt to call global 'print' (a nil value).
Backtrace:
1. (tail call): ?
2. Module:Item:3: in function "chunk"
3. mw.lua:511: ?
4. (tail call): ?
5. [C]: in function "xpcall"
6. MWServer.lua:99: in function "handleCall"
7. MWServer.lua:313: in function "dispatch"
8. MWServer.lua:52: in function "execute"
9. mw_main.lua:7: in main chunk
10. [C]: ?
Since print is Lua built-in function I have the feeling the problem will be somewhere in setting on the pc.
However, when I imported wiki Infoboxes, they are working OK.
Versions:
Linux Mint Tara - Cinnamon based on ubuntu 18
MediaWiki 1.31.7
Scribunto (106fbf4) 17:24, 15 May 2018
Lua 5.1.5
Any help pointing where the problem can be is highly appreciated.
Scribunto intentionally doesn't include print. The "Removed functions and packages" section in its manual says this about it:
This was discussed on wikitech-l and it was decided that it should be omitted in favour of return values, to improve code quality. If necessary, mw.log() may be used to output information to the debug console.

Lua: "Attempt to index a nill value"

Hi so I just installed Lua and I have been playing around with it a bit. When I run a program that is supposed to calculate whether an integer is even or odd it throws an error at me.
Program:
function is_even(n)
if bit32.band(n,1) == 0 then
print('Even')
else
print('Odd')
end
end
This is the error that I receive:
stdin:2: attempt to index a nil value (global 'bit32')
stack traceback:
stdin:2: in function 'is_even'
(...tail calls...)
[C]: in ?
What am i doing wrong here? This program is supposed to work on Lua 5.2+ I currently have Lua 5.3.3 installed.
The bit32 library was deleted from Lua 5.3, because it now supports bitwise operators.

Keep Lua tmpfile after execute

Uploades file represented as tmpfile() and will be removed then script exits.
How to hardlink this file to keep its content after removing tmpfile?
How to get name of file by its handle?
> a=io.tmpfile()
> print(a)
file (0x20c8790)
> lfs=require"lfs"
> lfs.link(a,"/tmp/aaaa")
stdin:1: bad argument #1 to 'link' (string expected, got FILE*)
stack traceback:
[C]: in function 'lfs.link'
stdin:1: in main chunk
[C]: in ?
This file is too big to copy it by byte to another.
io.tmpfile uses tmpfile of stdio.h, so it wont be possible to adjust this exported function.
you can use libraries such as pl.path to get full path of temp file.

Sublime Text FormatLua Error

I'm trying to format code with a package I installed for Sublime Text 3 - FormatLua.
However, I'm getting this error when I try to use it...
/usr/local/bin/lua: ./metalua/compiler.lua:119:
./metalua/compiler/bytecode/lopcodes.lua:284: attempt to call field
'gfind' (a nil value) stack traceback:
[C]: in function 'error'
./metalua/compiler.lua:119: in function 'get_bytecode_compiler'
./metalua/compiler.lua:125: in function 'f'
./metalua/compiler.lua:153: in function <./metalua/compiler.lua:150>
(...tail calls...)
[C]: in function 'require'
formatter.lua:24: in main chunk
[C]: in ?
Does anyone know what I must do to fix this issue? I must be missing some files - I see that gfind is nil (this was taken out after 5.0), but I don't want to mess with anything unless I'm sure I know what I'm doing. Thanks!
Yes, gfind was deprecated. You can replace string.gfind with string.gmatch. I applied a similar change for the same reason; here is the commit.
Works well after downgrading lua version to 5.1.4
Compiling from source code:
Lua 5.1.4 here: http://www.lua.org/ftp/lua-5.1.4.tar.gz:
Open your Terminal.app
wget http://www.lua.org/ftp/lua-5.1.4.tar.gz
tar xvzf lua-5.1.4.tar.gz
cd lua-5.1.4
make macosx
make install

Resources