Skip to content

Instantly share code, notes, and snippets.

@quienn
Last active November 26, 2022 19:22
Show Gist options
  • Save quienn/9032648e74f3093e21f74610bd611ce7 to your computer and use it in GitHub Desktop.
Save quienn/9032648e74f3093e21f74610bd611ce7 to your computer and use it in GitHub Desktop.
Set-LuaVersion: hererocks Wrapper for Windows PowerShell
function Set-LuaVersion {
param(
[string]$Hererocks = "$HOME\Dev\Lua",
[switch]$Jit,
[Parameter(Mandatory=$true,Position=0)]
[string]$Version
)
$LuaVersion = $(if ($Jit) { "jit$Version" } else { $Version })
# If there's already a Lua version activated, run the deactivation script.
if (Get-Command deactivate-lua -ErrorAction SilentlyContinue) {
deactivate-lua
}
if (Test-Path "$Hererocks\$LuaVersion") {
. "$Hererocks\$LuaVersion\bin\activate.ps1"
} else {
Write-Warning "Downloading version $Version..."
# Starts the installation process of the missing $Version
if ($Jit) {
hererocks "$Hererocks\$LuaVersion" -j $Version -rlatest
} else {
hererocks "$Hererocks\$LuaVersion" -l $LuaVersion -rlatest
}
. "$Hererocks\$LuaVersion\bin\activate.ps1"
}
}
Set-Alias -Name slv -Value Set-LuaVersion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment