Get containing path of lua file

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

    Have a look at the Lua debug library, which is part of the standard Lua distribution. You can use debug.getinfo to find the current file, or the file up N frames on the call stack:

    http://www.lua.org/manual/5.1/manual.html#5.9

    Note that this is probably fairly slow, so it is not something you want to do on the fast path if you are worried about such things.

提交回复
热议问题