[Idea:] Introduce 'Exec' class for dynamic calling which is safe unlike 'eval' function

Discuss the future of the AutoHotkey language
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

[Idea:] Introduce 'Exec' class for dynamic calling which is safe unlike 'eval' function

12 Jul 2023, 12:29

@Lexicos
Wish to introduce Exec(obj).eval() which is safe, unlike eval() function in AHK H.
I suddenly came up with an idea regarding dynamic calling which looks perfect.
Currently, in AHK H, local variables can be changed outside their func with this feature. For example:

Code: Select all

f(txt){
	a:=1
	,eval(txt)
	,MsgBox(a)
}
f('a+=2')
It's really not safe to do anything like that using the eval() function.
Maybe the limited dynamic features like obj.%prt% at present is almost sufficient, but still leaves some blanks in interacting with users in some situations, such as through inputting strings. The below class Exec(obj) with only one obj parameter would perhaps be a perfect addition to it and be a safe way at the same time:

Code: Select all

obj1:={prpt1:1}
,Exec(obj1).eval('this.prpt1:=5')
Note: Any variables must not be supported except this in the string form code, which is the only parameter of the eval(str) method. You will probably find that all the outer variable names in the executing string will get unified, because all of them named 'this'. It's just almost equivalent to a callback object except that it's in string format.

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 13 guests