Jump to content

Addons a.k.a Plugins for Autoit


Oldschool
 Share

Recommended Posts

Put testing.au3 @ScriptDir, compile the script and execute.

;testingDynFuncs
#Include <File.au3>
#Include <IE.au3>
Global $DynamicFuncs

If Not _FileReadToArray(@ScriptDir & "\testing.au3", $DynamicFuncs) Then
   MsgBox(4096,"Error", " Error reading the formula ==>>  error:" & @error)
   Exit
EndIf

MsgBox(0, "",_DynFunc("31"))
Func _DynFunc($number)
    Local $oIE
    For $i = 1 To $DynamicFuncs[0]
        Select
            Case StringInStr($DynamicFuncs[$i], "If") And StringInStr($DynamicFuncs[$i], "Return")
                $var = StringRegExp($DynamicFuncs[$i], '(?i)If(.*)Then', 3)
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)Return(.*)', 3)
                If Execute($var[0]) Then Return Execute($var1[0])               
            Case StringInStr($DynamicFuncs[$i], "If")
                $var = StringRegExp($DynamicFuncs[$i], '(?i)If(.*)Then', 3)
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)Then(.*)', 3)
                If Execute($var[0]) Then Execute($var1[0])          
            Case Not StringInStr($DynamicFuncs[$i], "If")
                Execute($DynamicFuncs[$i])
        EndSelect
    Next
    Return "It Works!"
EndFunc  ;<===_DynFunc

testing.au3

If $number > 30 Then $oIE = _IECreate( "www.autoitscript.com/images/autoit_6_240x100.jpg", 1, 1)
WinMove($oIE, "", 0, 0, 600, 800)
_IELoadWait($oIE)
MouseClick("Left", 450, 105)
Send("{BACKSPACE 50}")
Send("http://www.autoitscript.com/forum/index.php?showtopic=63654")
Send("{ENTER}")
Sleep(5000)
DllCall("user32.dll", "int", "MessageBox", "hwnd", 0, "str", "Too bad you can't smoke it!", "str", "Dynamic Func", "int", 0)
Edited by Oldschool
Link to comment
Share on other sites

AutoIt already has plugins. They are simply undocumented.

They are now.

Plugins probably shouldn't be open source because then the end user could (intentionally or not) change the code and cause problems.

In my particular case, or as can be seen here:

http://www.autoitscript.com/forum/index.ph...c=63528&hl=

having open source user defined functions is required or desirable.

The whole point of this script is to allow the end users to add proprietary logic to certain functions of the script without reveling their logic to the developer. At the same time the developer does not have to share his source with the end user. This makes your program customizable without the need to recompile.

Edited by Oldschool
Link to comment
Share on other sites

A good example about using plugins is here (Zip Plugin by eltorro).

Só o que posso lhe dizer, bom é quando faz mal!My work:Au3Irrlicht - Irrlicht for AutoItMsAgentLib - An UDF for MSAgentAu3GlPlugin T2 - A 3D plugin for AutoIt...OpenGl Plugin - The old version of Au3GlPlugin.MAC Address Changer - Changes the MAC AddressItCopter - A dragonfly R/C helicopter simulator[center]VW Bug user[/center]Pinheiral (Pinewood) city: http://pt.wikipedia.org/wiki/Pinheiral

Link to comment
Share on other sites

EDIT: I Need new glasses..:) Thanks to OldSchool for the sample belove. I have updated my code here so it works to as I find the func names used by Oldschool misleading. But That is probably due to different minds interpreting differently :waco:

The whole point of this script is to allow the end users to add proprietary logic to certain functions of the script without reveling their logic to the developer. At the same time the developer does not have to share his source with the end user. This makes your program customizable without the need to recompile.

Could you please provide a sample where the user calls a function in your script and gets a return value from the call?

Say you have a function AppLog($msg) function in your main script. And the user wants to write to the log.

Something like this (does not work as I expect..:) )

#Include <File.au3>
#Include <IE.au3>
Global $DynamicFuncs

Func Main()
    ; Cleanup old and write new test script
    Local $file = @ScriptDir & "\testing.au3"
    FileDelete($file)
    FileWrite($file, 'If 0 = AppLog("Log This") Then AppLog("Oh, NO UNEXPECTED!")' & @CRLF)
    FileWrite($file, 'If 911 = AppLog("And this") Then AppLog("Error 911")' & @CRLF)
    ; Execute test script
    If ReadPlugin($file) Then ScriptRun("31")
    ; TODO: Add error handling and legal check of script
EndFunc

; === Read the plugin (script) file.
Func ReadPlugin($file)
    If Not _FileReadToArray($file, $DynamicFuncs) Then
       MsgBox(4096,"Error", " Error reading the formula ==>>  error:" & @error)
       Return SetError(1, 0, 0)
    EndIf
    Return 1
EndFunc

; ===
Func AppLog($msg)
    ConsoleWrite("--> AppLog(" & $msg & ")" & @crlf)
    Return 911
EndFunc

; === ScriptRun Used to be _DynFunc. Dependency on global array should be removed.
Func ScriptRun($number)
    Local $oIE
    For $i = 1 To $DynamicFuncs[0]
        Select
            Case StringInStr($DynamicFuncs[$i], "If") And StringInStr($DynamicFuncs[$i], "Return")
                $var = StringRegExp($DynamicFuncs[$i], '(?i)If(.*)Then', 3)
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)Return(.*)', 3)
                If Execute($var[0]) Then Return Execute($var1[0])            
            Case StringInStr($DynamicFuncs[$i], "If")
                $var = StringRegExp($DynamicFuncs[$i], '(?i)If(.*)Then', 3)
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)Then(.*)', 3)
                If Execute($var[0]) Then Execute($var1[0])     
            Case Not StringInStr($DynamicFuncs[$i], "If")
                Execute($DynamicFuncs[$i])
        EndSelect
    Next
    Return 1
EndFunc  ;<===_DynFunc
; === Call main
Main()
Edited by Uten
Link to comment
Share on other sites

Could you please provide a sample where the user calls a function in your script and gets a return value from the call?

Say you have a function AppLog($msg) function in your main script. And the user wants to write to the log.

Something like this (does not work as I expect..:) )

#Include <File.au3>
Global $DynamicFuncs

If Not _FileReadToArray(@ScriptDir & "\UserDefined.au3", $DynamicFuncs) Then
   MsgBox(4096,"Error", " Error reading the formula ==>>  error:" & @error)
   Exit
EndIf

MsgBox(0, "",_DynFunc())
Func _DynFunc()
    Local $file = @ScriptDir & "\mylog.txt"
    For $i = 1 To $DynamicFuncs[0]
        Select
            Case StringInStr($DynamicFuncs[$i], "If") And StringInStr($DynamicFuncs[$i], "Return")
                $var = StringRegExp($DynamicFuncs[$i], '(?i)If(.*)Then', 3)
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)Return(.*)', 3)
                If Execute($var[0]) Then Return Execute($var1[0])            
            Case StringInStr($DynamicFuncs[$i], "If")
                $var = StringRegExp($DynamicFuncs[$i], '(?i)If(.*)Then', 3)
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)Then(.*)', 3)
                If Execute($var[0]) Then Execute($var1[0])     
            Case Not StringInStr($DynamicFuncs[$i], "If")
                Execute($DynamicFuncs[$i])
        EndSelect
    Next
    Return "Just finished logging some stuff!"
EndFunc  ;<===_DynFunc

UserDefined.au3

_FileWriteLog($file, 'AppLog("Log this")')
_FileWriteLog($file, 'AppLog("And this")')
Edited by Oldschool
Link to comment
Share on other sites

And here is return coming back to a user:

#Include <File.au3>

Global $DynamicFuncs

If Not _FileReadToArray(@ScriptDir & "\UserDefined.au3", $DynamicFuncs) Then
   MsgBox(4096,"Error", " Error reading the formula ==>>  error:" & @error)
   Exit
EndIf


MsgBox(0, "",_CatchAReturn("31"))
Func _CatchAReturn($number)
    For $i = 1 To $DynamicFuncs[0]
        Select
            Case StringInStr($DynamicFuncs[$i], "If") And StringInStr($DynamicFuncs[$i], "Return")
                $var = StringRegExp($DynamicFuncs[$i], '(?i)If(.*)Then', 3)
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)Return(.*)', 3)
                If Execute($var[0]) Then Return Execute($var1[0])           
            Case StringInStr($DynamicFuncs[$i], "If")
                $var = StringRegExp($DynamicFuncs[$i], '(?i)If(.*)Then', 3)
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)Then(.*)', 3)
                If Execute($var[0]) Then Execute($var1[0])     
            Case Not StringInStr($DynamicFuncs[$i], "If")
                Execute($DynamicFuncs[$i])
        EndSelect
    Next
EndFunc  ;<===_CatchAReturn

UserDefined.au3

If $number < 30 Then Return $number + 5
If $number > 30 Then Return $number - 5

In this case the return is "26"

Edited by Oldschool
Link to comment
Share on other sites

Thanks for the samples. I have updated my post a bit as it just reflected my need for new glasses (possibly with the brand new BBTK (bug behind the keyboard) feature..:) )

Link to comment
Share on other sites

Have you managed to execute an external loop yet??

Yes and no.

I have been able to execute a loop, just have not been able to stop it so far...

#Include <File.au3>
Global $DynamicFuncs

If Not _FileReadToArray(@ScriptDir & "\UserDefined.au3", $DynamicFuncs) Then
   MsgBox(4096,"Error", " Error reading the formula ==>>  error:" & @error)
   Exit
EndIf

MsgBox(0, "",_DynFunc2())

Func _DynFunc2()
    Local $file = @ScriptDir & "\mylog.txt"
    Local $counter
    Local $EndLoop

    For $i = 1 To $DynamicFuncs[0]
        Select
            Case StringInStr($DynamicFuncs[$i], "While")
                For $c = $i To $DynamicFuncs[0]
                    If StringInStr($DynamicFuncs[$c], "WEnd") Then 
                        $EndLoop = $c
                        ExitLoop
                    EndIf
                Next                
                $var3 = StringRegExp($DynamicFuncs[$i], '(?i)While(.*)', 3)
                While Execute($var3[0])
                    For $j = $i+1 To $EndLoop-1
                        Select
                            Case StringInStr($DynamicFuncs[$j], "If") And StringInStr($DynamicFuncs[$j], "Return")
                                $var = StringRegExp($DynamicFuncs[$j], '(?i)If(.*)Then', 3)
                                $var1 = StringRegExp($DynamicFuncs[$j], '(?i)Return(.*)', 3)
                                If Execute($var[0]) Then Return Execute($var1[0])            
                            Case StringInStr($DynamicFuncs[$j], "If")
                                $var = StringRegExp($DynamicFuncs[$j], '(?i)If(.*)Then', 3)
                                $var1 = StringRegExp($DynamicFuncs[$j], '(?i)Then(.*)', 3)
                                If Execute($var[0]) Then Execute($var1[0])     
                            Case Not StringInStr($DynamicFuncs[$j], "If")
                                Execute($DynamicFuncs[$j])
                        EndSelect
                    Next
                WEnd
            Case StringInStr($DynamicFuncs[$i], "If") And StringInStr($DynamicFuncs[$i], "Return")
                $var = StringRegExp($DynamicFuncs[$i], '(?i)If(.*)Then', 3)
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)Return(.*)', 3)
                If Execute($var[0]) Then Return Execute($var1[0])            
            Case StringInStr($DynamicFuncs[$i], "If")
                $var = StringRegExp($DynamicFuncs[$i], '(?i)If(.*)Then', 3)
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)Then(.*)', 3)
                If Execute($var[0]) Then Execute($var1[0])     
            Case Not StringInStr($DynamicFuncs[$i], "If")
                Execute($DynamicFuncs[$i])
        EndSelect
    Next
    Return "Just finished logging some stuff with a loop in the middle!"
EndFunc  ;<===_DynFunc

Be careful with that as it makes a giant file very fast...

UserDefined.au3

_FileWriteLog($file, 'Logging state before loop start')
$counter = 1
While $counter < 10
_FileWriteLog($file, "LoopCount = "&$counter)
$counter = $counter+1
WEnd
_FileWriteLog($file, 'Logging state after loops end')
Link to comment
Share on other sites

Yes and no.

I have been able to execute a loop, just have not been able to stop it so far...

This is getting really cool now :) but unfortunately I need the loops.... :) I hope you can finish it someday!!

Link to comment
Share on other sites

This is getting really cool now :) but unfortunately I need the loops.... :) I hope you can finish it someday!!

I got it working, but the loop counter has to written a bit different in the user defined section...check this:

#Include <File.au3>
Global $DynamicFuncs

If Not _FileReadToArray(@ScriptDir & "\UserDefined.au3", $DynamicFuncs) Then
   MsgBox(4096,"Error", " Error reading the formula ==>>  error:" & @error)
   Exit
EndIf

MsgBox(0, "",_DynFunc2())

Func _DynFunc2()
    Local $file = @ScriptDir & "\mylog.txt"
    Local $counter = 1
    Local $EndLoop

    For $i = 1 To $DynamicFuncs[0]
        Select
            Case StringInStr($DynamicFuncs[$i], "While")
                For $c = $i To $DynamicFuncs[0]
                    If StringInStr($DynamicFuncs[$c], "WEnd") Then 
                        $EndLoop = $c
                        ExitLoop
                    EndIf
                Next                
                $var3 = StringRegExp($DynamicFuncs[$i], '(?i)While(.*)', 3)
                ;MsgBox(0,"", $var3[0], 1)
                While Execute($var3[0])
                    For $j = $i+1 To $EndLoop-1
                        ;MsgBox(0,"", $DynamicFuncs[$j], 1)
                        Select
                            Case StringInStr($DynamicFuncs[$j], "If") And StringInStr($DynamicFuncs[$j], "Return")
                                $var = StringRegExp($DynamicFuncs[$j], '(?i)If(.*)Then', 3)
                                $var1 = StringRegExp($DynamicFuncs[$j], '(?i)Return(.*)', 3)
                                If Execute($var[0]) Then Return Execute($var1[0])            
                            Case StringInStr($DynamicFuncs[$j], "If")
                                $var = StringRegExp($DynamicFuncs[$j], '(?i)If(.*)Then', 3)
                                $var1 = StringRegExp($DynamicFuncs[$j], '(?i)Then(.*)', 3)
                                If Execute($var[0]) Then Execute($var1[0])                          
                            Case StringInStr($DynamicFuncs[$j], "$counter") And StringLen($DynamicFuncs[$j]) < 13
                                ;MsgBox(0,"", $DynamicFuncs[$j])    
                                $counter = Execute($DynamicFuncs[$j])                           
                            Case 1
                                Execute($DynamicFuncs[$j])                          
                        EndSelect
                    Next
                WEnd
            Case StringInStr($DynamicFuncs[$i], "If") And StringInStr($DynamicFuncs[$i], "Return")
                $var = StringRegExp($DynamicFuncs[$i], '(?i)If(.*)Then', 3)
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)Return(.*)', 3)
                If Execute($var[0]) Then Return Execute($var1[0])            
            Case StringInStr($DynamicFuncs[$i], "If")
                $var = StringRegExp($DynamicFuncs[$i], '(?i)If(.*)Then', 3)
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)Then(.*)', 3)
                If Execute($var[0]) Then Execute($var1[0])     
            Case Not StringInStr($DynamicFuncs[$i], "If")
                Execute($DynamicFuncs[$i])
        EndSelect
    Next
    Return "Just finished logging some stuff with a loop in the middle!"
EndFunc  ;<===_DynFunc

UserDefined.au3

_FileWriteLog($file, 'Logging state before loop start')
While $counter < 10
_FileWriteLog($file, "LoopCount = "&$counter)
$counter+1
WEnd
_FileWriteLog($file, 'Logging state after loops end')

Produces this output in the log:

2008-02-22 11:17:04 : Logging state before loop start
2008-02-22 11:17:04 : LoopCount = 1
2008-02-22 11:17:04 : LoopCount = 2
2008-02-22 11:17:04 : LoopCount = 3
2008-02-22 11:17:04 : LoopCount = 4
2008-02-22 11:17:04 : LoopCount = 5
2008-02-22 11:17:04 : LoopCount = 6
2008-02-22 11:17:04 : LoopCount = 7
2008-02-22 11:17:04 : LoopCount = 8
2008-02-22 11:17:04 : LoopCount = 9
2008-02-22 11:17:04 : LoopCount = 10
2008-02-22 11:17:04 : Logging state after loops end
Link to comment
Share on other sites

Good to see that someone found use of my example AFTER 2 years. :)

Nice work there ptrex, better late then never right.

ptrex is the godfather of dynamic func everyone.

There could be like a cool story to go along with that:

Once upon a time while struggling through the slums of AutoIt infancy, an automation madman by the name of ptrex birthed an fragile idea caller dynamic func. While growing up noone was nice to the newborn creature, and it stayed a recluse hiding in the depths of the example scripts forum. One day another madman by the name of Oldschool was introduced and befriended the reclusive beast. He decided to teach it to execute conditional statements....

Cheers dude.

Edited by Oldschool
Link to comment
Share on other sites

Here is another rather unusual example of dynamic loop execution:

#Include <File.au3>
Global $DynamicFuncs

If Not _FileReadToArray(@ScriptDir & "\UserDefined.au3", $DynamicFuncs) Then
   MsgBox(4096,"Error", " Error reading the formula ==>>  error:" & @error)
   Exit
EndIf
MsgBox(0, "",_DynFunc2())

Func _DynFunc2()
    Local $file = @ScriptDir & "\mylog.txt"
    Local $EndLoop
    
    For $i = 1 To $DynamicFuncs[0]
        Select
            Case StringInStr($DynamicFuncs[$i], "While")
                For $c = $i To $DynamicFuncs[0]
                    If StringInStr($DynamicFuncs[$c], "WEnd") Then 
                        $EndLoop = $c
                        ExitLoop
                    EndIf
                Next
                If StringInStr($DynamicFuncs[$i], "<") Then $var3 = StringRegExp($DynamicFuncs[$i], "\<(.*)", 3)
                If StringInStr($DynamicFuncs[$i], "<") Then $var5 = "< "&$var3[0]
                If StringInStr($DynamicFuncs[$i], ">") Then $var3 = StringRegExp($DynamicFuncs[$i], "\>(.*)", 3)
                If StringInStr($DynamicFuncs[$i], ">") Then $var5 = "> "&$var3[0]
                 
                While Execute($counter&$var5)
                    For $j = $i+1 To $EndLoop-1
                        Select
                            Case StringInStr($DynamicFuncs[$j], "If") And StringInStr($DynamicFuncs[$j], "Return")
                                $var = StringRegExp($DynamicFuncs[$j], '(?i)If(.*)Then', 3)
                                $var1 = StringRegExp($DynamicFuncs[$j], '(?i)Return(.*)', 3)
                                If Execute($var[0]) Then Return Execute($var1[0])            
                            Case StringInStr($DynamicFuncs[$j], "If")
                                $var = StringRegExp($DynamicFuncs[$j], '(?i)If(.*)Then', 3)
                                $var1 = StringRegExp($DynamicFuncs[$j], '(?i)Then(.*)', 3)
                                If Execute($var[0]) Then Execute($var1[0])                          
                            Case StringLeft($DynamicFuncs[$j], 1) = "$" And StringInStr($DynamicFuncs[$j], "+");And StringLen($DynamicFuncs[$j]) < 23
                                $var1 = StringRegExp($DynamicFuncs[$j], '\+(.*)', 3)
                                Assign("counter", Execute($counter+$var1[0]), 0)
                            Case StringLeft($DynamicFuncs[$j], 1) = "$" And StringInStr($DynamicFuncs[$j], "-");And StringLen($DynamicFuncs[$j]) < 23  ;And StringInStr($DynamicFuncs[$j], "=") 
                                $var1 = StringRegExp($DynamicFuncs[$j], '\-(.*)', 3)
                                Assign("counter", Execute($counter-$var1[0]), 0)                                    
                            Case Not StringInStr($DynamicFuncs[$j], "If")
                                Execute($DynamicFuncs[$j])                          
                        EndSelect
                    Next
                WEnd
            Case StringInStr($DynamicFuncs[$i], "If") And StringInStr($DynamicFuncs[$i], "Return")
                $var = StringRegExp($DynamicFuncs[$i], '(?i)If(.*)Then', 3)
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)Return(.*)', 3)
                If Execute($var[0]) Then Return Execute($var1[0])            
            Case StringInStr($DynamicFuncs[$i], "If")
                $var = StringRegExp($DynamicFuncs[$i], '(?i)If(.*)Then', 3)
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)Then(.*)', 3)
                If Execute($var[0]) Then Execute($var1[0])     
            Case StringLeft($DynamicFuncs[$i], 8) = "$counter" And StringInStr($DynamicFuncs[$i], "=") And StringLen($DynamicFuncs[$i]) < 20
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)= (.*)', 3)
                $var5 = $var1[0]
                Assign("counter", $var5, 0)
            Case StringLeft($DynamicFuncs[$i], 5) = "$file" And StringInStr($DynamicFuncs[$i], "=") ;And StringLen($DynamicFuncs[$i]) < 23
                $var1 = StringRegExp($DynamicFuncs[$i], '(?i)=(.*)', 3)
                $var5 = $var1[0]
                Assign("file", $var5, 0)
                ;MsgBox(0, "File", $file)               
            Case Not StringInStr($DynamicFuncs[$i], "If")
                Execute($DynamicFuncs[$i])      
        EndSelect
    Next
    Return "Just finished logging some stuff with a loop in the middle!"
EndFunc  ;<===_DynFuncoÝ÷ ÙK¬7wjíÜ¡×W®+^.8ÓMú~)^ßÒè§ËZµæÞ~Þ)²Ö«·x×Múr§µê

So when you try to execute, you will get an undeclared variable error, unless you are compiled. But if you select "continue anyway" during the error, you will get the desired result anyways.

No what is killing me here, is for some reason not declaring the $file variable does not work in the same manner...

When trying to execute with $file undeclared, and UserDefined.au3 looking like this:

$file = @ScriptDir & "\mylog.txt"
_FileWriteLog($file, 'Logging state before loop start')
$counter = 1
While $counter < 10
_FileWriteLog($file, "LoopCount = "&$counter)
$counter = $counter+1
WEnd
_FileWriteLog($file, 'Logging state after loops end')

no log file gets created....

Link to comment
Share on other sites

  • 10 months later...

There could be like a cool story to go along with that:

Once upon a time while struggling through the slums of AutoIt infancy, an automation madman by the name of ptrex birthed an fragile idea caller dynamic func. While growing up noone was nice to the newborn creature, and it stayed a recluse hiding in the depths of the example scripts forum. One day another madman by the name of Oldschool was introduced and befriended the reclusive beast. He decided to teach it to execute conditional statements....

Cheers dude.

LMFAO I Just though that was funny as hell. True but funny.

Edited by GoogleDude
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...