Retrieving a reference to a String with a Base Object using Object()/ObjGetBase()

Report problems with documented functionality
iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Retrieving a reference to a String with a Base Object using Object()/ObjGetBase()

20 Aug 2018, 11:01

Code: Select all

trouble := "jacks and candy don't mix."

obj := {"water":"H₂O", "❤":"❀ヅ♫"}

trouble.base.storedData := obj

class Text {
   characters(data) {
      RegExReplace(data, "s).", "", i)
      return i
   }
}

for reference, function in Text {
   if IsFunc(function)
      trouble.base[reference] := ObjBindMethod(Text, reference)
}

; TESTING
MsgBox % trouble.storedData.water "`t" trouble.storedData.❤
MsgBox % "Number of Characters in [" trouble "] is " trouble.characters()


; CASE A - Retrieving the String Buffer
MsgBox % address := &trouble                       ; OK
MsgBox % StrGet(address)                           ; OK

; CASE B - Getting some reference to the object...
MsgBox % address := Object(trouble)                ; NOT WORKING

; CASE C = Using new base functions
extractedBase1 := trouble.base
MsgBox % extractedBase1.storedData.water           ; OK
MsgBox % Object(extractedBase1)                    ; OK
extractedBase2 := ObjGetBase(trouble)              ; PARAMETER #1 INVALID
return
I want an address for my variable trouble which clearly has lots of stuff in its base object. What is Object(trouble) even supposed to do in this case?

https://autohotkey.com/docs/Objects.htm ... n_Pointers
https://autohotkey.com/docs/objects/Object.htm#GetBase
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Retrieving a reference to a String with a Base Object using Object()/ObjGetBase()

20 Aug 2018, 11:16

Object functions only work on objects directly - I don't know why you would assume they work on strings.
Also you go the address of the string buffer just fine - what more do you want?
Recommends AHK Studio
iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Re: Retrieving a reference to a String with a Base Object using Object()/ObjGetBase()

20 Aug 2018, 11:20

My string has a base object. You are telling me that ObjGetBase() should not work?
iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Re: Retrieving a reference to a String with a Base Object using Object()/ObjGetBase()

20 Aug 2018, 11:25

https://autohotkey.com/docs/Objects.htm ... c_Var_Init

Code: Select all

"".base.__Set := Func("Default_Set_AutomaticVarInit")

empty_var.foo := "bar"
MsgBox % empty_var.foo

Default_Set_AutomaticVarInit(ByRef var, key, value)
{
    if (var = "")
        var := Object(key, value)
}
Look at this official documentation. If this doesn't imply everything is an object, I don't know what does.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Retrieving a reference to a String with a Base Object using Object()/ObjGetBase()

20 Aug 2018, 11:35

When a non-object value is used with object syntax, the default base object is invoked. This can be used for debugging or to globally define object-like behaviour for strings, numbers and/or variables. The default base may be accessed by using .base with any non-object value; for instance, "".base. Although the default base cannot be set as in "".base := Object(), the default base may itself have a base as in "".base.base := Object().
This does not imply that functions specifically for objects work on non-objects though.
Recommends AHK Studio
iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Re: Retrieving a reference to a String with a Base Object using Object()/ObjGetBase()

22 Aug 2018, 08:31

nnnik wrote:When a non-object value is used with object syntax, the default base object is invoked.
Shouldn't this imply that reference_to_base := Object("string")?
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Retrieving a reference to a String with a Base Object using Object()/ObjGetBase()

22 Aug 2018, 08:49

No just as much as object({base:base}) doesn't get base.
Also calling a function is using function syntax is not using object syntax.
Recommends AHK Studio

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 25 guests