Get containing path of lua file

后端 未结 10 2114
粉色の甜心
粉色の甜心 2021-02-12 12:00

I am wondering if there is a way of getting the path to the currently executing lua script file?

This is specifically not the current working directory, which could be

10条回答
  •  耶瑟儿~
    2021-02-12 12:14

    arg[0]:match('.*\\')
    

    If it returns nil try changing the .\*\\\ with .*/ and arg[0] with debug.getinfo(1).short_src.

    But I find this to be the best and shortest way to get the current directory.

    You can of course append the file you are looking for with the .. operator. It will look something like this:

    arg[0]:match('.*\\')..'file.lua'
    

提交回复
热议问题