Mediawiki scribunto lua module do not know builtin functions - lua

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.

Related

unpack() not available on Lua 5.4?

I am reading a few tutorials on Lua and am trying to figure out how to use unpack(). I found an example that goes like this:
t = { "the", "quick", "brown" }
print (unpack (t))
The output should be "the quick brown".
What actually happens is this: "stdin:1: attempt to call a nil value (global 'unpack')".
How can I make unpack() work?
My Info:
OS: Mac OS 10.8
Lua: 5.4.2
Since Lua 5.2 unpack function is now at table.unpack
Function unpack was moved into the table library and therefore must be called as table.unpack.

Pubnub Lua (Corona) Library not working

I am developing with Corona SDK, the most recent public release (v3.0, build 2015.2646), on OS X 10.10.
I have downloaded the pubnub corona repo from here: https://github.com/pubnub/lua/
When I try to run the pubnub examples, multiple examples are failing with a run-time error in the core pubnub.lua library.
For instance, example-channel-information, example-mathmania, example-multi-drum.
They all result in a console runtime error of:
Oct 20 10:46:51.328: Runtime error
.../pubnub/corona/examples/example-channel-information/pubnub.lua:534: attempt to call upvalue 'callback' (a table value)
stack traceback:
[C]: in function 'callback'
.../pubnub/corona/examples/example-channel-information/pubnub.lua:534: in function <.../pubnub/corona/examples/example-channel-information/pubnub.lua:532>
(tail call): ?
Is this a problem with my environment, or is there a more recent pubnub.lua release, or is this a bug?
thanks

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

Parameter implicit "arg" in functions not work in Lua

I have a problem in use implicit parameter arg in functions.
The code not works. The documentation, http://www.lua.org/pil/5.2.html, should works.
function listar_um (...)
for i,v in ipairs(arg) do
print("usando args " .. arg[i])
end
end
listar_um("Olá", 1, "Dois")
This code works with the declaring variable lista.
function listar_um (...)
lista = {...}
for i,v in ipairs(lista) do
print("não usando args " .. lista[i])
end
end
listar_um("Olá", 1, "Dois")
Why the first example does not work?
Script for test: http://www.codeshare.io/IPwRJ
Execute on-line script: http://www.compileonline.com/execute_lua_online.php
Thanks.
The first edition of PiL talks about Lua 5.0. The use of arg is available in Lua 5.0, while it's removed since Lua 5.1
You can find it in Lua 5.0 reference manual, but not in Lua 5.1 reference manual.
The edition the online interpreter uses is Lua 5.2, you can find out by print(_VERSION).
Edit: after some tests, it seems that arg is still available in Lua 5.1, but not working in Lua 5.2.

Line number where SWIG_RuntimeError occurs

I am running Lua with a C++ library via swig. When a swig runtime error occurs I would like to know the line which caused the problem. The error message I receive does not have this information.
How can I find which line in the Lua code triggered the error?
For example suppose I have a swig function "swigstringcount" and it takes a string:
local n=4
local m=swigstringcount(n)
print (m,n)
This (obviously wrong) code produces an error on line two. Currently all I get is
error:SWIG_RuntimeError: swigstringcount requires a string
I want it to tell me that line 2 produced the error, like standard Lua error messages.
Based on this method for getting debug info from the Lua C API I've put together a (slightly messy) example of how you can integrate that into a SWIG interface:
%module test
%{
#undef SWIG_fail_arg
#define SWIG_fail_arg(func_name,argnum,type) \
{lua_Debug ar;\
lua_getstack(L, 1, &ar);\
lua_getinfo(L, "nSl", &ar);\
lua_pushfstring(L,"Error (%s:%d) in %s (arg %d), expected '%s' got '%s'",\
ar.source,ar.currentline,func_name,argnum,type,SWIG_Lua_typename(L,argnum));\
goto fail;}
%}
%include <std_string.i>
%inline %{
void func(const std::string& str) {}
%}
This basically replaces the default SWIG_fail_arg macro with a modified one that gets and prints some debug info.
I tested it with the latest SWIG trunk (I think you might be using an older version since the text I see didn't quite match), but I was able to do:
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require('test')
> local n=4
> test.func(n)
Error (=stdin:1) in func (arg 1), expected 'std::string const &' got 'nil'
stack traceback:
[C]: in function 'func'
stdin:1: in main chunk
[C]: ?
I seem to have more debug info (i.e. a full stack trace) there already though.

Resources