Skip to content

Instantly share code, notes, and snippets.

@djfdyuruiry
Last active April 19, 2021 13:54
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment