Jump to content

Plys – AutoIt superset with namespaces and stuff


NSUSpray
 Share

Recommended Posts

629626601_.png.451805a667e764185531eff0ad97f034.png

Plys (/ˈplz/) represents the inconspicuous wrapper which complements the AutoIt language with

  1. preprocessor keyword #import "filename" loads only public functions and variables
  2. Python-like code blocks by lines indentation (without endfunc, wend etc.)
  3. dim and const outside of functions means global and global const respectively, inside of functions means local and local const
  4. arguments of function are const by default, but with dim prefix it becomes variable
  5. short synonyms for functions as a rule using in large projects: for arrays, files and strings
  6. no “$” prefix in variable names
  7. single-line anonymous functions
  8. and each of this is optional

Overview

; file “mylib.aup”

dim foo*, bar

func baz*()
    foo = quux()

func quux(dim arg="one/two/three")
    bar = Sort(Split(arg, "/", @NoCount))
    return "begin" . @ . bar[0] . @ . "end"
; file “main.aup”

#import "mylib.aup"

In this example variable bar and function quux() are private for module mylib.aup (names at declaration ends with an asterisk) and not visible in main.aup. Variable foo and function baz() will be visible with the “mylib:” prefix:

; file “main.aup”

#import "mylib.aup"

foo = baz()  ; error: no foo and baz() in this scope
mylib:foo = mylib:baz()  ; OK: foo and baz() are public in “mylib” scope
mylib:bar = mylib:quux()  ; error: bar and quux() are private in “mylib” scope

Sort is synonym for _ArraySort, Split is synonym for StringSplit, @NoCount is synonym for $STR_NOCOUNT, “@” is synonym for @CRLF, “.” is synonym for “&” operator.

All synonyms

Spoiler

Add ColDelete ColInsert Combinations Display Extract FindAll Insert Max MaxIndex Min MinIndex Permute Pop Push Search Shuffle Sort Swap ToClip Transpose Trim Unique → _Array*
ToHist → _Array1DToHistogram
BinSearch → _ArrayBinarySearch
Concat → _ArrayConcatenate

ChangeDir Copy CreateShortcut Flush GetAttrib GetEncoding GetLongName GetShortcut GetShortName GetSize GetTime GetVersion Open Opendialog Read ReadLine ReadToArray Recycle RecycleEmpty SaveDialog SelectFolder SetAttrib SetEnd SetPos SetTime Write WriteLine → File*
CreateLink → FileCreateNTFSLink
FirstFile → FileFindFirstFile
NextFile → FileFindNextFile

Struct → DllStructCreate
StructGet → DllStructGetData
StructGetSize → DllStructGetSize
StructGetPtr → DllStructGetPtr
StructSet → DllStructSetData

Echo → ConsoleWrite

AddCR Format InStr IsAlNum IsAlpha IsASCII IsDigit IsLower IsSpace IsUpper IsXDigit Left Len Lower Mid Replace Right Split StripCR StripWS TrimLeft TrimRight Upper → String*
ReFind → StringRegExp
ReReplace → StringRegExpReplace

Activate Active Flash GetCaretPos GetClassList GetClientSize GetProcess GetTitle Kill List MenuSelectItem MinimizeAll MinimizeAllUndo SetOnTop SetTitle SetTrans Wait WaitActive WaitClose WaitNotActive → Win*

@ReMatch → $STR_REGEXPMATCH
@ReArray @ReArrayFull @reArrayGlobal @reArrayGlobalFull → $STR_REGEXP*MATCH

@NoCaseSense @CaseSense @NoCaseSenseBasic @StripLeading @StripTrailing @StripSpaces @StripAll @ChrSplit @EntireSplit @NoCount @EndNotStart @UTF16 @USC2 → $STR_*

@ → @CRLF
@ActiveWin → WinGetHandle("[ACTIVE]")
@CmdLine → $CmdLine

. → &
.= → &=

Setup

Requirements: AutoIt (minimum), AutoIt Script Editor (optionally).

  1. Download and unpack archive from latest release.
  2. Double click the “setup.aup.au3” file and follow to setup instructions.

First steps

  1. Right-click in the any folder and select New > AutoIt Plys Script.

  2. Right-click on the created file again and select Edit Script.

  3. At the bottom of the file type the following:

    #include <MsgBoxConstants.au3>
    dim msg = ""
    for i = 1 to 10
        msg .= "Hello World!" . @
    msg = TrimRight(msg, 1)
    MsgBox(MB_OK, "My First Plys Script", msg)
  4. Save the script and double-click the file for run (or right-click the file and select Run Script).

Extra options

You can use extra options by typing in the script one of this:

#plys dollarprefix  ; refuse to use variables without “$” prefix
#plys noconst  ; use default variable declarations behavior
#plys noindent  ; ignore indentation but obligue to use “endif/wend/etc”.
#plys noimport  ; refuse the import operator
#plys nosynonyms  ; refuse the function and macro synonyms
#plys nolambda  ; refuse the anonymous functions

Environment

After installation Plys already integrated to Windows shell. If you want to run a script by command line use

<AutoIt3.exe path> <AutoIt3exe folder>\Plys\plys.aup.au3 [/Rapid] [/ErrorStdOut] [/NoStdio] <script path> [<arguments>]

/Rapid means that if source files have not be modified since the previous run, they will not be re-translated. This option speeds up script execution startup.

The /ErrorStdOut switch allows the redirection of a fatal error to StdOut which can then be captured by an application.

Also you can turn off data exchange through standard input/output streams, then the shell process will not hang in memory, but then you will not be able to observe the output of your program in the output window of your development environment. You can do this by adding the /NoStdio option.

If you want to translate a script to pure AutoIt code use

<AutoIt3.exe path> <AutoIt3exe folder>\Plys\plys.aup.au3 [/Translate] <script path>

Try AutoIt Plys package for Sublime Text which including syntax highlighting, auto-completions, build systems for run and compile, context help, “goto” feature, comments toggling, Tidy and Include Helper command for AutoIt and AutoIt Plys.

128544520_.png.f8e97997aa5cd7de8187bb3e97def90b.png

 

You can compile the script, specifying to the compiler the translated file *.aup.au3.

How it works

The plys.aup.au3 file contains the code that will run immediately after the launch of your script. On setup this file will copy to AutoIt install dir (as Plys\plys.aup.au3) and aup-files will associated with it. On the launch aup-files are automatically processed, after which the new AutoIt process interprets the already converted code, and the current process remains cycle to continue data exchange with the new process via standard streams. This handler replaces all #import with #include. The processed files get the extension .aup.au3 and are placed in the folder of the original script with “hidden” attribute.

Future

  • #import "filename.aup" noprefix
#import "mylib.aup" noprefix

bar = foo()
; bar and foo will be taken from the “mylib.aup” without “mylib:” prefix
  • #import "filename.aup" as alias
#import "mylib.aup" as ml

ml:bar = ml:foo()  ; bar and foo will be taken from the “mylib.aup”
  • function scope functions

func GlobalFunc()
    dim var1 = "body"
    func LocalFunc(var2)
        return "begin" . @ . var2 . @ . "end"
    return LocalFunc(LocalFunc(var1))

MsgBox(MB_OK, "begin/body/end", GlobalFunc())
  • array values in place and array comprehension

a = [3, 7, 1]
for i in [1, 2, 4]
    Echo(i . @)
    Display([t*3 for t in a if t > i])  ; if i = 2 then Display([9, 21]) etc.

 

Download

Repository on GitHub

Very old version (import only): import

 

Edited by NSUSpray
Version 0.5.0
Link to comment
Share on other sites

Fixed: Wrapper used case-sensitive mode instead insensitive (could found “local …” but not “Local …”).

Critical! The algorithm did not work correctly for programs written in the generally accepted style (!), when keywords are started with a capital letter.

Link to comment
Share on other sites

Massive update!

  • Python-like blocking by lines indentation (without endfunc, wend etc.)
  • dim and const outside of functions means global and global const respectively, inside of functions means local and local const
  • arguments of function are const by default, but with dim prefix it becomes variable
  • short synonyms for functions as a rule using in large projects: for arrays, files and strings
Edited by NSUSpray
Link to comment
Share on other sites

  • NSUSpray changed the title to AutoIt plys – syntax additions for comfortable coding (file scope namespaces and stuff)
  • NSUSpray changed the title to Plys – Light Your AutoIt Code! (AutoIt superset with namespaces and stuff)

Version 0.4.0

  • Rewrited on Plys
  • Added automatic installation
  • Added shell integration: run and translate to AutoIt by double click or context menu
  • Public via * at declaration instead private via _ (underscore)
  • Added operator/macro synonyms for &, &= and @CRLF
  • Added lambda (anonymous functions) feature

Version 0.4.3

  • Added compiled HTML Help with examples (aup-script files)

Version 0.4.4

  • Fixed: incorrect line number and filename in error out

https://github.com/NSUSpray/Plys/releases/tag/v0.4.4

Edited by NSUSpray
Version 0.4.4
Link to comment
Share on other sites

  • NSUSpray changed the title to Plys – AutoIt superset with namespaces and stuff

Version 0.5.0

  • Added: rapid start option /Rapid
  • Added: substitution of macros @ScriptFullPath, @ScriptName and @ScriptLineNumber
  • Added: macros @PlysPath and @PlysVersion
  • Added: Unicode support for stderr and stdout streams
  • Added: process the error window message, the notification area tool tip and icon
  • Changed: translation algorithm for better performance
  • Changed: Plys options for each file
  • Changed: /NoStdio command line switch instead “#plys nostdio” line in script
  • Changed: lambda feature enabled by default
  • Fixed: tab to spaces conversion is broken
  • Fixed: dollar prefix is appended for “until” keyword
  • Fixed: incorrect line enumeration
  • Fixed: extra endif after single-line if..then and decreasing indent

https://github.com/NSUSpray/Plys/releases/tag/v0.5.0

Edited by NSUSpray
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...