lua-users home
lua-l archive

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


Robert Raschke wrote:

On Mon, Apr 26, 2010 at 4:25 PM, Lorenzo Donati wrote:

    Now to the point.
    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. My purpose is to build applications in pure Lua (or wxLua)
    that can automatically find their modules/components/data without
    any installation or shell script launcher (I'm playing with
    executables created using wxLuafreeze and plan also to use srlua to
    achieve a similar effect with plain Lua).
    I've searched the archive but found only some suggestions to parse
    arg[0], but this doesn't always work.


I don't think this is possible without using C. I use GetModuleFileName() in my Windows C startup code to find where the EXE is that got invoked.

But there's also the location of a particular Lua script you're getting via require. I don't know if that allows you to figure out where it came from.

Depending on how "proper" Lorenzo wants it to work, for "100% works" Unicode paths may also have to be supported... Hard to accomplish using pure Lua.

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia