Q:

Get containing path of lua file

I am wondering if there is a way of getting the path to the currently executing lua script file? 
This is specifically not the current working directory, which could be entirely different. I know luafilesystem will let me get the current working directory, but it doesn't seem to be able to tell the current executing script file.
Thanks
EDIT:
I'm not running from the standard command line interpreter, I am executing the scripts from a C++ binary via luabind.

A:

This is a more elegant way:
function script_path()
   local str = debug.getinfo(2, "S").source:sub(2)
   return str:match("(.*/)")
end

print(script_path())

A:

If the Lua script is being run by the standard command line interpreter, then try arg[0].

A:

As lhf says:
~ e$ echo "print(arg[0])" > test.lua
~ e$ lua test.lua
test.lua
~ e$ cd /
/ e$ lua ~/test.lua
/Users/e/test.lua
/ e$ 

Here's the same info using the debug.getinfo mechanism
~ e$ echo "function foo () print(debug.getinfo(1).source) end; foo()" > test.lua
~ e$ lua test.lua
@test.lua
~ e$ cd /
/ e$ lua ~/test.lua
@/Users/e/test.lua
/ e$ 

This is available from the C API lua_getinfo

