Get containing path of lua file

后端 未结 10 1935
粉色の甜心
粉色の甜心 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

    This is a more elegant way:

    function script_path()
       local str = debug.getinfo(2, "S").source:sub(2)
       return str:match("(.*/)")
    end
    
    print(script_path())
    

提交回复
热议问题