Page 1 of 8
v1 -> v2 Script Converter
Posted: 30 Nov 2016, 12:19
by guest3456
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.
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
------------
Re: v1 -> v2 Script Converter
Posted: 30 Nov 2016, 14:54
by vasili111
Really very necessary project
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.
Re: v1 -> v2 Script Converter
Posted: 30 Nov 2016, 15:03
by SnowFlake
why should i use AHK2?
Re: v1 -> v2 Script Converter
Posted: 30 Nov 2016, 16:39
by Helgef
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!
Re: v1 -> v2 Script Converter
Posted: 30 Nov 2016, 23:26
by guest3456
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
Re: v1 -> v2 Script Converter
Posted: 30 Nov 2016, 23:49
by guest3456
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
Re: v1 -> v2 Script Converter
Posted: 01 Dec 2016, 08:57
by guest3456
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
Re: v1 -> v2 Script Converter
Posted: 01 Dec 2016, 09:00
by guest3456
Re: v1 -> v2 Script Converter
Posted: 01 Dec 2016, 11:04
by Helgef
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.
Re: v1 -> v2 Script Converter
Posted: 01 Dec 2016, 11:08
by guest3456
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
Re: v1 -> v2 Script Converter
Posted: 01 Dec 2016, 11:19
by Helgef
guest3456 wrote:i didn't see the thread you're talking about
I was referring to
this thread
Re: v1 -> v2 Script Converter
Posted: 01 Dec 2016, 11:27
by guest3456
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
Re: v1 -> v2 Script Converter
Posted: 03 Dec 2016, 09:42
by guest3456
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
Re: v1 -> v2 Script Converter
Posted: 11 Dec 2016, 18:51
by guest3456
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%
Re: v1 -> v2 Script Converter
Posted: 20 Dec 2016, 12:55
by guest3456
updates:
- convert all IfXXX commands
- convert File*Dir commands
- convert if between
- convert renamed vars and funcs
- detect empty params
Re: v1 -> v2 Script Converter
Posted: 28 Jun 2018, 21:55
by joedf
Wow, I forgot about this.... Cool!
Re: v1 -> v2 Script Converter
Posted: 31 Jul 2019, 14:46
by ahklearner
just replied to get subscribed to the post
Re: v1 -> v2 Script Converter
Posted: 31 Jul 2019, 19:12
by DuyMinh
Does anyone know editor support v2 syntax? Thank you!
Re: v1 -> v2 Script Converter
Posted: 01 Aug 2019, 11:14
by ahklearner
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.
Re: v1 -> v2 Script Converter
Posted: 27 Jul 2021, 16:53
by AHK_user
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.