Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[SOLVED] Default base for objects?


  • Please log in to reply
11 replies to this topic
Bentschi
  • Moderators
  • 120 posts
  • Last active: Sep 05 2014 02:12 AM
  • Joined: 26 Nov 2008
Hi all,

I played around with the default base object for non-objects.
But i am unable to find a way to access the default base object for objects.
Something like...
obj := []
obj.base.doSomething := Func("ObjDoSomething")

ObjDoSomething(obj)
{
  ;...
}

x := []
x.doSomething()
Is there a way to make this work?
Thanks in advance!

rbrtryn
  • Members
  • 1177 posts
  • Last active: Sep 11 2013 08:04 PM
  • Joined: 22 Jun 2011

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().


My Scripts are written for the latest released version of AutoHotkey.

Need a secure, accessible place to backup your stuff? Use Dropbox!


girlgamer
  • Moderators
  • 3263 posts
  • Last active: Feb 01 2015 09:49 AM
  • Joined: 04 Jun 2010
One of the things i most hated about objects was their lack of granularity. If you just wanted a banana you got the banana all right, but you also got the gorilla holding it, and the entire jungle the gorilla was in.

The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ‚óŹ
MMO Fighter   KeyLooperDemo   Key Spammer   TinyClickRecorder  GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Rock-on%20kitten.gif


Bentschi
  • Moderators
  • 120 posts
  • Last active: Sep 05 2014 02:12 AM
  • Joined: 26 Nov 2008
Thanks

Although the default base cannot be set as in "".base := Object()

I allready read this sentence, but doesn't this meant to be for non-objects?
Sorry if i understand something wrong, but i want to access the base for objects like for non-objects.

How do i get the banana now (with, or without gorilla and jungle)?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

But i am unable to find a way to access the default base object for objects.

There isn't one. You need to create it first.
obj.base := {}

Although the default base cannot be set as in "".base := Object()

Not relevant.

Bentschi
  • Moderators
  • 120 posts
  • Last active: Sep 05 2014 02:12 AM
  • Joined: 26 Nov 2008
I thought there may be a way to add methods to objects that are created with [], {}, Object() or Array(), without had to define something for each instance.

Anyway, thanks to all for the fast support.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
I have just posted a workaround in the Tutorials section.

Bentschi
  • Moderators
  • 120 posts
  • Last active: Sep 05 2014 02:12 AM
  • Joined: 26 Nov 2008
I thought i will get an error if i try to create a function named "Object" or "Array", therefore i did not even tried it.
But it works impeccable.
Thanks for it.

Bentschi
  • Moderators
  • 120 posts
  • Last active: Sep 05 2014 02:12 AM
  • Joined: 26 Nov 2008
The example works great, but sorry that i disturb again.
Maybe it's a stupid question...

Classes seems to be the main-thing of the object-syntax in ahk, or possibly have the same significance like base-objects.
Is it possible to inject methods to classes, with no need to extend from another class or define it in every class?

I thought it would be easier to put methods that i need really often in a main-class.
If this will not work, it's ok too (i can also extend my classes from one).

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
No, each class should explicitly extend your base class.

Bentschi
  • Moderators
  • 120 posts
  • Last active: Sep 05 2014 02:12 AM
  • Joined: 26 Nov 2008
ok, i thought so.
Thanks anyway

Bentschi
  • Moderators
  • 120 posts
  • Last active: Sep 05 2014 02:12 AM
  • Joined: 26 Nov 2008
If someone is interested in what i was making out of this...
Here is the link to the german forum <!-- m -->http://de.autohotkey...pic.php?t=10295<!-- m -->

In the documentation (Dokumentation) is at the end a test-code you can try to understand it.

Vor Non-Objects there is a "binary-mode" which you can enter using the alloc-method and leave with the free-Method.
If you are in binary-mode, you can use the variable like the file-object.
For write-Operations, the size of the buffer will automaticly increase, if there is less than required allocated.

RegEx does not have the same syntax as in AHK "options)searchstring".
The RegEx in this Library looks like "/searchstring/options", because this way you can use Strings too for searching.
For Example:
str := "This is a test!"
strA := str.replace("/test/i", "lie")
strB := str.replace("test", "lie")
Would both do exactly the same.