Jump to content

Creating a simple script-engine with autoit.


Recommended Posts

Hello readers of this post  :)

I'm planning to make a sort of script engine via autoit.

It will read text files as 'scripts' with my self made scripting language.

(but i'm going to make my own extension for the 'scripts')

i'm thinking about " nameOfFile.GeekScript " or something...

how it works:

files with the extension ".geekscript" will be opened with my "script-engine.exe" made in autoit.

-script-engine.exe reads the script and breaks it apart in sentences by @CRLF.

-every sentence will be spitted up to 'words' (or commands) that will be recognized by my script-engine.

-the engine recognizes if you want to make a variable when it reads a word followed by '=' and after that a string or number (or calculations).

and here i'm stuck, if the script engine reads this for example:

-----------------------------------------------------------------------------

ABC = 456

DEF = "this is a test" & ABC + 123

-----------------------------------------------------------------------------

for the variable "DEF", it must calculate the result for that variable and store that in a dictionary object or something.
i tough of using autoit's "execute" or "eval" function to see what the output would be but unfortunately if by coincidence the
variable exists in the 'script-engine source code' eval or execute will use that variable...
 

this is what i mean:

-----------------------------------------------------------------------------

Func = 456

-----------------------------------------------------------------------------

if i use eval or execute for this string: eval("func = 456") then it would give an error or it won't work.

same for variables that exist in the 'script-engine autoit code'...

does anybody know if there is a way for calculating strings like eval does, but don't use the variables made in the autoit script?

 

Link to post
Share on other sites

Requires you to have the 'Func' declared, unfortunatly:

Local $Func
$string = "Func = 456"
$aString = StringRegExp($string,"(.*)\s=\s(.*)",3)
$VarName = $aString[0]
$VarValue = $aString[1]
Assign($VarName,$VarValue)
ConsoleWrite("VariableName=[" & $VarName & "], Value=[" & Eval($VarName) & "] or, using your 'variable'=[" & $Func & "]" & @CRLF )

output: VariableName=[Func], Value=[456] or, using your 'variable'=[456]

edit: no need to move the array into $VarName...helpfile states the first param of assign can't be an array, but am able to do so...must mean it can't be an empty array element?:

Local $Func
$string = "Func = 456"
$aString = StringRegExp($string,"(.*)\s=\s(.*)",3)
Assign($aString[0],$aString[1])
ConsoleWrite("using your 'variable'=[" & $Func & "]" & @CRLF )

output: using your 'variable'=[456]

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to post
Share on other sites

Requires you to have the 'Func' declared, unfortunatly:

Local $Func
$string = "Func = 456"
$aString = StringRegExp($string,"(.*)\s=\s(.*)",3)
$VarName = $aString[0]
$VarValue = $aString[1]
Assign($VarName,$VarValue)
ConsoleWrite("VariableName=[" & $VarName & "], Value=[" & Eval($VarName) & "] or, using your 'variable'=[" & $Func & "]" & @CRLF )

output: VariableName=[Func], Value=[456] or, using your 'variable'=[456]

edit: no need to move the array into $VarName...helpfile states the first param of assign can't be an array, but am able to do so...must mean it can't be an empty array element?:

Local $Func
$string = "Func = 456"
$aString = StringRegExp($string,"(.*)\s=\s(.*)",3)
Assign($aString[0],$aString[1])
ConsoleWrite("using your 'variable'=[" & $Func & "]" & @CRLF )

output: using your 'variable'=[456]

 

thank you for the reply!

i see you are using stringregexp, can you explain me what you are doing with that?

also, wouldn't it be more useful to store the name in a dictionary object or has stringregexp something to do with that?

to "calculate" the string i was thinking about first replacing all the possible declared variables in my "geek script" with there outputs

but the problem then is that a variable can be declared in a very complicated way:

myVar = 1 + -5 * 8 / 7 - 5 & "test" + -1 - -10 & "help!!!"

Link to post
Share on other sites

I am trying to do something very similar in one of my scripts,

I like how jdelaney went about it but for what I am doing I cannot declare the variables before.

I came up with this real quick and it works for what you are trying to do,

there are a couple ways you could improve it because right now it will confuse similar variable names ex. ABC and ABCD

I can think of a couple ways of fixing this but i think you can figure it out ;)

#include <Array.au3>

Dim $TestScript = 'ABC = 456' & @CRLF & _
                  'DEF = "this is a test" & ABC + 123' & @CRLF & _
                  'myVar =  1 + -5 * 8 / 7 - 5  & "test" &  -1 - -10  & "help!!!"' & @CRLF & _
                  'Func = 456' & @CRLF

ProcessScript($TestScript)

Func ProcessScript($hScript)
    Local $hSplit = StringSplit($hScript, @CRLF, 1)
    Local $Variables[1] = [0], $Data[1] = [0]
    For $i = 1 to $hSplit[0] Step 1
        Local $aString
        $aString = StringRegExp($hSplit[$i],"(.*)\s=\s(.*)",3)
        If IsArray($aString) Then
            _ArrayAdd($Variables, $aString[0])
            _ArrayAdd($Data, $aString[1])
            $Variables[0] += 1
            $Data[0] += 1
        EndIf
    Next
    For $i = 1 to $Variables[0] Step 1
        ConsoleWrite("+ Variable["&$i&"] = "&$Variables[$i]&@CRLF)
        ConsoleWrite("> Data["&$i&"]     = "&$Data[$i]&@CRLF)
    Next
    For $i = 1 to $Data[0] Step 1
        Local $ProcessData = $Data[$i]
        For $c = 1 to $Variables[0] Step 1
            If StringinStr($Data[$i], $Variables[$c]) Then
                $ProcessData = StringReplace($Data[$i], $Variables[$c], $Data[$c])
            EndIf
        Next
        ConsoleWrite("- Processed Data["&$i&"]     = "&Execute($ProcessData)&@CRLF)
    Next
EndFunc
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By asiawatcher
      hi below i got one script i made which runs audacity starts a recording and ends it at specific times
       
      when i run the script even if it isn't the time to start audacity and sits idle on taskbar the pc fan gets very loud, when i close the script it comes back to normal 
       
      why this happens ? anything wrong with my code ?? cheers
      #include <INet.au3> #include <Array.au3> #include <WinAPIFiles.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <string.au3> #include <FTPEx.au3> #include <ClipBoard.au3> #include <date.au3> #include <ProgressConstants.au3> #include <IE.au3> #Include <Constants.au3> #Include <INET.au3> #include <SendMessage.au3> #include <File.au3> #include <String.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Misc.au3> #include <FileConstants.au3> #include <WinAPI.au3> while 1 if @HOUR = '11' And @MIN = '00' Then  Run("C:\Program Files (x86)\Audacity\audacity.exe", "", @SW_MAXIMIZE) SLEEP(2000) if ProcessExists("audacity.exe") Then winactivate("Audacity") EndIf      Send("r") ;;KREVATI Sleep(1000 * 60) endif if @HOUR = '23' And @MIN = '00' Then  if ProcessExists("audacity.exe") Then winactivate("Audacity") EndIf Send("s") Sleep(1000 * 60) EndIf wend  
    • By nacerbaaziz
      goodmorning; autoit team
      please their are any youtube search way working?
      because i was using the get source and split it to get the result but know it does not working any way.
      is the youtube disabled that? and is their any other simple way to do that?
      i tested all examples found in this post but also it don't work
      https://www.autoitscript.com/forum/topic/123945-youtube-search/
      and here is the example that i use to and it don't work any more
      local $hSearchOpenHNDL, $hSearchConnect, $sSearchGet local $a_UrlsArray[1][5] local $b_ButtonsDisabled = false, $b_SearchBTNFocus = false, $b_SearchListFocus, $h_SearchFocusHND local $Return = "0" local $s_OpenStringY = "/feed/trending" local $ChannelUrl = "", $channelName = "" if Not ($a_YoutubeSearchArray[0][0] = 0) then GUICtrlSetData($searchInp, $s_youtubeSearchLastSearch) $s_OpenStringY = "/results?search_query=" & StringReplace(GUICtrlRead($searchInp), " ", "+") $a_UrlsArray = $a_YoutubeSearchArray for $i = 1 to $a_UrlsArray[0][0] _GUICtrlListBox_AddString($SearchList, $a_UrlsArray[$i][0] & $a_UrlsArray[$i][2] & $a_UrlsArray[$i][3]) next _GUICtrlListBox_SetCurSel($SearchList, $I_youtubeSearchLastIndex-1) GUICtrlSetState($SearchList, $GUI_focus) else if Ping("youtube.com", 1000) > 1 then $hSearchOpenHNDL = _WinHttpOpen('') if not (@Error) then $hSearchConnect = _WinHttpConnect($hSearchOpenHNDL, "youtube.com") if Not (@Error) then $sSearchGet = _WinHttpSimpleRequest($hSearchConnect, "get", $s_OpenStringY) if not (@Error) then local $a_strings = _StringBetween($sSearchGet, '<a href="/watch', "<ul") local $title = "" local $url = "" local $length = "" local $result = "" GUICtrlSetData($SearchList, "") ReDim $a_UrlsArray[1][5] for $i = 0 to UBound($a_strings)-1 $url = _StringBetween($a_strings[$i], "?", '"') if @error then ContinueLoop $url = "https://www.youtube.com/watch?" & $url[0] $title = _StringBetween($a_strings[$i], 'dir="', '</a>') if @error then ContinueLoop $title = $title[0] $title = StringRegExpReplace($title, '(.*\"\>)', "") if StringRegExp($a_strings[$i], '[0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}', 0) = 1 then $length = StringRegExp($a_strings[$i], '[0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}', 2) elseIf StringRegExp($a_strings[$i], '[0-9]{1,2}\:[0-9]{1,2}', 0) = 1 then $length = StringRegExp($a_strings[$i], '[0-9]{1,2}\:[0-9]{1,2}', 2) else $length = "" endIf if IsArray($length) then $length = ": (" & $length[0] & ")" else $length = "" endIf $ChannelUrl = stringRegexpReplace($a_strings[$i], '(^.*?<a.*?\"(\/user|\/channel))+', "$2") $channelName = stringRegexpReplace($ChannelUrl, '(.*?\".*?>)(.*</a>)+', "$2") $ChannelUrl = stringRegexpReplace($ChannelUrl, '(\".*)+', "") $channelName = stringRegexpReplace($channelName, '(</a>.*)+', "") $result &= $title & @crlf & $url & @crlf ReDim $a_UrlsArray[UBound($a_UrlsArray)+1][5] $a_UrlsArray[UBound($a_UrlsArray)-1][0] = $title $a_UrlsArray[UBound($a_UrlsArray)-1][1] = $url $a_UrlsArray[UBound($a_UrlsArray)-1][2] = $length if not ($channelName = "") then $a_UrlsArray[UBound($a_UrlsArray)-1][3] = ", (" & $channelName & ")" if not ($channelUrl = "") then $a_UrlsArray[UBound($a_UrlsArray)-1][4] = "https://www.youtube.com" & $channelUrl $a_UrlsArray[0][0] = UBound($a_UrlsArray)-1 _GUICtrlListBox_AddString($SearchList, $a_UrlsArray[UBound($a_UrlsArray)-1][0] & $length & $a_UrlsArray[UBound($a_UrlsArray)-1][3]) next endIf endIf endIf endIf endIf  
      i hope any one can help me
      thanks in advance
    • By v120
      Original posted by CoePSX
       
       
       
       
      Drawing_Script.au3
    • By TheAutomator
      I'm writing a recursive decent parser in Autoit!
      The programming language i'm making is called HighLevel.
      I'm doing this for learning purposes, because it's fun and because I can implement it into my other project:
      Fullscreen Console With custom programming language!
       
      It's not easy...

      In Autoit you don't have objects like in Java or Visual Basic, so I had to figure out a way to still convert the code to an abstract syntax tree.
      I used nested array's and array based dictionary's instead of objects.
      The code is still very dirty and I need to make a lot of modifications but if you're careful with testing you'll see what it can do already.
       
      Console window
      Because this code eventually will get implemented into my console project I crafted a nice little console window (with a custom sci-fi looking theme, yeah i was a little bored haha).
      {ESC} is your panic button for now, it terminates the script completely.
      If you get an error while opening a script the text will turn red.
      To minimize it press the blue button, to close it use the red one, to drag the gui just grab it on one of the sides.
      The console window will display what you write to it with your "HighLevel-script" and some additional information:

       
      How to test it:
      Download: HighLevel.Au3, Debug.Au3 (includes a function to display nested arrays for debugging), GUI.bmp (for the console)
      Compile the Autoit code to EXE.
      The GUI.bmp must be in the same folder as the EXE file!
      Write a HighLevel-script (text file) and drag it into the compiled autoit-exe.
      The custom made little console window will pop up in the left top corner of your screen and your HighLevel-script (the text file) will be interpreted and executed.
       
      The Language:
      exit script:     Abort      show / hide the console:     Show     Hide      write to/clear the console:     Write 'this is a ''string''!'     Clear variables: test_var_1 = 123 some_list = ['a', 5, true] some_list[1] = 3 math = 1 + 2 * 3 / 4 - -5 & test_var beep (under construction):     Beep F, optD wait X seconds:     Wait X      Messages:     Message 'Hello World!'      move/click the mouse:     Move X, Y     Click      send keys (under construction):     Send 'HighLevel', True      if's:     If false     ElseIf true         # this part will run     Else     End subs:     Sub X         # do stuff     End     Call X      for loops:     For X = 1 to 10         # X iterates     End Values:     Input 'Give me input'     Random     YesNo 'yes or no' operators:     + - * / & > = ! < ( ) And Not Or  
      Example script:
      # my first HighLevel script message 'Hello World!' message 'Lets write to the console...' clear # clear the console... list = ['a', 16, true] for i = 0 to 2     write list[i]     wait 1 end sub test     if YesNo 'would you like to quit?'         message 'Goodbye!'         abort     else         write 1 + 2 * 3 & ' math!'     end end call test  
      test script.HighLevel
      GUI.bmp
      Debug.au3
      HighLevel.au3
    • By ademon
      Hi. I can open the editor with out problems but I can not compile because it is placed on another partition diferent from C.
      Can you provide an update of this bug?


×
×
  • Create New...