Page 1 of 1

ObjCount() - Call to nonexistent function | 2.0-a097-60f26de

Posted: 15 Jun 2018, 12:18
by Flipeador

Code: Select all

MsgBox ObjCount({}) ; Call to nonexistent function
MsgBox {1:0,2:0}.Count() ; 2
.. and it does not appear in the list of methods:
https://lexikos.github.io/v2/docs/objects/Object.htm

Re: ObjCount() - Call to nonexistent function | 2.0-a097-60f26de

Posted: 15 Jun 2018, 14:08
by burque505
Not in the list of methods, but the example is there below:
Count := Object.Count()
Returns the number of key-value pairs present in the object.

Code: Select all

MsgBox % {A: 1, Z: 26}.Count()    ;  2
MsgBox % ["A", "B", "C"].Count()  ;  3
MsgBox % ["A",    , "C"].Count()  ;  2
Edit: I do see it says Object.Count, and not ObjCount :D

Just ran this, the msgbox says "4":

Code: Select all

myObject := Array("1","2","3","4")
msgbox myObject.Count()
Regards,
burque505

Re: ObjCount() - Call to nonexistent function | 2.0-a097-60f26de

Posted: 15 Jun 2018, 14:17
by Flipeador
Each method also has an equivalent function, which can be used to bypass any custom behaviour implemented by the object [..]
btw: works well on AHKv1.

Re: ObjCount() - Call to nonexistent function | 2.0-a097-60f26de

Posted: 15 Jun 2018, 14:19
by burque505
I see what you mean now. Point taken.
EDIT: As you say, it works in V1, with the appropriate tweaking:

Code: Select all

myObject := Array("1","2","3","4")
x := myObject.Count()
msgbox %x% ; "4"

y := ObjCount(myObject) ; also "4"
msgbox %y%

Re: ObjCount() - Call to nonexistent function | 2.0-a097-60f26de

Posted: 15 Jun 2018, 15:46
by coffee
Flipeador wrote:
Each method also has an equivalent function, which can be used to bypass any custom behaviour implemented by the object [..]
btw: works well on AHKv1.
It's not in the built-in function array in script.cpp. (Lexikos probably overlooked it, since it's just one line missing).

BIFn(ObjCount, 1, 1, BIF_ObjXXX),

After BIFn(ObjClone, 1, 1, BIF_ObjXXX),

If you need it right now to finish something.

Re: ObjCount() - Call to nonexistent function | 2.0-a097-60f26de

Posted: 15 Jun 2018, 15:54
by Flipeador
Yes, you are right. I had not seen the source code. It's nothing important. Thank you. :D
:wave:

Re: ObjCount() - Call to nonexistent function | 2.0-a097-60f26de  Topic is solved

Posted: 18 Jun 2018, 19:08
by lexikos
Yes, it was overlooked when I merged with v1. The v1 code base uses a giant if-else-if ladder instead of a table of functions.

[2020-06-28: Note that ObjCount has since been renamed to ObjOwnPropCount, although more typically one would use myMap.Count. See v2.0-a104-3e7a969d.]