Plys – AutoIt superset with namespaces and stuff
-
Recently Browsing 0 members
No registered users viewing this page.
-
Similar Content
-
By tarretarretarre
- _____ _____ _ _ - |_ _|___ ___ ___ _ _| __|___ ___|_|___| |_ - | | | -_| -_| | | |__ | _| _| | . | _| - |_| |___|___|_|_|_ |_____|___|_| |_| _|_| - By TarreTarreTarre|___|Build '1.0.0' |_| + F5 = Run script + F6 = Build 'AU3' + F7 = Build 'EXE' + F8 = Options GUI + F10 = Exit TeenyScript All example code and documentation moved to: http://teenyscript.tarre.nu/documentation
Official Github repo: http://github.com/tarreislam/teenyscript
F.A.Q Q: What is TeenyScript? A: TeenyScript is a Superset of AutoIt which makes it more advanced Q: How does it work? A: TeenyScript code are parsed into native AutoiT code Q: Does it depend on anything else than AutoIt? A: Just one dependency, that is AutoitObject, the best UDF ever created for AutoIt, besides that, only Native AutoIt is used Features
"Anonymous" functions Endless scope nesting OOP (powered by AutoitObject) User-friendly integration Powerful macros Namespaces Lists Project support, for easy deployment Userfriendly GUI for userfriendly Tasks for the Userfriendly person And much more To come
You decide, I am happy to do requests!
Install and Update TeenyScript
HOW TO GET STARTED
Run TeenyScript.au3 Now this should see something like this in your console
Code Press F8 and navigate to the misc tab to install SciTE calltips Run \ Build \ Compile
How to run with Sublime Text
Here is some examples of TeenyScript code
;Basic List usage $Example_A = Func() ; Create a list Local $myList = { 'Name': 'Tarre' } ; Add \ Change data on $MyList $myList{'Age'} = 25 ; Create MySecondList Local $MySecondList = { "Name" => "John", "Age" => "00" } ; Using variable instead of a string Local $KeyName = "Age" Local $KeyVal = 1337 $MySecondList{$KeyName} = $KeyVal ; You may also pass lists to lists. however this has to be done in this fashion. Local $oList = {'myList': $myList, 'mySecondList' => $MySecondList} ; Return the objects Return $oList EndFunc();call the function on the variable ; Loop through list and print their values $Example_B = Func() Local $MyList = {'A': 'Hello FROM A', 'B': 'Hello FROM B', 'C': 'Hello FROM C'} Local $aNames = ['A', 'B', 'C'] For $i = 0 To UBound($aNames) -1 MsgBox(0,0,$myList{$aNames[$i]}) Next EndFunc #MAIN MsgBox(0,"Example A 1", $Example_A.myList.Name) MsgBox(0,"Example A 2", $Example_A.myList.Age) MsgBox(0,"Example A 3", $Example_A.mySecondList.Name) MsgBox(0,"Example A 4", $Example_A.mySecondList.Age) $Example_B(); Execute examble B Here is a non class nested function calculator example (calculator.ts.au3)
$calculator = Func($a, $and, $b) $division = Func($a, $b) if Not $a or Not $b Then Return "Error dividing 0" EndIf Return $a/$b EndFunc Switch $and Case '+' Return $a + $b Case '-' Return $a - $b Case '/' Return $division($a, $b) Case '*' Return $a * $b EndSwitch Return "Unkown attribute "&$and EndFunc #MAIN ConsoleWrite($calculator(25, '*', 25)&@CRLF) ConsoleWrite($calculator(25, '/', 0) & @CRLF) ConsoleWrite($calculator(1, '^', 2) & @CRLF)
teeny-script.zip (OLD)
TeenyScript beta2.zip (OLD)
teeny-script Beta 4.zip (OLD)
teeny-script Beta 5.zip (OLD)
teeny-script BETA 6.zip (OLD)
TeenyScript Beta 7.zip (OLD)
teeny-script Beta 8.zip (OLD)
TeenyScript-master 1.0.0.zip (OLD)
TeenyScript-1.1.0.zip (OLD)
TeenyScript-1.2.0.zip (OLD)
TeenyScript-2.0.0.zip (OLRD, Release notes)
TeenyScript-2.1.3.zip (Newest 2016-09-16, Release notes)
-
By c.haslam
As I understand it: there is no distinction, when a variable is declared outside any function, between declaring it Global and declaring it Local.
This is unfortunate when:
a project has several dialogs: declaration of control variables can conflict. a project has one complex dialog In the latter case, I have one here with a dialog function that is 269 lines!
I could declare all the control variables as Global, but globals should be aoided where possible.
I think good practice would be to put each dialog in its own file (unless it is a really simple one).
Life would be easier if there were a distinction in how variables are declared outside functions:
Global would mean the variable is known to all .au3 files in the project Local would mean that the variable is known only within the file in which it is declared. So control variables could then be declared as known to all functions in the file (module) by declaring them as Local outside any function. Other languages have this feature.
I am working on a project with one not-very-complex dialog. I would like to be able to split its 269 lines into several functions, e.g. the creation of the dialog, enabling/disabling controls based on a control, and updating the values of the controls due to user actions (in this case, a listview). I already have factored out into functions parts that do not involve control variables: verifications of user entries and actions when the user clicks on OK (or equivalents).
Would this be script-breaking change? Probably, but only for those who don't follow the best coding practices: as AutoIt is now, one should not be declaring variables as Local outside functions, because one gets Global anyway. There is nothing Local about a variable declared outside functions.
I will be interested to learn what others think. If this is an old topic, I apologize. If I have it wrong, do tell me.
-
By guinness
If you are coming from the realm of C# 3.0 then lamda expressions should be pretty familiar to you as it's basic syntactic sugar for creating a function with a conditional return.
Since functions in AutoIt are first class objects, the following code should make some sense. It passes an array of integers to a function called IsTrueForAll() that checks whether the function object matches the return condition of that function (you passed). So for example a function called IsGreaterThanOrEqualTo10() checks if all values are greater than or equal to 10 (TRUE). Similarly, IsLessThan10() checks if all values are less than 10 (FALSE). This example should be nothing new to those of you who use v3.3.10.0+ and have an understanding of Call().
#include <MsgBoxConstants.au3> Local $aArray[] = [10, 100, 99, 67] If IsTrueForAll($aArray, IsGreaterThanOrEqualTo10) Then MsgBox($MB_SYSTEMMODAL, '', 'Condition was True.') Else MsgBox($MB_SYSTEMMODAL, '', 'Condition was False') EndIf If IsTrueForAll($aArray, IsLessThan10) Then MsgBox($MB_SYSTEMMODAL, '', 'Condition was True.') Else MsgBox($MB_SYSTEMMODAL, '', 'Condition was False') EndIf Func IsTrueForAll($aArray, $hFunc) ; Loop through the array and check the function passed with a single param matches the condition. For $i = 0 To UBound($aArray) - 1 If Not $hFunc($aArray[$i]) Then Return False EndIf Next Return True EndFunc ;==>IsTrueForAll Func IsGreaterThanOrEqualTo10($x) Return $x >= 10 EndFunc ;==>IsGreaterThanOrEqualTo10 Func IsLessThan10($x) Return $x < 10 EndFunc ;==>IsLessThan10 But, we could easily just forget about writing the functions (less typing is always nice) and let the compiler or pre-processor do all the work for us. It would simply use the lambda expression and create the function for us with whatever we specified. Like so...
#include <MsgBoxConstants.au3> Local $aArray[] = [10, 100, 99, 67] If IsTrueForAll($aArray, $x => $x >= 10) Then ; $x is the parameter, => tells us it's a lambda expression and then the condition we are checking. MsgBox($MB_SYSTEMMODAL, '', 'Condition was True.') Else MsgBox($MB_SYSTEMMODAL, '', 'Condition was False') EndIf If IsTrueForAll($aArray, $x => $x < 10) Then ; $x is the parameter, => tells us it's a lambda expression and then the condition we are checking. MsgBox($MB_SYSTEMMODAL, '', 'Condition was True.') Else MsgBox($MB_SYSTEMMODAL, '', 'Condition was False') EndIf Func IsTrueForAll($aArray, $hFunc) ; Loop through the array and check the function passed with a single param matches the condition. For $i = 0 To UBound($aArray) - 1 If Not $hFunc($aArray[$i]) Then Return False EndIf Next Return True EndFunc ;==>IsTrueForAll...which would create the following code with anonymous functions (they're anonymous as we don't care about them in our main script)...
#include <MsgBoxConstants.au3> Local $aArray[] = [10, 100, 99, 67] If IsTrueForAll($aArray, D3F7B1B92177415CA70C7FFC35C2649C) Then MsgBox($MB_SYSTEMMODAL, '', 'Condition was True.') Else MsgBox($MB_SYSTEMMODAL, '', 'Condition was False') EndIf If IsTrueForAll($aArray, DA06B548ABF4045AA32F805E6651004) Then MsgBox($MB_SYSTEMMODAL, '', 'Condition was True.') Else MsgBox($MB_SYSTEMMODAL, '', 'Condition was False') EndIf Func IsTrueForAll($aArray, $hFunc) For $i = 0 To UBound($aArray) - 1 If Not $hFunc($aArray[$i]) Then Return False EndIf Next Return True EndFunc ;==>IsTrueForAll Func D3F7B1B92177415CA70C7FFC35C2649C($x) Return $x >= 10 EndFunc ;==>D3F7B1B92177415CA70C7FFC35C2649C Func DA06B548ABF4045AA32F805E6651004($x) Return $x < 10 EndFunc ;==>DA06B548ABF4045AA32F805E6651004 Example of parsing a lambda expression and replacing in the chosen script:
#include <WinAPICom.au3> ; Script read from a file. Local $sScript = "#include <MsgBoxConstants.au3>" & @CRLF $sScript &= "" & @CRLF $sScript &= "Local $aArray[] = [10, 100, 99, 67]" & @CRLF $sScript &= "If IsTrueForAll($aArray, $x => $x >= 10) Then" & @CRLF ; Lambda expression. $sScript &= " MsgBox($MB_SYSTEMMODAL, '', 'Condition was True.')" & @CRLF $sScript &= "Else" & @CRLF $sScript &= " MsgBox($MB_SYSTEMMODAL, '', 'Condition was False')" & @CRLF $sScript &= "EndIf" & @CRLF $sScript &= "" & @CRLF $sScript &= "If IsTrueForAll($aArray, $x => $x < 10) Then" & @CRLF ; Lambda expression. $sScript &= " MsgBox($MB_SYSTEMMODAL, '', 'Condition was True.')" & @CRLF $sScript &= "Else" & @CRLF $sScript &= " MsgBox($MB_SYSTEMMODAL, '', 'Condition was False')" & @CRLF $sScript &= "EndIf" & @CRLF $sScript &= "" & @CRLF $sScript &= "Func IsTrueForAll($aArray, $hFunc) ; Loop through the array and check the function passed with a single param matches the condition." & @CRLF $sScript &= " For $i = 0 To UBound($aArray) - 1" & @CRLF $sScript &= " If Not $hFunc($aArray[$i]) Then" & @CRLF $sScript &= " Return False" & @CRLF $sScript &= " EndIf" & @CRLF $sScript &= " Next" & @CRLF $sScript &= " Return True" & @CRLF $sScript &= "EndFunc ;==>IsTrueForAll" & @CRLF ReplaceLambdaInScript($sScript, '$x => $x >= 10') ; Parse the lambda expression and replace it in the above script. ReplaceLambdaInScript($sScript, '$x => $x < 10') ; Parse the lambda expression and replace it in the above script. ConsoleWrite($sScript & @CRLF) ; This is the new script with the lamda expression convert to an anonymous method! ClipPut($sScript) Func CreateLambdaMethod($sExpression) ; Currently no error checking of whether parameters match. Local $bIsReturn = False, _ ; Is the return condition. $sFunction = StringRegExpReplace(_WinAPI_CreateGUID(), '[}{-]', ''), $sParam = '', $sReturn = '' $sFunction = StringRegExpReplace($sFunction, '^\d+', '') ; Remove digits at the beginning of the function name. For $i = 1 To StringLen($sExpression) $sChr = StringMid($sExpression, $i, 1) If $bIsReturn Then $sReturn &= $sChr ElseIf $sChr & StringMid($sExpression, $i + 1, 1) == '=>' Then ; Check for => $i += 1 $bIsReturn = True ElseIf Not $bIsReturn Then $sParam &= $sChr EndIf Next If Not $bIsReturn Then Return "" ; Something went wrong as the => was not found. $sParam = '(' & StringRegExpReplace($sParam, '^\h*|\h*$', '') & ')' $sReturn = @TAB & 'Return ' & $sReturn Return 'Func ' & $sFunction & $sParam & @CRLF & $sReturn & @CRLF & 'EndFunc ;==>' & $sFunction & @CRLF EndFunc ;==>CreateLambdaMethod Func ReplaceLambdaInScript(ByRef $sScript, $sLambda) Local $sFunction = CreateLambdaMethod($sLambda) Local $sFunctionName = StringRegExp($sFunction, 'Func (\w*)\(', 3) If @error Then Return False $sFunctionName = $sFunctionName[0] $sScript = StringReplace($sScript, $sLambda, $sFunctionName, 1) $sScript &= @CRLF & $sFunction Return True EndFunc ;==>ReplaceLambdaInScriptIt was a simple idea I had this morning whilst having breakfast.
-
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now