v1 -> v2 Script Converter

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

v1 -> v2 Script Converter

30 Nov 2016, 12:19

AHK v2 Script Converter

This is a work in progress and nowhere near complete.

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 alpha build.
I've also added essential unit tests using the Yunit framework to encourage contributions from others.

However, this project is way more ambitious that I originally thought, and it needs a lot of work.

See here for many of the changes that need to be handled: https://autohotkey.com/v2/v2-changes.htm


Image



Usage

1. Download the full repo. Then run the included v2converter.exe file (or run v2converter.ahk with AHK v2)
2. Choose your input scriptfile.ahk written for AHK v1. The converted script will be named scriptfile_v2new.ahk in the same directory
3. Look over the Visual Diff to manually inspect the changes


Latest Download:
https://github.com/mmikeww/AHK-v2-scrip ... master.zip

Project page:
https://github.com/mmikeww/AHK-v2-script-converter

------------
Last edited by guest3456 on 16 Jan 2017, 23:22, edited 6 times in total.

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

Re: v1 -> v2 Script Converter

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
Google: floowsnaake
GitHub: floowsnaake
Contact:

Re: v1 -> v2 Script Converter

30 Nov 2016, 15:03

why should i use AHK2?
:yawn:
Helgef
Posts: 3570
Joined: 17 Jul 2016, 01:02
Contact:

Re: v1 -> v2 Script Converter

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: 2496
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

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: 2496
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

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: 2496
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

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.

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

Re: v1 -> v2 Script Converter

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: 2496
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

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: 3570
Joined: 17 Jul 2016, 01:02
Contact:

Re: v1 -> v2 Script Converter

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: 2496
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

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: 2496
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

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: 2496
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

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: 2496
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

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: 6875
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: v1 -> v2 Script Converter

28 Jun 2018, 21:55

Wow, I forgot about this.... Cool! :D
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 3200 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 49 guests