Lua global variable containing path to current file?

后端 未结 3 441
北荒
北荒 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:12

    In Lua 5.2, when a script is loaded via require, it receives as arguments the module name given to require and the filename that require used to open the script:

    $ cat a.lua
    require"b"
    $ cat b.lua
    print("in b",...)
    $ lua a.lua
    in b    b   ./b.lua
    

    In Lua 5.1, only the module name is passed, not the filename.

提交回复
热议问题