lua script and when executed via wrk the version is different - lua

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.

Related

how to compile a lua excutable?

I'm playing with lua with the following link: https://www.tutorialspoint.com/lua/lua_basic_syntax.htm.
Now I'm a bit confused with this supposed simple task to run lua file in the other way, i.e.,
Let's try another way to execute a Lua program. Below is the modified test.lua file −
Live Demo
#!/usr/local/bin/lua
print("test")
Here, we have assumed that you have Lua interpreter available in your /usr/local/bin directory. The first line is ignored by the interpreter, if it starts with # sign. Now, try to run this program as follows −
chmod a+rx test.lua
./test.lua
We will get the following output.
test
I think somehow I need to know where the Lua interpreter located. Any comments are greatly appreciated.
EDIT: After changing /usr/local/bin/lua into /usr/bin/lua, it worked out well.
As mentioned in the manual, use
#!/usr/bin/env lua
if lua is in your PATH.

What's the difference between using th and lua commands to run a lua script?

Is there a difference in executing .lua files written for torch using th and lua?
On the server I'm using, I can't run the th command, but I can import torch inside the python interpreter (I'm assuming that this is because pytorch is installed but not torch itself).
I'm wondering if I can just run lua scriptname.lua instead of th scriptname.lua like instructed here: https://github.com/jwyang/JULE.torch

Error loading module when using 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).

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.

How to install lmapm for lua?

I am making a script that requires lmapm, but I'm not quite sure how to install it. I have 4 files,
lmapm.c
test.lua
README
Makefile
And I'm not sure how to use them in my lua environment. Lua 5.1 is installed on my desktop in a folder called "5.1", and it was installed with LuaRocks (If that matters) I know lua libraries are used with require, but this is a c file, not a lua file.
How can I install/use lmapm in my lua programs?
Upon reading the readme it tells me to run make, but makefile is just a "file" on my computer, there is nothing I can run it with.
README: Short description of what you got and how to install & use the module at the end.
test.lua: Lua script to test the module/sample of usage.
lmapm.c: C source code and the module in raw/still unusable form. Needs to get compiled and linked to a dynamic library of target platform.
Makefile: Automatic build instructions to compile&link lmapm.c to what you finally use in Lua.
Makefile serves as a macro which makes building easier with minimal input by users. To run this file, you need program make (comes with GNU toolchain; on Unix install package build-essential, on Windows MSYS). Before you have to fix the path to your Lua and MAPM installation (as mentioned in the official build instructions). Furthermore you need the C compiler and linker (which you already installed on Unix together with make and have to install on Windows by f.e. MinGW).
The result is a dynamic library/Lua C module which you can require simply by its filename. To put it in the scope of Lua, move it in the application or (better) in the Lua modules directory.

Resources