Error loading module when using lua - lua

I'm new to lua and recently learning DL with Torch.
I have installed torch just following instructions: http://torch.ch/docs/getting-started.html#_ and added some packages using luarocks install. Then I wrote a test file:
require 'torch'
require 'nn'
--[[do something]]
when running with lua test.lua (Ubuntu 14.04), it errs as followed:
error loading module 'libpaths' from file
'/home/user1/torch/install/lib/lua/5.1/libpaths.so':
/home/user1/torch/install/lib/lua/5.1/libpaths.so: undefined symbol:
luaL_register
It seems something wrong with path settings or so. However, when I run test with command th, it works fine.
I searched and examined these answers: Error loading module (Lua)
Torch7 Lua, error loading module 'libpaths' (Linux)
not fully answered my question though.
So I wonder where exactly the error comes from, and how to fix it. Even though I can use torch with th.
ADD:
I find that the reason maybe API luaL_register is not supported in ver 5.2 which is what I am using, while th calls a lua shell in ver 5.1? So does this mean I can only use th to run my files?

You are likely using your system Lua (probably version 5.2), but Torch requires LuaJIT it comes with. Run your script as luajit test.lua (it's probably in /home/user1/torch/install/bin/luajit).

Related

Warning: Could not find Lua 5.3 in PATH - When Trying to Install Gumbo library with Luarocks

When writing luarocks install gumbo
In the location/directory of my luarocks file in cmd, I am getting the following error
Warning: Could not find Lua 5.3 in PATH.
Modules may not install with the correct configurations. You may want to specify the path prefix to your build of Lua 5.3 using --lua-dir
Installing https://luarocks.org/gumbo-0.5-1.src.rock
Error: Failed finding Lua library. You may need to configure LUA_LIBDIR.
I've added lua53.exe to the same directory, and added the file both to my user variables and system variables in control panel.
Not sure if worth mentioning, but when running lua53.exe and trying to use luarocks install gumbo from there,
the lua53 cmd-like window responds with stdin:1: syntax error near 'install'
I was hoping to do some web scraping with lua, and later on building a World of Warcraft addon that utilizes gumbo to show certain helpful information within the WoW client, but I can't seem to even get the most basic stuff to work...
Setting up LuaRocks on Windows is annoying and I'm not familiar with it myself. If you added both the LuaRocks and Lua 5.3 Windows binaries (Executables and Includes) to your Path system variable:
luarocks path prints the commands for setting up the LUA_PATH and LUA_CPATH system variables.
The config.lua file tells you what your variables.LUA_LIBDIR value is. You can check it with luarocks config. For me that file would be in:
C:/Users/Ketho/AppData/Roaming/luarocks/config-5.3.lua
otherwise you can create an empty file there and put in this line to point it to wherever your Lua folder is:
variables.LUA_LIBDIR = "C:/lua-5.3.5_Win32_bin"
variables.LUA_INCDIR = "C:/lua-5.3.5_Win32_bin/include"
As for using gumbo to show information within WoW, the addon environment is sandboxed. Unless you meant you just want to get the data to hardcode into your addon.

lua script and when executed via wrk the version is different

I have a lua script test.lua
which when executed lua test.lua it executes and provides me output as expected and it uses lua 5.3 when compiling
But when i execute the same test.lua via wrk (http performance test benchmark brew tool) , it reached to lua 5.1 (which I dont have in my system) rather than 5.3
And there is no any wrk config which tries to reach to lua 5.1 . I am not sure why it behaves different and hits different version of lua
An hint to this confusion will be appreciated.
From the LuaJIT site, here:
LuaJIT is API-compatible with Lua 5.1
wrk uses LuaJIT, as noted here.

luaj doesn't find .so modules

I've written a GUI in Java and use a lua-script to calculate some values for images with a neural network. Therefore the lua-script requires some modules from torch7.
I got so far that it finds the modules which have a init.lua file. However, it fails when a module only has a .so file. The module is required in one of the init.lua files.
Before I require the modules in the script i set the new package.path and the package.cpath to LUA_PATH and LUA_CPATH because luaj only used the default path which didn't work.
I think this a LuaJ problem because when I run the script in the terminal with lua script_name.lua it works fine.
package.path = package.path .. ';/home/user/.luarocks/share/lua/5.1
/?.lua;/home/user/.luarocks/share/lua/5.1/?/init.lua;/home/user/torch
/install/share/lua/5.1/?.lua;/home/user/torch/install/share/lua/5.1
/?/init.lua;./?.lua;/home/user/torch/install/share/luajit-2.1.0-
beta1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1
/?/init.lua'
package.cpath = '/home/user/torch/install/lib/?.so;/home/user/.luarock
/lib/lua/5.1/?.so;/home/user/torch/install/lib/lua/5.1/?.so;./?.so;
/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so'
require 'torch'
require 'nn'
require 'image'
The error message is as follows:
exception in thread "main" org.luaj.vm2.LuaError: #/home/user/torch/install/share/lua/5.1/paths/init.lua:1 module 'libpaths' not found: libpaths
no field package.preload['libpaths']
libpaths.lua
/home/user/.luarocks/share/lua/5.1/libpaths.lua
/home/user/.luarocks/share/lua/5.1/libpaths/init.lua
/home/user/torch/install/share/lua/5.1/libpaths.lua
/home/user/torch/install/share/lua/5.1/libpaths/init.lua
./libpaths.lua
/home/user/torch/install/share/luajit-2.1.0-beta1/libpaths.lua
/usr/local/share/lua/5.1/libpaths.lua
/usr/local/share/lua/5.1/libpaths/init.lua
no class 'libpaths'
I call the script from my java program:
public ScoreImage(){
G_ = JsePlatform.standardGlobals();
//G_.get("dofile").call( LuaValue.valueOf(changePath_));
G_.get("dofile").call( LuaValue.valueOf(script_));
}
I use lua 5.1 because some of the problems where solved by changing from lua 5.2 to lua 5.1. I have Ubuntu 14.04 LTS and luaj 3.0.1.
I really appreciate any help!
It seems that LuaJ does not have the ability to load dll files and so files.
You may want to look into jnlua:
https://code.google.com/archive/p/jnlua/

Lua version in ZeroBraneStudio vs Torch

I am using ZeroBrane Studio as IDE to code deep learning. I have realized that the models I save when programming in the IDE (using Lua 5.1 as interpreter) do not load well when executing the same loading from Torch7. The same happens when learning from torch (./th code.lua) and then trying to load them inside the IDE. I get something like:
/opt/zbstudio/bin/linux/x64/lua: /home/dg/torch/install/share/lua/5.1/torch/File.lua:294: unknown object
Does anybody know how to check the lua version that torch is using? Any idea on how to workaround this?
Thanks!
update: It seems that I am indeed using the same Lua version (5.1) in both Torch and ZeroBrane. I still get different behaviour (one successful and the other crashing) when passing through torch.load().
To check the version of Lua that anything is running, you would usually print _VERSION. It's a global variable that stores the version of Lua (unless you overwrite it, of course).
print(_VERSION)
If this isn't available for some reason, they might state their version on their site (?)
Most command line tools on Linux understand the -v command line switch (for "version"). So do Lua and LuaJIT.
To figure out which interpreter is running a particular script, you can scan the arg table for the smallest (usually negative) index:
local exe, i = arg[ 0 ], -1
while arg[ i ] do
exe, i = arg[ i ], i-1
end
print( exe )
Or (on Linux) you can look into the /proc file system while your script is running:
ls -l /proc/4425/exe
(substitute 4425 with real process ID).
Judging from the error message the interpreter used in ZeroBrane Studio seems to be /opt/zbstudio/bin/linux/x64/lua in your case.
#siffiejoe: thanks for posing your question regarding versions, it gave me the correct directions to explore.
/opt/zbstudio/bin/linux/x64/lua version is LuaJIT 2.0.2
"lua" command alone points to /usr/bin/lua, and it is Lua 5.1.5
~/torch/install/share/lua/5.1 seemed to contain Lua 5.1
~/torch/install/bin/luajit is 2.1.0-alpha
So after realizing that terminal "th" is using LuaJit 2.1.0 all I had to do is create a user.lua in ZeroBrane and add the line "path.lua = "~/torch/install/bin/luajit". Now ZB is using the same luajit interpreter as th.
Thanks all for your suggestions.

Lua 5.2 adding luasocket (unstable)

Im trying to use luasocket with lua 5.2. i downloaded the code form the git repository and built it. then made a make install so that it generated core.dll and mime.dll. put those into the custom lua program directory [CPATH] im developing and tried loading it. But i get following error message:
Failed at error loading module 'socket.core' from file 'D:\[..myprogram..]\socket\core.dll':
Module was not found.
how can i check if the dll is correct. or did i do anything wrong?
Thanks
Is your executable residing in the same directory as your lua files?
Try putting the dll in the directory of your executable.
Most likely you are loading socket modules that are compiled for Lua 5.1, not Lua 5.2 (or at least it's the same error I get in a case like that). Is it possible that you have socket module for Lua 5.1 somewhere in your path? It may come with LuaForWindows or another package. You can try to remove/move the socket DLLs you compiled (for Lua 5.2) and see if you get the same error.

Resources