#2980 closed Feature Request (Works For Me)
Can't call a function in a map with the point operator [BETA]
| Reported by: | anonymous | Owned by: | |
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | Severity: | None | |
| Keywords: | Beta Version | Cc: |
Description
I love the point operator in maps. But this don't work with functions. The first version generates an error:
"The requested action with this object has failed."
$oPerson = Person("John Smith", 30)
$oPerson.Print($oPerson) ; version 1
$oPerson["Print"]($oPerson) ; version 2
$func = $oPerson.Print ; version 3
$func($oPerson)
Func Person($sName, $iAge)
Local $oObj[]
$oObj.Name = $sName
$oObj.Age = $iAge
$oObj.Print = Person_Print
Return $oObj
EndFunc
Func Person_Print($oThis)
ConsoleWrite($oThis.Name & ": " & $oThis.Age & @LF)
EndFunc
Can you fix it?
Attachments (0)
Change History (9)
comment:1 by , on Feb 1, 2015 at 1:00:02 PM
| Version: | 3.3.13.19 |
|---|
comment:2 by , on Feb 1, 2015 at 11:07:56 PM
Use this:
($oPerson.Print)($oPerson) ; version 1
Note that Au3Check chokes on this.
comment:3 by , on Feb 2, 2015 at 9:48:55 PM
Thx jchd18. It's a good idea. With the following code, can I deactivate Au3Check:
#AutoIt3Wrapper_Run_AU3Check=N
follow-up: 5 comment:4 by , on Feb 3, 2015 at 12:51:29 PM
| Resolution: | → Fixed |
|---|---|
| Status: | new → closed |
Exactly.
It would be very hard to make the version 1 construct work. Look at this:
$X.Y($p)
How could the interpreter understand that otherwise that first try to evaluate
Y($p)
as a function then
$X.(Y($p))
Take into consideration that a non-member function Y could exist. AutoIt is only an interpreter, there is no actual compilation.
comment:5 by , on Feb 4, 2015 at 6:06:57 PM
Replying to jchd18:
How could the interpreter understand that otherwise that first try to evaluate
Y($p)as a function then
$X.(Y($p))
Because the grammar doesn't allow that. It works for COM objects, doesn't it?
follow-up: 7 comment:6 by , on Feb 5, 2015 at 10:21:37 PM
My "wrong grammar" was just an illustration of what could happen.
Also don't compare AutoIt Maps and COM objects. Objects do have declared methods while Maps are simpler structures having only passive member variables. One other good illustration of the difference is that you had to pass "this" explicitely as a parameter to the pseudo-member function (indeed: a member variable which happens to hold a function pointer).
comment:7 by , on Feb 7, 2015 at 12:14:18 AM
Replying to jchd18:
My "wrong grammar" was just an illustration of what could happen.
The interpreter already supports the syntax for COM objects and maps (it doesn't try to execute Y($p) first), but it doesn't support it's execution for the special case of maps:
Local $oHTTP = ObjCreate ("winhttp.winhttprequest.5.1")
$oHTTP.Open ("GET", "http://www.AutoItScript.com")
; OK
$oHTTP.bogus ()
; Error: The requested action with this object has failed.
Local $map []
$map.f = f
$map.f ()
; Error: The requested action with this object has failed.
Please undo the status change.
Also don't compare AutoIt Maps and COM objects. Objects do have declared methods while Maps are simpler structures having only passive member variables. [...]
Please don't misunderstand, I didn't create this ticket and it wasn't my intension to use maps as objects.
comment:8 by , on Feb 7, 2015 at 12:49:48 PM
| Resolution: | Fixed |
|---|---|
| Status: | closed → reopened |
comment:9 by , on Aug 10, 2020 at 10:26:13 AM
| Resolution: | → Works For Me |
|---|---|
| Status: | reopened → closed |
Hi,
I recheck with the latest beta and I get the following results so I assume it is OK
>Running:(3.3.15.3):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe John Smith: 30 John Smith: 30 John Smith: 30 +>11:23:43 AutoIt3.exe ended.rc:0

Automatic ticket cleanup.