Lua4z
A binary distribution of Lua for z/OS, with batteries
-- Print paths that affect Lua

-- Splits string into lines at delimiter; optionally indent each line
function string.lines(s, delim, indent)
  indent = indent or 0
  local lines = s:gsub("([^%" .. delim .. "]+)%" .. delim .. "?",
    string.rep(" ", indent) .. "%1\n")
  return lines
end

-- Define the paths
-- (define values as functions to differentiate between
-- undefined value variable and nil value)
local paths = {
  { name = "package.path",
    description = "Initialized from LUA_PATH environment variable"},
  { name = "package.cpath",
    description = "Initialized from LUA_CPATH environment variable"},
  { name = "PATH environment variable",
    description = "Executable program search path",
    value = function () return os.getenv("PATH") end,
    delim = ":"},
  { name = "LIBPATH environment variable",
    description = "DLL search path",
    value = function () return os.getenv("LIBPATH") end,
    delim = ":"}
}

-- Indent paths under headings
local indent = 2

-- Print the paths
for _, path in ipairs(paths) do
  -- Print path name and description
  print(path.name .. ": " .. path.description)
  if path.value then
    -- Path value defined as function: call the function
    path.value = path.value()
  else
  -- No path value specified:
  -- interpret the name as a variable that contains the value
    path.value = loadstring("return " .. path.name)()
  end
  if path.value then
    -- Default path delimiter is a semicolon
    path.delim = path.delim or ";"
    -- Print path split into lines indented 2 spaces
    print(path.value:lines(path.delim, indent))
  else
    -- PATH is undefined when running Lua on MVS
    print(string.rep(" ", indent) .. "not defined\n")
  end
end