|
Milind Gupta <milind.gupta@gmail.com> 于2020年1月22日周三 上午4:08写道:
>
> 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"
The issue with method is:
`pwd' will give the work dir which maybe or may not the dir the lua
script resides in.
But I want to obtain the dir which is the lua script resides in.
Regards
> 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
>>
--
Hongsheng Zhao <hongyi.zhao@gmail.com>
Institute of Semiconductors, Chinese Academy of Sciences
GnuPG DSA: 0xD108493