【发布时间】:2014-02-20 09:54:38
【问题描述】:
Lua 中是否有一个全局变量包含当前正在解释的文件的路径?类似于 Python 的 __file__ 变量?
我在解释器中快速运行for k, v in pairs(_G) do print(k) end,看看是否能找到任何东西。只列出了以下变量?
string xpcall package tostring print os unpack require getfenv setmetatable next assert tonumber io rawequal collectgarbage getmetatable module rawset math debug pcall table newproxy type coroutine _G select gcinfo pairs rawget loadstring ipairs _VERSION dofile setfenv load error loadfile
关于如何获取当前正在执行的文件的路径有什么建议吗?
【问题讨论】:
-
这将返回启动 Lua 时使用的文件名,但是,它不会返回“当前文件”,它会随
require命令而改变。 -
请注意,
arg表仅在通过lua命令行解释器运行脚本时可用。
标签: module lua filesystems filenames interpreter