Skip to content

Instantly share code, notes, and snippets.

@HumanEquivalentUnit
Last active December 21, 2019 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HumanEquivalentUnit/c0578ec228878abd1baf353e2ea38567 to your computer and use it in GitHub Desktop.
Save HumanEquivalentUnit/c0578ec228878abd1baf353e2ea38567 to your computer and use it in GitHub Desktop.
PowerShell Cmdlet in Dyalog APL proof of concept
⍝ This is in a workspace, default namespace
⍝ created by )Ed ○InvokeAplExpression
⍝ Then exported as a Microsoft .Net Assembly
⍝ With the Isolation Mode dropdown set to
⍝ 'Each assembly attempts to use local bridge and interpreter libraries'
⍝ pre-req: make a project folder e.g. "D:\m\" and copy file
⍝ System.Management.Automation.dll from the .Net GAC into it.
⍝ PS> Copy-Item -Path ([psobject].Assembly.Location) -Destination 'd:\m\' -Verbose
⍝ (this path is in the :Using line, because loading from the GAC doesn't find it)
⍝ After exporting the DLL open an Admin PowerShell session, and:
⍝ 1) copy the DLL to the Dyalog folder, so it can find the bridge DLLs
⍝ PS> Copy-Item D:\m\AplTest.dll 'C:\Program Files\Dyalog\Dyalog APL-64 17.1 Unicode\'
⍝ 2) change to folder
⍝ PS> cd 'C:\Program Files\Dyalog\Dyalog APL-64 17.1 Unicode\'
⍝ 3) import it
⍝ PS> Import-Module .\AplTest.dll -Verbose
⍝ 4) check for exported cmdlets, should be one
⍝ PS> Get-command -module apltest
⍝ 5) run it, get output 1 2 3
⍝ PS> Invoke-AplExpression
:Class InvokeAplExpression : Cmdlet
:Using System
:Using System.Management.Automation,D:\m\System.Management.Automation.dll
:Access public
:Attribute CmdletAttribute VerbsLifecycle.Invoke 'AplExpression'
⍝ This field needs ParameterAttribute
⍝ to allow PS> Invoke-AplExpression -AplCode '⍳ 5'
⍝ but this attempt doesn't work, the default '⍳ 3' only runs
:Field Public Instance AplCode ← '⍳ 3'
:Attribute ParameterAttribute
∇ BeginProcessing
:Access protected override
:Signature Void←BeginProcessing
WriteObject(⊂⍎AplCode)
:EndClass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment