Skip to content

Instantly share code, notes, and snippets.

@djfdyuruiry
Last active May 5, 2025 18:44
Show Gist options
  • Save djfdyuruiry/4e8ba66b336235f419b25a9fc27793c4 to your computer and use it in GitHub Desktop.
Save djfdyuruiry/4e8ba66b336235f419b25a9fc27793c4 to your computer and use it in GitHub Desktop.
Simple lua module to get the path to the temporary directory on the current host (e.g. '/tmp') [https://ideone.com/675UZR]
local function getTempPath()
local directorySeperator = package.config:match("([^\n]*)\n?")
local exampleTempFilePath = os.tmpname()
-- remove generated temp file
pcall(os.remove, exampleTempFilePath)
local seperatorIdx = exampleTempFilePath:reverse():find(directorySeperator)
local tempPathStringLength = #exampleTempFilePath - seperatorIdx
return exampleTempFilePath:sub(1, tempPathStringLength)
end
return getTempPath
@Buy-One
Copy link

Buy-One commented May 5, 2025

Also os.getenv('TEMP')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment