VarSetCapacity() has VarName bug...

Report problems with documented functionality
pidgay
Posts: 5
Joined: 21 Aug 2017, 02:32

VarSetCapacity() has VarName bug...

21 Aug 2017, 02:58

VarSetCapacity() cannot hold capacity if 'VarName' belongs object.

Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox % VarSetCapacity(vvv, 20)	; this prints '20'

oo := {}
MsgBox % VarSetCapacity(oo.x, 20) ; expected '20', but '0'


so I can't write like this.

Code: [Select all] [Download] GeSHi © Codebox Plus

class Test {
buffer := 0
__New(size) {
VarSetCapacity(this.buffer, size)
}
}


I have to write like this.

Code: [Select all] [Download] GeSHi © Codebox Plus

outerBuffer := 0
class Test {
__New(size, ByRef outerBuffer) {
VarSetCapacity(outerBuffer, size)
}
}


In documentation,
If VarName is not a valid variable name (such as a literal string or number), 0 is returned.



is this a bug, right?
fix this, please.

sorry for poor english
thanks for reading this
poor english :(
Helgef
Posts: 2391
Joined: 17 Jul 2016, 01:02
Contact:

Re: VarSetCapacity() has VarName bug...

21 Aug 2017, 08:18

o.xx is not a variable name, its an expression which gets the content of the key xx in o. Use setCapacity for an object's fields. If you want to initialise the memory to zero, you can use eg, globalAlloc.

Cheers.
pidgay
Posts: 5
Joined: 21 Aug 2017, 02:32

Re: VarSetCapacity() has VarName bug...

21 Aug 2017, 09:16

Helgef wrote:o.xx is not a variable name, its an expression which gets the content of the key xx in o. Use setCapacity for an object's fields. If you want to initialise the memory to zero, you can use eg, globalAlloc.

Cheers.


I understood o.xx is an expression which gets the content of the key xx in o.
but field of class = key of object in Autohotkey????

Actually, I tend to use built-in functions(eg. VarSetCapacity) rather than DllCall(eg. GlobalAlloc)...
thank you for replying. ;)
poor english :(
Helgef
Posts: 2391
Joined: 17 Jul 2016, 01:02
Contact:

Re: VarSetCapacity() has VarName bug...

21 Aug 2017, 11:13

Hello. I would describe a field as a key/value pair, you set the capacity for the value.

Cheers, :)
obeeb
Posts: 140
Joined: 20 Feb 2014, 19:15

Re: VarSetCapacity() has VarName bug...

21 Aug 2017, 20:02

pidgay wrote:but field of class = key of object in Autohotkey????

Autohotkey uses prototype based inheritance, everything is a key of object or a key of the base(prototype) object or the key of the base of the base object...
This includes constructors, destructors, properties, meta properties...
In Autohotkey "field of class" is just a key that is added in the auto generated __Init method, this method is called before the constructor(__New) when you use the new keyword.

A class in Autohotkey is not really a class but just syntactic sugar for the following:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



The above code is exactly the same as:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



If you are coming from languages with "real" classes that use class based inheritance like Java, c# or c++ this might seem strange but you will get used to it.
You should thoroughly read https://autohotkey.com/docs/Objects.htm#Custom_Objects it's probably the most difficult documentation page in Autohotkey but it's very well explained.
pidgay
Posts: 5
Joined: 21 Aug 2017, 02:32

Re: VarSetCapacity() has VarName bug...

09 Sep 2017, 01:50

You should thoroughly read https://autohotkey.com/docs/Objects.htm#Custom_Objects it's probably the most difficult documentation page in Autohotkey but it's very well explained.


Oh my god! What I wanna know was in document!! :shock:

Your kind answer makes me relieved of anxiety.

Thank you! x2 :D
poor english :(

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 3 guests