Lua image errors - lua

I have installed lua image according to this - link. I also tested my install with luajit -limage -e "image.test()" and it says 0 errors and 0 warnings. Also, when I try
> require 'image'
> l = image.lena()
There are no errors. However, when I try image.display(l), I get the following errors:
/home/srilatha/torch/install/share/lua/5.1/trepl/init.lua:384: module 'qt' not found:No LuaRocks module found for qt
no field package.preload['qt']
no file '/home/srilatha/.luarocks/share/lua/5.1/qt.lua'
no file '/home/srilatha/.luarocks/share/lua/5.1/qt/init.lua'
no file '/home/srilatha/torch/install/share/lua/5.1/qt.lua'
no file '/home/srilatha/torch/install/share/lua/5.1/qt/init.lua'
no file './qt.lua'
no file '/home/srilatha/torch/install/share/luajit-2.1.0-beta1/qt.lua'
no file '/usr/local/share/lua/5.1/qt.lua'
no file '/usr/local/share/lua/5.1/qt/init.lua'
no file '/home/srilatha/.luarocks/lib/lua/5.1/qt.so'
no file '/home/srilatha/torch/install/lib/lua/5.1/qt.so'
no file '/home/srilatha/torch/install/lib/qt.so'
no file './qt.so'
no file '/usr/local/lib/lua/5.1/qt.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'error'
/home/srilatha/torch/install/share/lua/5.1/trepl/init.lua:384: in function 'require'
/home/srilatha/torch/install/share/lua/5.1/image/init.lua:1363: in function 'display'
[string "_RESULT={image.display(l)}"]:1: in main chunk
[C]: in function 'xpcall'
/home/srilatha/torch/install/share/lua/5.1/trepl/init.lua:651: in function 'repl'
...atha/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:199: in main chunk
[C]: at 0x00406670
I have torch running properly so I don't know what the problem would be with qt. How can I fix this?

Did you read this by any chance?
https://github.com/torch/image/blob/master/doc/gui.md
image.display among other functions can only be accessed via the qlua Lua interpreter.
Calling that function from LuaJit will result in the errors you're facing.

Just to add to Piglet's answer - read about qlua:
https://github.com/torch/qtlua/blob/master/doc/qt.md#qlua
At first I thought: "Oh dear, I'm using luajit, in a torch installation, I have no time and motivation to install another interpreter, configure luarocks to work with it, and then install everything from scratch". Good news: I was wrong.
qlua is an interpreter, but it gets installed in your existing Lua + Torch directory.
$ luarocks install qtlua
$ luarocks install qttorch
$ which qlua
/home/me/torch/install/bin/qlua
$ qlua
Lua 5.1 Copyright (...)
> require('image')
> l = image.lena()
> image.display(l)
>
.. a window pops up, and the prompt returns immediately.
This is because qlua has a background GUI thread to display your images and react to events (closing, and resizing the window, upon which the image will be scaled - with no aspect preservation: W & H independent).

Related

How to pass on path of ZLIB to ImageMagick?

Executing, both:
a)$/home/julia/displayImage.jl
b) julia> /home/julia/displayImage.jl
throw error:
...could not load library ...deps/usr/lib/libMagickWand-6.Q16.so" lib64/libz.so.1: version ZLIB_1.2.9,
where displayImage.jl, is:
#! /opt/julia-1.1.0/bin/julia
using Images, TestImages, FileIO, Colors, ImageView;
function displayImage(path::String)
img = nothing;
if isfile(path)
img = load(path);
imshow(img);
else
info("ERROR: While loading image!");
end
end
the same code works when each command is copied, pasted and executed at julia prompt during the ImageMagick's build session but not after exit from the session!
It is observed that: a)julia is not using the ZLIB installed in its deps folder after build session of ImageMagick. b)the os and julia packages CodecZlib, Conda, ZipFile, ImageMagick... have different versions of ZLIB.
Please advise me on a) how to pass on ZLIB path which is inside the folder of package, ImageMagick while executing at shell prompt and b) also using single updated version!
Executing the followong line at shell prompt resolves the issue for the session.
$export LD_LIBRARY=/opt/julia/julia-1.1.0/share/julia/stdlib/v1.1/ImageMagick/deps/usr/lib:/usr/lib64:$LD_LIBRARY_PATH
where the first path is of ZLIB inside ImageMagick package.

Why is Lua reporting that "The specified procedure could not be found." for this library compiled from source?

I've been working at this for a while now and I can't figure out what's wrong.
At this point I've built everything from source and it still doesn't work. My environment is Windows 10 x64 and I'm compiling with Cygwin's MinGW-w64. Everything is compiled as i686 (32-bit) and not x86_64.
For reference, instances where I use gcc is actually i686-w64-mingw32-gcc. liblua53.dll.a and libyaml.a were compiled from source using Lua 5.3.5 and LibYAML 0.2.2.
I built the objects:
gcc -DVERSION=\"git-5695363\" -Ilua-5.3/src -Ilibyaml/src/include -c ext/yaml/emitter.c -o emitter.o
gcc -DVERSION=\"git-5695363\" -Ilua-5.3/src -Ilibyaml/src/include -c ext/yaml/scanner.c -o scanner.o
gcc -DVERSION=\"git-5695363\" -Ilua-5.3/src -Ilibyaml/src/include -c ext/yaml/parser.c -o parser.o
gcc -DVERSION=\"git-5695363\" -Ilua-5.3/src -Ilibyaml/src/include -c ext/yaml/yaml.c -o yaml.o
Then linked:
gcc -shared -static -s -Llua-5.3/dist -Llibyaml/dist emitter.o parser.o scanner.o yaml.o -lyaml -llua53.dll -o lyaml.dll
I've linked it as -shared because the output is a dll and as -static because I'm statically linking libyaml.a. I also tried compiling with dynamic linking to libyaml.dll with the same error from Lua.
My Lua environment was compiled from the source and compiler:
> lua53.exe -v
Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio
Running a simple script works fine:
> lua53.exe -e 'print("Hello!")'
Hello!
But I can't load the library:
> lua53.exe -e 'require("lyaml")'
lua53.exe: error loading module 'lyaml' from file 'lyaml.dll':
The specified procedure could not be found.
stack traceback:
[C]: in ?
[C]: in function 'require'
(command line):1: in main chunk
[C]: in ?
I know that this is an error from Windows but I don't know what procedure is missing or where it's coming from.
I also checked that all dynamic-linking dependencies are being met and functions are being exported:
How can I debug this further?
I ended up building everything on Linux and ran into the same problem but with a much more useful error:
$LD_LIBRARY_PATH=. ./test.lua
/bin/lua: error loading module 'lyaml' from file './lyaml.so':
./lyaml.so: undefined symbol: luaopen_lyaml
stack traceback:
[C]: in ?
[C]: in function 'require'
./test.lua:5: in main chunk
[C]: in ?
The problem is that Lua binds the "luaopen_" symbol to the name of the library being loaded. So require("somelib") would be for somelib.dll with a an exact-matching luaopen_somelib export symbol. I built the library as lyaml.dll (to match the library name) but this symbol was exported as luaopen_yaml, which meant that Lua was looking for luaopen_lyaml (which didn't exist).
Several solutions are possible:
Modify the export in the source code to match the file name.
Modify the file name to match the export from the source code.
Ignore the discrepancy completely and use package.loadlib() which allows this.
I've opted for the third solution. Thank you #PaulKulchenko for the third solution.
The key takeaway from this is that there is by default a tight coupling between require(), the export symbol, and the file name of library being loaded.
Since you are already using Dependency walker, I recommend using its "Profile" feature. You can start profiling on lua53.exe file and when you execute the require command, the profiler will show you the trace of all DLLs being loaded and any errors related to their load as well as the details of the error that you don't see from the Lua message.
You can also execute package.loadlib("lyaml.dll", "luaopen_yaml") to confirm that the signature is valid; you should get a function back that, when executed, will return the actual package.

local luarocks package install (luarepl) does not work

I'm new to luarocks and I just tried to install luarepl.
The installation apparently went fine:
$ luarocks install luarepl
Installing https://luarocks.org/luarepl-0.8-1.rockspec...
Using https://luarocks.org/luarepl-0.8-1.rockspec... switching to 'build' mode
Updating manifest for /Users/me/.luarocks/lib/luarocks/rocks-5.1
luarepl 0.8-1 is now built and installed in /Users/me/.luarocks (license: MIT/X11)
but if I try to launch the executable, it seems that the installation is broken:
$ ~/.luarocks/bin/rep.lua
/usr/local/bin/lua5.1: ...cks/lib/luarocks/rocks-5.1/luarepl/0.8-1/bin/rep.lua:23: module 'repl.console' not found:
no field package.preload['repl.console']
no file './repl/console.lua'
no file '/usr/local/share/lua/5.1/repl/console.lua'
no file '/usr/local/share/lua/5.1/repl/console/init.lua'
no file '/usr/local/lib/lua/5.1/repl/console.lua'
no file '/usr/local/lib/lua/5.1/repl/console/init.lua'
no file './repl/console.so'
no file '/usr/local/lib/lua/5.1/repl/console.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './repl.so'
no file '/usr/local/lib/lua/5.1/repl.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
...cks/lib/luarocks/rocks-5.1/luarepl/0.8-1/bin/rep.lua:23: in main chunk
[C]: ?
I look into the ~/.luarocks dir:
$ cd ~ ; find .luarocks
.luarocks
.luarocks/bin
.luarocks/bin/rep.lua
.luarocks/config.lua
.luarocks/lib
.luarocks/lib/luarocks
.luarocks/lib/luarocks/rocks-5.1
.luarocks/lib/luarocks/rocks-5.1/luarepl
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/bin
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/bin/rep.lua
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc/COPYING
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc/IDEAS.md
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc/plugins.md
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc/README.md
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc/Roadmap.md
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/luarepl-0.8-1.rockspec
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/rock_manifest
.luarocks/lib/luarocks/rocks-5.1/manifest
.luarocks/share
.luarocks/share/lua
.luarocks/share/lua/5.1
.luarocks/share/lua/5.1/repl
.luarocks/share/lua/5.1/repl/console.lua
.luarocks/share/lua/5.1/repl/init.lua
.luarocks/share/lua/5.1/repl/plugins
.luarocks/share/lua/5.1/repl/plugins/autoreturn.lua
.luarocks/share/lua/5.1/repl/plugins/completion.lua
.luarocks/share/lua/5.1/repl/plugins/example.lua
.luarocks/share/lua/5.1/repl/plugins/filename_completion.lua
.luarocks/share/lua/5.1/repl/plugins/history.lua
.luarocks/share/lua/5.1/repl/plugins/keep_last_eval.lua
.luarocks/share/lua/5.1/repl/plugins/linenoise.lua
.luarocks/share/lua/5.1/repl/plugins/pretty_print.lua
.luarocks/share/lua/5.1/repl/plugins/rcfile.lua
.luarocks/share/lua/5.1/repl/plugins/rlwrap.lua
.luarocks/share/lua/5.1/repl/plugins/semicolon_suppress_output.lua
.luarocks/share/lua/5.1/repl/sync.lua
.luarocks/share/lua/5.1/repl/utils.lua
and I can find that stuff.
I tried adding a line to config.lua to load packages from local installation to no avail:
$ cat ~/.luarocks/config.lua
local_by_default=true
(removing it has no effect)
did I miss some obvious step?
running luarocks with no arguments gives me:
CONFIGURATION
Lua version: 5.1
Configuration files:
System: /usr/local/etc/luarocks51/config-5.1.lua (ok)
User : /Users/me/.luarocks/config.lua (ok)
Rocks trees in use:
/Users/me/.luarocks ("user")
/usr/local ("system")
it seems that the user rock tree is not in the package path:
$ lua
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> print(package.path)
./?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua
why?
From https://github.com/luarocks/luarocks/wiki/Using-LuaRocks:
Most LuaRocks installations will feature two rocks trees:
"system" rock tree (used by default)
"user" rock tree
To be able to use the module, we need to make sure that Lua can find that dkjson.lua file when we run require("dkjson"). You can check your Lua paths from the Lua environment, using
print(package.path)
print(package.cpath)
These variables can be pre-configured from outside Lua, using the LUA_PATH and LUA_CPATH environment variables.
If you installed both Lua and LuaRocks in their default directories (/usr/local on Linux and Mac OSX), then the "system" tree is /usr/local and it will work by default. However, the "user" tree (for installing rocks without admin privileges) is not detected by Lua by default. For that we'll need to configure these environment variables.
LuaRocks offers a semi-automated way to do this. If you type the following command:
luarocks path --bin
it will print commands suitable for your platform for setting up your environment. On typical Unix terminal environments, you can type this:
eval $(luarocks path --bin)
and it apply the changes, temporarily, to your shell. To have these variables set permanently, you have to configure the environment variables to your shell configuration (for example, by adding the above line to your .bashrc file if your shell is Bash).

Got error loading module while running a simple lua script as tcp client

Run the following simple lua script but got error. I am running lua 5.2 on ubuntu.
local host, port = "127.0.0.1", 80
local socket = require("socket")
local tcp = assert(socket.tcp())
tcp:connect(host, port);
--note the newline below
tcp:send("GET / HTTP/1.1\r\n\r\n");
Here is the error:
~/learn/lua$ lua te.lua
lua: te.lua:2: module 'socket' not found:
no field package.preload['socket']
no file '/usr/local/share/lua/5.2/socket.lua'
no file '/usr/local/share/lua/5.2/socket/init.lua'
no file '/usr/local/lib/lua/5.2/socket.lua'
no file '/usr/local/lib/lua/5.2/socket/init.lua'
no file '/usr/share/lua/5.2/socket.lua'
no file '/usr/share/lua/5.2/socket/init.lua'
no file './socket.lua'
no file '/usr/local/lib/lua/5.2/socket.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.2/socket.so'
no file '/usr/lib/lua/5.2/socket.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './socket.so'
stack traceback:
[C]: in function 'require'
te.lua:2: in main chunk
[C]: in ?
Problem solved after installing the package manager luarocks and then socket package.
Here are the commands from the page
$ wget https://luarocks.org/releases/luarocks-2.4.1.tar.gz
$ tar zxpf luarocks-2.4.1.tar.gz
$ cd luarocks-2.4.1
$ ./configure; sudo make bootstrap
$ sudo luarocks install luasocket
$ lua
Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio
> require "socket"

Luajit load shared object from current working directory instead of default search path

I'm using Luajit 2.0.4 on Ubuntu 16.04
I have a simple C library.
int five() {
return 5;
}
I compile it like so
gcc -o five.so -shared -fPIC -Wall -Werror five.c
In the same directory I have a lua script
local ffi = require("ffi")
ffi.load("./five.so")
ffi.cdef([[
int five();
]])
print(ffi.C.five())
I've also tried it with an absolute path.
local ffi = require("ffi")
local fh = assert(io.popen("pwd", "r"))
local cwd = assert(fh:read())
print(cwd)
ffi.load(cwd .. "/five.so")
ffi.cdef([[
int five();
]])
print(ffi.C.five())
When I run
luajit five.lua
I get this
luajit: five.lua:6: luajit: undefined symbol: five
stack traceback:
[C]: in function '__index'
five.lua:6: in main chunk
[C]: at 0x004044a0
How do I load a shared object in the current working directory in luajit?
That's correct. The reason is that ffi.C points to a namespace to access the standard C-runtime (plus some additional libraries depending on your OS). From LuaJIT docs:
This is the default C library namespace [...] — note the uppercase
'C'. It binds to the default set of symbols or libraries on the target
system. These are more or less the same as a C compiler would offer by
default, without specifying extra link libraries.
If you want to call a C-function from an external library you need to:
Declare the function to use inside ffi.cdef, so LuaJIT knows how
to call that function.
Import the external library and assign it to
a Lua variable which serves as a namespace for the external
function.
Actually call the function.
Your code can be reworked as:
local ffi = require("ffi")
local lib = ffi.load("five")
ffi.cdef([[
int five();
]])
print(lib.five())
In addition, it's not necessary to add .os suffix. To resolve library names, the package.cpath variable is used. It works like package.path variable. Question marks (?) are replaced by the library name.
$ luajit -e "print(package.cpath)"
./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so

Resources