Lua global variable containing path to current file?

后端 未结 3 393
北荒
北荒 2021-01-12 15:37

Is there a global variable in Lua that contains the path to the file currently being interpreted? Something like Python\'s __file__ variable?

I ran a qu

3条回答
  •  囚心锁ツ
    2021-01-12 16:24

    In response to the answer by lhf:
    Being new to Lua, I was initially confused what ... meant. Turns out it's a vararg just like with ANSI C: https://www.lua.org/manual/5.3/manual.html#3.4. In my experience with lua 5.3, using

    local packageName, packagePath = ...
    

    got me the package name as when used in a require and the absolute file path of the package.

提交回复
热议问题