lua-users home
lua-l archive

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


Just want to note that debug.getinfo() could return source file for
current function. I think this is more correct approach than working
with arg[] as not all code is loaded from shell.

You may try to saving this code to separate file and call it from other
directory.

--[ test_path.lua ]--
local print_info =
  function()
    local level = 0
    while true do
      local info = debug.getinfo(level, 'S')
      if not info then
        break
      end
      print(('%2d [%s]'):format(level, info.source))
      level = level + 1
    end
  end

print_info()
--[]--

(debug.getinfo(level) returns table with information about function
<level>s up.)