Skip to content

Instantly share code, notes, and snippets.

@chip
Created January 28, 2026 17:25
Show Gist options
  • Select an option

  • Save chip/79c40b0491e715054bbe7cdaeb509af0 to your computer and use it in GitHub Desktop.

Select an option

Save chip/79c40b0491e715054bbe7cdaeb509af0 to your computer and use it in GitHub Desktop.
Lua get pwd, open file, read data
function open_file(filename)
local dir = io.popen("pwd"):read()
local path = dir .. filename
local file = io.open(path, "rb")
if not file then return nil end
local data = file:read("*ab")
return data
end
print(open_file("/lua/tests/fixtures/MARKDOWN.lua"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment