Instead of making a Othersyntax command, I think it would be better if ahk supported file-here notation - this would have more general usage. This could be supported by a dll that hosts an ActiveScript engine - allowing the usage of all ActiveScript compatible scripting languages -Perl, Python, VbScript, JScript, RubyScript and others. Then you'd have wrapper functions for the dll - like with the perl interface.
File-here is like this -
Code:
var = << EOF
#some ruby code
class Blah
def sneeze(duration)
puts "Ach" + ("o" * duration)
end
end
EOF
ActiveEval(var,"RubyScript")
Basically everything between the << EOF (which can be any word)
and it's counter part is totally excluded from parsing by ahk - so you can use quotes and such freely, except maybe for %variable%. Avoiding the need for escapes would greatly ease the use of other scripting languages. The contents of these blocks would be stuck into whatever variable they would be pointed at. Maybe the syntax could leave off the = as well.
I'll look at making the dll.
EDIT:
F*ck this. Leave it up to M$ to write a completely unusable api. Practically no documentation and waaay to much code to just tack on an ActiveScript site. If someone more comfortable with c++ wants to take a stab at it
http://www.codeproject.com/com/mfcscripthost.asp seems to be a good resource.
EDIT:
NYAHAHAHAHA!

I WIN!
Put this in peval.vbs
Code:
Dim StdIn, script
script = ""
Set StdIn = WScript.StdIn
Do While Not StdIn.AtEndOfStream
script = script + StdIn.ReadLine
Loop
execute script
Here's an example:
Code:
F1::
text := RunVBS("WScript.echo ""howdy""")
Msgbox, %text%
return
;CMDRet functions
RunWaitEx(CMD, CMDdir, CMDin, ByRef CMDout, ByRef CMDerr)
{
VarSetCapacity(CMDOut, 100000)
VarSetCapacity(CMDerr, 100000)
RetVal := DllCall("cmdret.dll\RunWEx", "str", CMD, "str", CMDdir, "str", CMDin, "str", CMDout, "str", CMDerr)
Return, %RetVal%
}
Capture(CMD, input)
{
CMDOUT =
CMDERR =
RunWaitEx(CMD, a_scriptdir, input, CMDOUT, CMDERR)
return %CMDOUT%
}
;let's run some vbscript stuff
RunVBS(script)
{
return Capture("cscript.exe peval.vbs",script)
}
It uses CMDRet and a pipe-reading vbscript to do it. Basically you pipe the script you want to run into peval.vbs and IT runs the code in execute(). Doesn't need a special dll, and doesn't need a temporary file. Just needs CMDRet.dll and peval.vbs.
So lets look at what this would look like with CMDRet built into AHK, and file-here syntax added :
Code:
adminstuff = << EOF
Option Explicit
Dim FSO
Dim Services
Dim SecDescClass
Dim SecDesc
Dim Trustee
Dim ACE
Dim Share
Dim InParam
Dim Network
Const FolderName = "C:\Public"
Const AdminServer = "\\AdminMachine"
Const ShareName = "Pubs"
Const PrinterShare = "\\CorpPrinters\PrinterShare"
' First we add a printer to this machine and make it the default.
Set Network = CreateObject("Wscript.Network")
Network.AddWindowsPrinterConnection PrinterShare
Network.SetDefaultPrinter PrinterShare
' Next we create a folder and populate it with some files.
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.FolderExists(FolderName) Then
FSO.CreateFolder(FolderName)
End If
Call FSO.CopyFile(AdminServer & "\Public\Images\*.*", FolderName)
' Make the folder into a share using WMI
' See the WMI SDK for information on how this code works.
Set Services = GetObject("WINMGMTS:{impersonationLevel=impersonate,(Security)}!" & AdminServer & "\ROOT\CIMV2")
Set SecDescClass = Services.Get("Win32_SecurityDescriptor")
Set SecDesc = SecDescClass.SpawnInstance_()
Set Trustee = Services.Get("Win32_Trustee").SpawnInstance_
Trustee.Domain = Null
Trustee.Name = "EVERYONE"
Trustee.Properties_.Item("SID") = Array(1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)
Set ACE = Services.Get("Win32_Ace").SpawnInstance_
ACE.Properties_.Item("AccessMask") = 2032127
ACE.Properties_.Item("AceFlags") = 3
ACE.Properties_.Item("AceType") = 0
ACE.Properties_.Item("Trustee") = Trustee
SecDesc.Properties_.Item("DACL") = Array(ACE)
Set Share = Services.Get("Win32_Share")
Set InParam = Share.Methods_("Create").InParameters.SpawnInstance_()
InParam.Properties_.Item("Access") = SecDesc
InParam.Properties_.Item("Description") = "Public Share"
InParam.Properties_.Item("Name") = ShareName
InParam.Properties_.Item("Path") = FolderName
InParam.Properties_.Item("Type") = 0
Share.ExecMethod_("Create", InParam)
EOF
RunVBS(adminstuff)
RunVBS(script)
{
return Capture("cscript.exe peval.vbs",script)
}
There's little weird syntax and it's readily adaptable to a variety of scripting languages and other programs.
And python and ruby both support piping scripts into them, so there's those working with no trouble. Come to think of it, embedding ActiveScript probably wouldn't be the answer anyway, because you would lose the functionality of WSH, leaving vbscript considerably less useful.
Here's a quick example for piping scripts to ruby.
Code:
F2::
text := Capture("ruby",
(
"class Blah
def sneeze(duration)
puts ""Ach"" + (""o"" * duration)
end
end
Blah.new.sneeze(5)")
)
Msgbox, %text%
return