Override the default *object* base class

Get help with using AutoHotkey and its commands and hotkeys
geek
Posts: 918
Joined: 02 Oct 2013, 22:13
GitHub: G33kDude
Location: GeekDude
Contact:

Override the default *object* base class

06 Jan 2015, 16:11

I'll let the comments explain

Code: Select all

; I want to be able do this
MsgBox, % "aeiou".Split().Join(".")

; But instead I have to do this
MsgBox, % "".Join.("aeiou".Split(), ".")

class CustomObject
{
	static _ := "".base.base := CustomObject
	
	Split(Args*)
	{
		return StrSplit(this, Args*)
	}
	
	Join(JoinString)
	{
		for k,v in this
			Out .= JoinString . v
		return Out.Sub(JoinString.Len()+1)
	}
	
	Sub(Args*)
	{
		return SubStr(this, Args*)
	}
	
	Len()
	{
		return StrLen(this)
	}
}
That is, without manually setting the base
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Re: Override the default *object* base class

06 Jan 2015, 16:51

.Split() returns an object so you would have to assign its base too. Default base object will only work on non-object stuff like strings and numbers.

Code: Select all

; I want to be able do this
MsgBox, % "aeiou".Split().Join(".")

; But instead I have to do this
; MsgBox, % "".Join.("aeiou".Split(), ".")

class CustomObject
{
    static _ := "".base.base := CustomObject
    
    Split(Args*)
    {
        oSplit := StrSplit(this, Args*)
        oSplit.base := CustomObject
        return oSplit
    }
    
    Join(JoinString)
    {
        for k,v in this
            Out .= JoinString . v
        return Out.Sub(JoinString.Len()+1)
    }
    
    Sub(Args*)
    {
        return SubStr(this, Args*)
    }
    
    Len()
    {
        return StrLen(this)
    }
}
geek
Posts: 918
Joined: 02 Oct 2013, 22:13
GitHub: G33kDude
Location: GeekDude
Contact:

Re: Override the default *object* base class

06 Jan 2015, 17:13

I don't want to have to set the base of every object I want to use .Join() on though, that's the problem
lexikos
Posts: 8292
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Override the default *object* base class

06 Jan 2015, 18:05

Too bad.

There is no default object base class. You cannot override that which does not exist.

You can override {} and []: Customizing Object() and Array()

Return to “Ask For Help”

Who is online

Users browsing this forum: arczi_87, geoffh, Google [Bot], Green Astronaut, hitman, Lepes, mikeyww, samyo2323, XMCQCX and 50 guests