Sign in to follow this  
Followers 0
guinness

Lambda expressions - A really rough sketch.

7 posts in this topic

#1 ·  Posted (edited)

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   ;==>ReplaceLambdaInScript
It was a simple idea I had this morning whilst having breakfast. Edited by guinness
1 person likes this

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites



Just in case...


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

The saying is old code should run new code, therefore we don't need to change the function IsTrueForAll(), just the function we pass which contains the condition we are checking.

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Funnily enough I was thinking of mentioning this to you, as you'd already written a preprocessor capable of this.

C# lambdas a quite complex when you get to how they deal with variables used within them. For example look at the following code:

delegate int MulByDelegate(int x);

        static void Main(string[] args)
        {
            MulByDelegate mul1;
            MulByDelegate mul2;

            {
                int mulBy = int.Parse(Console.ReadLine());

                mul1 = (x => x * mulBy);
            }

            {
                int mulBy = int.Parse(Console.ReadLine());

                mul2 = (x => x * mulBy);
            }

            Console.WriteLine("mul1 = {0}", mul1(5));
            Console.WriteLine("mul2 = {0}", mul2(5));
            Console.ReadKey();
        }

This demonstrates that lambdas are first class objects, and are created at runtime. As you'd expect, mul1 does multiplication by the first number you input and mul2 by the second.

Now try this very similar code:

delegate int MulByDelegate(int x);

        static void Main(string[] args)
        {
            MulByDelegate mul1;
            MulByDelegate mul2;

            {
                int mulBy = int.Parse(Console.ReadLine());

                mul1 = (x => x * mulBy);

                mulBy = int.Parse(Console.ReadLine());

                mul2 = (x => x * mulBy);
            }

            Console.WriteLine("mul1 = {0}", mul1(5));
            Console.WriteLine("mul2 = {0}", mul2(5));
            Console.ReadKey();
        }

The only difference is that instead of the mulBy variable going out of scope then being re-declared, it is reused. Now both lambdas should be the same. 

The variable mulBy is captured, rather than just substituted in.

When you disassemble the C# code for the latter, you'll find there is actually a new static class created, called c__DisplayClass2 or something like that, which has mulBy as a member variable. When looking at the byte code of the former you'll see two classes with names like that, both with their own mulBy member.

This page may go some way towards explaining the behaviour and its uses.

Share this post


Link to post
Share on other sites

1. I didn't think about using { } as you did. My mind is quite literally blown.

2. Maybe I am not seeing what you're seeing, because I am using ILSpy.

 

1st

private static void Main(string[] args)
{
    int mulBy2 = int.Parse(Console.ReadLine());
    Program.MulByDelegate mul = (int x) => x * mulBy2;
    int mulBy = int.Parse(Console.ReadLine());
    Program.MulByDelegate mul2 = (int x) => x * mulBy;
    Console.WriteLine("mul1 = {0}", mul(5));
    Console.WriteLine("mul2 = {0}", mul2(5));
    Console.ReadKey();
}
2nd

private static void Main(string[] args)
{
    int mulBy = int.Parse(Console.ReadLine());
    Program.MulByDelegate mul = (int x) => x * mulBy;
    mulBy = int.Parse(Console.ReadLine());
    Program.MulByDelegate mul2 = (int x) => x * mulBy;
    Console.WriteLine("mul1 = {0}", mul(5));
    Console.WriteLine("mul2 = {0}", mul2(5));
    Console.ReadKey();
}

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

IlSpy is too clever, you need to look at the actual byte code. Should be a program called Ildasm in the start menu (it's installed with visual studio).

Even then, the first one is actually changed. Notice how there are now two different variables names rather than one being reused! That actually displays the difference very nicely.

Share this post


Link to post
Share on other sites

I looked at the IL code as well, but I am way too tired right now. Tomorrow I will look and understand.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • ALIENQuake
      By ALIENQuake
      Hello everyone,
      Finally I decide to ask hard question about one of the project which I currently maintain:
      Big World Setup aka mod installer for infinity engine games like BG, IWD, PST etc
      Project page: https://bitbucket.org/BigWorldSetup/bigworldsetup/overview
      More screenshot: https://forums.beamdog.com/discussion/44476/tool-big-world-setup-bws-mod-manager-for-baldurs-gate-enhanced-edition-trilogy-for-windows/p1
      General Features
      downloading mods (please see remarks!) easy mod installation correct install order of mods/components handle mod and components conflicts and auto solve them easy backup creation/restoring ability to add you own mods Internal Features (every single feature which you see here is already working in autoit)
       
      It look as simple GUI application but it has quite complicated logic regarding "handle mod and components conflicts and auto solve them" - this is most important feature of the app.
      This app needs to be converted into multi-platform GUI application because Enhanced Editions of the game can be played on OSX and Linux also. But for the past 6 years, there wasn't a single gamer/developer who would try to convert this app using multi-platform language and GUI. 
      This is the moment when I'm asking for help:
      - Which language would suit the best for multi-platform GUI application?  c#,python,java or other?
      - Is there any general approach for such conversion? 
      - Does autoit community/developer have some experience with converting autoit GUI applications into multi-platform GUI app by using multi-platform language like c#,python,java
      - Is there someone who isn't scared by looking at the source code of the application and feature list to help me with converting or even begin with creating multi-platform GUI app template which will just simply run the same commandline for every system ? 
      If there is something else which you would know, pleas ask and I will try to answer my best.
       
    • JohnOne
      By JohnOne
      I'm trying to follow a tutorial on youtube dealing with service based database.
      In the video, the guy adds a service based database to project, and a DataSource Configuration Wizard pops up, where he selects entity data model, which maps a load of stuff, creates classes automatically, has diagrams the lot, an all singing all dancing dealy, but in my vs2015 it does not pop up, and I don't know how to get to the same place in another fashion, I've only ever used sqlite see.
      Hoping someone know how to do what he does some other way.
      Skip to about 2 minutes if you are interested and can be bothered.
       
    • LuuQuangICT
      By LuuQuangICT
      Hello every body!!!
      I was try this code is work in AutoIt (au3)
      #include <MsgBoxConstants.au3> #include <GuiListView.au3> Global $hWndWindow = WinGetHandle("Form1") Global $hWndLv = ControlGetHandle($hWndWindow, "", "WindowsForms10.SysListView32.app.0.bf7771_r11_ad11") MsgBox($MB_SYSTEMMODAL, "", ControlListView($hWndWindow, "", $hWndLv, "GetItemCount")) _GUICtrlListView_ClickItem($hWndLv, 1, "left", False, 2)  
      But now, I want to use _GUICtrlListView_ClickItem  in C#. I was add reference AutoItX3.dll and AutoItX3.Assembly.dll for my project but i could not found any function which same _GUICtrlListView_ClickItem  from them. Please help me
    • Vexhero
      By Vexhero
      Hello! I have a script in autoit which I made yesterday and Im still getting the hang of autoit
      My question is, is there anyone here who would be able to explain how the convertion would go between AutoIt and C# when it comes to these lines of code, would I need to declare an array to show the $x & $y position? Also The LC is a function I have a bit down the code

       
      While (Not($it_full)) $pixels = PixelSearch(257, 181, 276, 202,0xA19695,10) ;Check color If NOT(@error) Then LC($pixels[0],$pixels[1]) EndIf $pixels = PixelSearch(693, 479, 729, 504,0x000001,3) ;Search If NOT(@error) Then ; MsgBox(0,"Title","Found It!") $it_full = True Sleep(8000) EndIf WEnd  
    • Chocolade
      By Chocolade
      I added to my project in c# referenced the dll's : AutoitX3.Assembly.dll and AutoitX3Lib.dll
      In my code i'm trying to simulate a combination of Ctrl + O
      So I did:
      AutoIt.AutoItX.ControlSend(processTitle, "", processFileName, "^^{r}"); When using a break point:
      In processTitle I see:  Game
      In the processFileName I see: C:\Program Files (x86)\Game\Game\Game.exe
      For checking I looked into Task Manager and there I see in the tab details: Game.exe as name and in Description I see Game
      And if I will click manually on my own Ctrl + O it will work it will do what I need it will take effect.
      But when using the AutoIt it will not work will do nothing no effect at all. And I see it's getting and doing the line with the ControlSend but nothing
      happen.
      And it did work few hours ago. What is wrong ?