Skip to content

Instantly share code, notes, and snippets.

@anonhostpi
Last active January 17, 2024 12:04
Show Gist options
  • Save anonhostpi/c18abd1158dce07ff18ab94e3111a514 to your computer and use it in GitHub Desktop.
Save anonhostpi/c18abd1158dce07ff18ab94e3111a514 to your computer and use it in GitHub Desktop.
The PowerShanos Thanos Shauntlet
using namespace Python.Runtime
# Import the C# libraries:
Import-Package pythonnet
Import-Package Microsoft.ClearScript
Import-Package NLua
Import-Package IronRuby.Libraries
Import-Package R.NET
# Setup Python:
& {
$dll = where.exe python | ForEach-Object {
$root = $_ | Split-Path -Parent
$name = $root | Split-Path -Leaf
"$root\$name.dll"
} | Where-Object { Test-Path $_ } | Resolve-Path
[Python.Runtime.Runtime]::PythonDLL = $dll
[Python.Runtime.PythonEngine]::Initialize() | Out-Null
[Python.Runtime.PythonEngine]::BeginAllowThreads() | Out-Null
}
$lock = [Py]::GIL()
# Import the CPython libraries:
$py = [Py]::Import("builtins")
$java = [py]::Import("jpype")
$julia = [py]::Import("julia")
# Setup JavaScript:
$js = [Microsoft.ClearScript.V8.V8ScriptEngine]::new()
$js.AddHostType( [System.Console] )
# Setup Lua:
$lua = [NLua.Lua]::new()
# Setup Ruby:
$ruby = [IronRuby.Ruby]::CreateRuntime().GetEngine("rb")
# Setup R:
$r = [RDotNet.REngine]::GetInstance()
# Setup Java:
[py]::import("jpype.imports") | Out-Null
[py]::import("jpype.types") | Out-Null
$java.startJVM()
# Setup Julia:
# $julia.install() # needs to be run the first time you run PyJulia
[py]::import("julia.Base") | Out-Null
# PowerShell built-ins:
[System.Console]::WriteLine( "Hello World from C#, F#, and VB!" )
Write-Host "Hello World from PowerShell!"
# C# embeds:
Write-Host
$js.Script.Console.WriteLine( "Hello World from JavaScript!" ) | Out-Null
$lua.GetFunction( "print" ).Call( "Hello World from Lua!" )
$ruby.Execute("puts 'Hello World from Ruby!'")
$r.Evaluate('cat("Hello World from R!")') | Out-Null
# CPython embeds:
Write-Host
$py.print( "Hello World from CPython!" )
$java.JPackage("java.lang").System.out.println("Hello World from Java!")
$julia.Base.print('Hello World from Julia!')
$lock.Dispose()
$java.shutdownJVM()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment