[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Inferring the location of a Lua script
- From: Petite Abeille <petite.abeille@...>
- Date: Mon, 26 Apr 2010 19:21:38 +0200
On Apr 26, 2010, at 5:25 PM, Lorenzo Donati wrote:
> I need a way to make a Lua script know it's exact location, i.e. its absolute file system path (under Win XP is enough) using pure Lua and no C.
As mentioned by Peter, debug.getinfo( aLevel, 'S' ).source is your friend. Usage Example:
As far as absolute path goes, you need to know your current location, which is usually not possible from plain Lua. Something like LuaFileSystem lfs.currentdir() would be required to achieve that.
That said, one usually only needs a relative path to load resources.
For example, the code bellow looks for a file named 'Finder.dml' relative to wherever 'Finder.lua' was loaded from: