Skip to content

Instantly share code, notes, and snippets.

@DJStompZone
Last active January 23, 2025 14:30
Show Gist options
  • Save DJStompZone/1974d946dd523728ccca61ee3ed75d30 to your computer and use it in GitHub Desktop.
Save DJStompZone/1974d946dd523728ccca61ee3ed75d30 to your computer and use it in GitHub Desktop.
Fix Backticks (Lua)
<#
.SYNOPSIS
Processes a Lua file by replacing certain characters.
.DESCRIPTION
The script checks if `v.l` or `vehicles.lua` exists. If `v.l` exists, it uses that for processing. Otherwise, it renames `vehicles.lua` to `v.l` and processes the file content to replace backticks with single quotes.
.AUTHOR
DJ Stomp <[email protected]>
.LICENSE
MIT
.LINK
https://gist.githubusercontent.com/DJStompZone/1974d946dd523728ccca61ee3ed75d30
#>
$luaFile = "vehicles.lua"
$tempFile = "v.l"
try {
# Check if either file exists
if (-Not (Test-Path $luaFile) -and -Not (Test-Path $tempFile)) {
Write-Error "Neither '$luaFile' nor '$tempFile' exists. Exiting."
exit 1
}
# If `v.l` doesn't exist but `vehicles.lua` does, rename it
if (-Not (Test-Path $tempFile) -and (Test-Path $luaFile)) {
Rename-Item -Path $luaFile -NewName $tempFile
Write-Host "Renamed '$luaFile' to '$tempFile'."
} else {
Write-Host "'$tempFile' already exists. Using it for processing."
}
# Process the content of the file
python -c @"
with open('v.l', 'r+', encoding='utf-8') as fp:
_d = fp.read().replace(chr(96), chr(39))
open('vehicles.lua', 'w', encoding='utf-8').write(_d)
"@
Write-Host "File processed successfully."
} catch {
Write-Error "An error occurred: $_"
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment