Locating the module file

after loading a module in Lua, I would like to determine which module file corresponds to it. In python, you do this with code like:

import module_name
module_name.__file__

      

So, in Lua, if I have something like

require 'math'

      

what have I put in order to determine where this module is located? BTW, I don't really need the math space, but instead there are some other third party packages that have been downloaded and you want to know which copy of the assembly files is actually being used when I call Lua.

+3


source to share


1 answer


The library package

can provide you with what you need.

For example, if I have util.lua

Lua in my path so that I can write:

require 'util'

      



I can get the file path like this:

print(package.searchpath('util', package.path))

      

+4


source







All Articles