Last active
April 19, 2021 13:54
-
-
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]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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