v1 -> v2 Script Converter

Post your working scripts, libraries and tools.
guest3456
Posts: 3477
Joined: 09 Oct 2013, 10:31

v1 -> v2 Script Converter

Post by guest3456 » 30 Nov 2016, 12:19

AHK v2 Script Converter

This is a work in progress. But it should be good enough to save you a lot of time with some of the more tedious conversions.

This script will attempt to convert a script written in AHK v1 to the correct syntax so that it works in AHK v2.
It is useful to quickly convert some of the bigger syntax changes. Afterwards you can investigate the converted version for other minor changes that the converter didn't cover.

I took Frankie's original converter, and updated it to work with the latest AHK v2 beta build.
I've also added essential unit tests using the Yunit framework to encourage contributions from others.


Image



Latest Download:
https://github.com/mmikeww/AHK-v2-script-converter/archive/master.zip

Usage instructions on the project page:
https://github.com/mmikeww/AHK-v2-script-converter




------------
Last edited by guest3456 on 04 Apr 2024, 11:24, edited 11 times in total.


vasili111
Posts: 747
Joined: 21 Jan 2014, 02:04
Location: Georgia

Re: v1 -> v2 Script Converter

Post by vasili111 » 30 Nov 2016, 14:54

Really very necessary project :thumbup:
There is already lots of useful code for AutoHotkey v1 and without this project, it will be hard to easy migrate from v1 to v2. This project will greatly help the process.
DRAKON-AutoHotkey: Visual programming for AutoHotkey.

User avatar
SnowFlake
Posts: 368
Joined: 28 Apr 2015, 05:41
Contact:

Re: v1 -> v2 Script Converter

Post by SnowFlake » 30 Nov 2016, 15:03

why should i use AHK2?
:yawn:

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: v1 -> v2 Script Converter

Post by Helgef » 30 Nov 2016, 16:39

Excellent! I just tried this on a ~1200 lines script, and it did a lot of changes I wouldn't want to do manually. So it is already useful. But I see there is a lot of work to be done still.
The visual diff is a really nice feature!

guest3456
Posts: 3477
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

Post by guest3456 » 30 Nov 2016, 23:26

SnowFlake wrote:why should i use AHK2?
well, here's a couple
1. you can call all commands as functions. thats good enough for me
2. you can %deref% variables (and expresions!) INSIDE quoted strings: (not anymore :( )

Code: Select all

;v1
WinGetTitle, Title, A
MsgBox, The active window is %Title%.
MsgBox, % "1+1=" 1+1

;v2
Title := WinGetTitle("A")
MsgBox("The active window is %Title%.")
MsgBox("1+1=%1+1%")
i wonder if the converter should change all command syntax to function syntax like above
Last edited by guest3456 on 08 Jan 2018, 20:24, edited 4 times in total.


guest3456
Posts: 3477
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

Post by guest3456 » 30 Nov 2016, 23:49

update:

Code: Select all

var2 = 2       ;v1

var2 := "2"    ;v2 converted
lexikos recommends var=value should always assign a string, even if value is numeric


guest3456
Posts: 3477
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

Post by guest3456 » 01 Dec 2016, 08:57

Helgef wrote:Excellent! I just tried this on a ~1200 lines script, and it did a lot of changes I wouldn't want to do manually. So it is already useful. But I see there is a lot of work to be done still.
The visual diff is a really nice feature!
please post the results of any failed or incorrect conversions, either here in this thread or on github:

https://github.com/mmikeww/AHK-v2-scrip ... ter/issues
Last edited by guest3456 on 01 Dec 2016, 09:20, edited 2 times in total.


guest3456
Posts: 3477
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

Post by guest3456 » 01 Dec 2016, 09:00



Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: v1 -> v2 Script Converter

Post by Helgef » 01 Dec 2016, 11:04

guest3456 wrote: please post the results of any failed or incorrect conversions, either here in this thread or on github:
I didn't experience any incorrect convertions, just missed one, from my short-term memory, things that I had to fix manually after the conversion:
  • SetBatchLines, removed
  • StringReplace, ... changed to StrReplace,...
  • IfMsgBox Yes/... See comment
There were more but I don't remember at this point, sorry.

Comment on IfMsgBox
I just removed them for now, I'm not sure if it has been decided what will happen to that. There was a thread about it recently, I'm sure you saw it.

guest3456
Posts: 3477
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

Post by guest3456 » 01 Dec 2016, 11:08

Helgef wrote: I didn't experience any incorrect convertions, just missed one, from my short-term memory, things that I had to fix manually after the conversion:
  • SetBatchLines, removed
  • StringReplace, ... changed to StrReplace,...
  • IfMsgBox Yes/... See comment
There were more but I don't remember at this point, sorry.
yep, there are many more that still need to be done
Helgef wrote: Comment on IfMsgBox
I just removed them for now, I'm not sure if it has been decided what will happen to that. There was a thread about it recently, I'm sure you saw it.
i didn't see the thread you're talking about. but this was changed to A_MsgBoxResult as mentioned in v2-changes


Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: v1 -> v2 Script Converter

Post by Helgef » 01 Dec 2016, 11:19

guest3456 wrote:i didn't see the thread you're talking about
I was referring to this thread

guest3456
Posts: 3477
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

Post by guest3456 » 01 Dec 2016, 11:27

Helgef wrote:
guest3456 wrote:i didn't see the thread you're talking about
I was referring to this thread
ah yes i did see that. so its best for the converter not to make a decision yet


guest3456
Posts: 3477
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

Post by guest3456 » 03 Dec 2016, 09:42

updates
- fix, return %var% now does double deref in v2
- use A_StringCaseSense for InStr replacements instead of outputting warning comment
- if var is 'type'
- StrReplace


guest3456
Posts: 3477
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

Post by guest3456 » 11 Dec 2016, 18:51

updates to handle parameters that "can be an expression"

Code: Select all

; all of these

StringLeft, OutputVar, String, %count%
StringLeft, OutputVar, String, % count
StringLeft, OutputVar, String, count

; should convert to this

OutputVar := SubStr(String, 1, count)

Code: Select all

; these

Sleep, %count%
Sleep, count
Sleep, count*2

; should convert to these

Sleep, %count%
Sleep, %count%
Sleep, %count*2%


guest3456
Posts: 3477
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

Post by guest3456 » 20 Dec 2016, 12:55

updates:

- convert all IfXXX commands
- convert File*Dir commands
- convert if between
- convert renamed vars and funcs
- detect empty params


User avatar
joedf
Posts: 9097
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: v1 -> v2 Script Converter

Post by joedf » 28 Jun 2018, 21:55

Wow, I forgot about this.... Cool! :D
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

ahklearner
Posts: 316
Joined: 23 Jan 2015, 01:49

Re: v1 -> v2 Script Converter

Post by ahklearner » 31 Jul 2019, 14:46

just replied to get subscribed to the post :)

User avatar
DuyMinh
Posts: 40
Joined: 05 May 2017, 08:34

Re: v1 -> v2 Script Converter

Post by DuyMinh » 31 Jul 2019, 19:12

Does anyone know editor support v2 syntax? Thank you!

ahklearner
Posts: 316
Joined: 23 Jan 2015, 01:49

Re: v1 -> v2 Script Converter

Post by ahklearner » 01 Aug 2019, 11:14

I am greatly an AHK dependent, and I am from a non-programming background, more than writing code I do analyze codes written by others and learn from them doing small changes.

Till date, all of our codes are written in v1, if I need to test, learn, and analyze these scripts >>> I cant change codes manually all the time :( if something can be automated, we should, it would be a great help, please think of all the guys like me and future learners like me for whom AHK is or might be a breadwinner.

AHK_user
Posts: 523
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: v1 -> v2 Script Converter

Post by AHK_user » 27 Jul 2021, 16:53

Is somebody planning of updating this convertor to the new AHK V2 Beta?

I tried it out on a script, it did some conversion wel, but failed in a lot of lines. (msgbox, iniRead, loop read, iniwrite,inputbox,...)
This is of course normal because the AHK V2 Beta is just released and this convetor is 4 years old.

Post Reply

Return to “Scripts and Functions (v2)”