Detecting traces of the default base object

Post your working scripts, libraries and tools for AHK v1.1 and older
iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Detecting traces of the default base object

18 Nov 2018, 22:26

Code: Select all

try MsgBox % "Ground Level: " ObjRawGet(q, "__class")                      " Number of Objects: " q.Count()
try MsgBox % "Level -1: " ObjRawGet(q.base, "__class")                     " Number of Objects: " q.base.Count()
try MsgBox % "Level -2: " ObjRawGet(q.base.base, "__class")                " Number of Objects: " q.base.base.Count()
try MsgBox % "Level -3: " ObjRawGet(q.base.base.base, "__class")           " Number of Objects: " q.base.base.base.Count()
try MsgBox % "Level -4: " ObjRawGet(q.base.base.base.base, "__class")      " Number of Objects: " q.base.base.base.base.Count()
try MsgBox % "Level -5: " ObjRawGet(q.base.base.base.base.base, "__class") " Number of Objects: " q.base.base.base.base.base.Count()
I was confused as to why the MsgBox was showing 0 objects instead of throwing an error. It turns out that q.base.base resolves to the "" empty string. And "".base is a valid object. Therefore at every odd level in the hierarchy of bases, one will find a valid object.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Detecting traces of the default base object

19 Nov 2018, 12:33

The default base may be accessed by using .base with any non-object value; for instance, "".base

Code: Select all

dbo := 1.base ; here it is, do what you like with it
dbo.push(1,2,3)
msgbox % isobject(dbo) "`n" dbo.count()
Cheers.
Last edited by Helgef on 19 Nov 2018, 12:46, edited 1 time in total.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Detecting traces of the default base object

19 Nov 2018, 12:43

Helgef's code is v2 only ;)

iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Re: Detecting traces of the default base object

19 Nov 2018, 12:48

Too late he made a ninja edit!

Original v2:

Code: Select all

dbo := 1.base ; here it is, do what you like with it
dbo.push 1,2,3
msgbox isobject(dbo) '`n' dbo.count()
Last edited by iseahound on 19 Nov 2018, 12:49, edited 1 time in total.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Detecting traces of the default base object

19 Nov 2018, 12:49

Hello guest3456 :wave:
I updated it, it is now untested ;) .
Cheers

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 212 guests