lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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:

http://dev.alt.textdrive.com/browser/HTTP/Bundle.lua#L52

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:

http://dev.alt.textdrive.com/browser/HTTP/IPLocation.lua#L39