Hi
@Chunjee
I've been working on a version of
expect for AHKv2. In doing so I realised that I've made a number of naming and formatting changes. I've also added a public method to access most of AHKv2
Is functions, including
InStr (code copied below for your info, comment, use, etc).
Code: Select all
AHKIsFuncs(pAHKFunc, pParam2, psParam3:="", pNote:="")
{
if (pAHKFunc = "InStr")
{ ;Returns true if the needle(pParam2) is in the haystack(pAHKFunc), else false.
this.TestType := "InStr"
iPos := %pAHKFunc%(pParam2, psParam3)
if (iPos > 0)
return this._test(1, true, pNote)
else
return this._test(0, true, pNote)
}
if (pAHKFunc = "IsInteger")
{ ;Returns true if (pParam2) is an integer, else false.
this.TestType := "IsInteger"
if IsInteger(pParam2)
return this._test(1, true, pNote)
else
return this._test(0, true, pNote)
}
if (pAHKFunc = "IsFloat")
{ ;Returns true if (pParam2) is a real number, else false.
this.TestType := "IsFloat"
if IsFloat(pParam2)
return this._test(1, true, pNote)
else
return this._test(0, true, pNote)
}
if (pAHKFunc = "IsNumber")
{ ;Returns true if (pParam2) is an integer or a real number, else false.
this.TestType := "IsNumber"
if IsNumber(pParam2)
return this._test(1, true, pNote)
else
return this._test(0, true, pNote)
}
if (pAHKFunc = "IsObject")
{ ;Returns true if (pParam2) is an object, else false.
this.TestType := "IsObject"
if IsObject(pParam2)
return this._test(1, true, pNote)
else
return this._test(0, true, pNote)
}
if (pAHKFunc = "IsSet")
{ ;Returns true if (pParam2) has been assigned a value, else false.
;**Im not sure this works...by passing an unset var it seems to become 'set'?**
this.TestType := "IsSet"
;Next line used to test IsSet.
; pParam2 := unset
if IsSet(pParam2)
return this._test(1, true, pNote)
else
return this._test(0, true, pNote)
}
if (pAHKFunc = "IsDigit")
{
/* Returns true if (pParam2) is:
- a positive integer,
- an empty string,
- or a string which contains only the characters 0 through 9.
Other characters such as the following are not allowed: spaces, tabs, plus signs,
minus signs, decimal points, hexadecimal digits, and the 0x prefix.
*/
this.TestType := "IsDigit"
if IsDigit(pParam2)
return this._test(1, true, pNote)
else
return this._test(0, true, pNote)
}
if (pAHKFunc = "IsAlpha")
{
/* Returns true if (pParam2) is a string and:
- is empty or
- contains only alphabetic characters.
False if there are any digits, spaces, tabs, punctuation, or other non-alphabetic
characters anywhere in the string. For example, if pParam2 contains a space followed
by a letter, it is not considered to be alpha.
*/
this.TestType := "IsAlpha"
if IsAlpha(pParam2)
return this._test(1, true, pNote)
else
return this._test(0, true, pNote)
}
if (pAHKFunc = "IsSpace")
{
/* Returns true if (pParam2) is a string and:
- is empty or
- contains only whitespace consisting of the following characters:
space (A_Space or `s), tab (A_Tab or `t), linefeed (`n), return (`r), vertical tab (`v), and formfeed (`f).
*/
this.TestType := "IsSpace"
if IsSpace(pParam2)
return this._test(1, true, pNote)
else
return this._test(0, true, pNote)
}
return
}
Ultimately the 'new' expect is now not so similar looking (but is functionally very close) to your script for AHKv1.
I'd like to post it somewhere but don't want to hijack this thread. Or I could start a new thread in the v2 section of the forum and fully reference this thread? Very happy to be guided by what you would like me to do.
Cheers,