lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


When the Lua script on most systems starts arg contains the command from which the script was started. I have this file:

for k,v in pairs(arg) do
print(k,v)
end

When I run it like:
D:\>lua d:\commandArgs.lua
0       d:\commandArgs.lua
-1      lua

When I do:
D:\>lua commandArgs.lua
0       commandArgs.lua
-1      lua

This works fine for me in Windows and Linux as well. In the second case we do not get the path. To get the path can be system dependent. If you have the os library and popen function in your lua version, 1 way to get the path is:

cmd = os.execute("pwd") and "pwd" or "cd"
f = io.popen(cmd,"r")
path = f:read("*a")
f:close()

Milind


On Mon, Jan 20, 2020 at 11:20 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
Hi,

Is there any robust and convenient methods for me to obtain the lua
script's (absolute/real) dirname and file name from within the script
itself?

Regards
--
Hongsheng Zhao <hongyi.zhao@gmail.com>
Institute of Semiconductors, Chinese Academy of Sciences
GnuPG DSA: 0xD108493