Modify

Opened 5 years ago

Last modified 5 years ago

#2980 reopened Feature Request

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 (8)

comment:1 Changed 5 years ago by TicketCleanup

  • Version 3.3.13.19 deleted

Automatic ticket cleanup.

comment:2 Changed 5 years ago by jchd18

Use this:

($oPerson.Print)($oPerson) ; version 1

Note that Au3Check chokes on this.

comment:3 Changed 5 years ago by anonymous

Thx jchd18. It's a good idea. With the following code, can I deactivate Au3Check:

#AutoIt3Wrapper_Run_AU3Check=N

comment:4 follow-up: Changed 5 years ago by jchd18

  • Resolution set to Fixed
  • Status changed from new to 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 in reply to: ↑ 4 Changed 5 years ago by anonymous 2

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?

comment:6 follow-up: Changed 5 years ago by jchd18

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 in reply to: ↑ 6 Changed 5 years ago by anonymous 2

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 Changed 5 years ago by jchd18

  • Resolution Fixed deleted
  • Status changed from closed to reopened

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as reopened The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.