Opened 11 years ago
Closed 6 years ago
#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 , 11 years ago
| Version: | 3.3.13.19 |
|---|
comment:2 by , 11 years ago
Use this:
($oPerson.Print)($oPerson) ; version 1
Note that Au3Check chokes on this.
comment:3 by , 11 years ago
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 , 11 years ago
| 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 , 11 years ago
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 , 11 years ago
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 , 11 years ago
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 , 11 years ago
| Resolution: | Fixed |
|---|---|
| Status: | closed → reopened |
comment:9 by , 6 years ago
| 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.