Get containing path of lua file

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

    Shortest form which I have found looks like this:

    debug.getinfo(1).source:match("@?(.*/)")
    

    Index 1, 2- other - depends on which function in call stack you want to query. 1 is last called function (where you're in). If you're running in global context, then probably 2 is more appropriate (haven't tested by myself)

提交回复
热议问题