Changes between Initial Version and Version 1 of Ticket #2713


Ignore:
Timestamp:
05/18/14 18:15:49 (10 years ago)
Author:
Mat
Comment:

This has been discussed here: http://www.autoitscript.com/forum/topic/161296-supposed-byref-bug/ (Link is to MVP section)

I've changed the code in the report to be much simpler, without the OPs attempt to write object oriented AutoIt without objects.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #2713 – Description

    initial v1  
    1 In the following script, the presence of {{{ByRef}}} causes {{{$old}}} to be a reference, not a copy.
     1In the following script, the presence of {{{ByRef}}} causes {{{$b}}} to be a reference, not a copy.
     2
    23{{{
    3 #include "car.au3"
     4Local $a[2] = [1, 2]
    45
    5 $car = Car () ; speed: 50
     6test($a[0])
    67
    7 Func getAcceleratedCar (ByRef $car_speed)
    8         Local $old = $car
    9         $car_speed *= 2
    10         Local $new = $car
     8Func test(ByRef $foo)
     9    Local $b = $a
     10    $foo += 1
    1111
    12         Car_printSpeed ($car, "car") ; speed: 100
    13         Car_printSpeed ($old, "old") ; speed: 100, expected 50
    14         Car_printSpeed ($new, "new") ; speed: 100
    15 
    16         $car = $old
    17         return $new
    18 EndFunc
    19 
    20 getAcceleratedCar ($car [$Car_Speed])
     12    ConsoleWrite($a[0] & @LF)
     13    ConsoleWrite($b[0] & @LF)
     14EndFunc   ;==>test
    2115}}}
    22 
    23 car.au3:
    24 {{{
    25 ; class Car
    26 Func Car ($speed = 50)
    27         Local $__instance [$__Car__ObjectSize] = [$__Car__VTable]
    28         $__instance [$Car_Speed] = $speed
    29         return $__instance
    30 EndFunc
    31 Func __Car__printSpeed__Impl (ByRef $__instance, $name)
    32         ConsoleWrite ("speed of " & $name & ": " & $__instance [$Car_Speed] & @CRLF)
    33 EndFunc
    34 Func Car_printSpeed (ByRef $__instance, $__arg1)
    35         Local $function = ($__instance [$__Car__VTableIndex]) [$__Car__printSpeed__Index]
    36         Return $function ($__instance, $__arg1)
    37 EndFunc
    38 Const $__Car__VTableIndex = 0
    39 Const $__Car__VTable = [__Car__printSpeed__Impl]
    40 Const $__Car__printSpeed__Index = 0
    41 Const $__Car__ObjectSize = 2
    42 Const $Car_Speed = 1
    43 ; end class Car
    44 }}}