AutoHotkey Community

It is currently May 27th, 2012, 3:11 am

All times are UTC [ DST ]




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1036 posts ]  Go to page Previous  1 ... 27, 28, 29, 30, 31, 32, 33 ... 70  Next
Author Message
 Post subject:
PostPosted: March 16th, 2010, 3:08 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
lexikos* wrote:
I think it only serves to mislead those not in the know, without adding any real meaning or convenience. I also think the main benefit of the _NewEnum approach is that a scripted object could override it; if that is done, Enum[k,v] and Enum[k]:=v would be ambiguous.
To me, enum[k]:=v appears elegant. We can think of obj/enum as the conjugate pair under the time reversal, i.e., obj/enum propagates forward/backward in time, and obj/enum[k]:=v remains a valid form under reversing time. At any rate, IMO, there is no need to disallow it. Let the user decide what to use.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2010, 4:41 pm 
Offline

Joined: November 30th, 2008, 1:51 pm
Posts: 73
Lexikos wrote:
On a related note, I think we should replace (or supplement) the numeric flags with a more intuitive options string. I don't like having to refer to the documentation every time I want to call FileOpen. Perhaps something like this:
Code:
;First character indicates access mode
r   read
w   write
a   append
u   update (read/write)

;Subsequent characters are optional flags
r   SHARE_READ
w   SHARE_WRITE
d   SHARE_DELETE
`n  translate between `r`n and `n
`r  replace standalone `r with `n when reading

;Example
f := FileOpen(fn, "ar`n")  ; append and share read access


I though about it, but it can be achieved in script level easily, too.

We do not provide a library that contains most common used scripts like AutoIt does (though we have many nice scripts in this forum or the wiki), but I think it may be good to do. This can avoid adding these trivial works to the core and bloating its size.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 19th, 2010, 11:10 pm 
Offline

Joined: May 17th, 2008, 5:00 am
Posts: 39
Location: Dallas, TX
I'm trying to call a user define function "newEntry" thusly:
Code:
t1.newEntry()
newEntry doesn't take any parameters. This is by design (think of it as a constructor w/ no parameters).

My first problem is when I do the simple syntax above, it doesn't invoke anything.

The second problem is if I spice things up a bit by doing:
Code:
t1.newEntry(1)
.. my function get's invoked, but it's not passing the object reference into the call. The documentation says "When called, the parameter list contains a reference to the target object, followed by the parameters of the get, set or call operation."

Here is my full code:
Code:
#SingleInstance force

t1 := Object("title","one", "tags", Object("a","foo","b","bar"))
t1.newEntry := "Task_newEntry"
   
t := EnumTree( t1 )

ListVars
MsgBox, % t
Pause

; Doesn't work
t1.newEntry()

; Doesn't pass t1, passes 1
t1.newEntry(1)

t := EnumTree( t1 )
ListVars
MsgBox, % t
Pause

enumTree( o, depth="" )
{
   Enum := o._NewEnum()
   While Enum.Next(k,v)
   {
      if IsObject( v ) {
         t .= depth . k . "== Object`n"
         t .= enumTree( v, depth . " •" )
      } else {
         t .= depth . k . "==" . v . "`n"
      }
   }
   return t
}

;Task_newEntry( func, obj="~!", param="~!" )
Task_newEntry( obj )
{
   n = 0
   ListVars
   Pause
   if ( obj.Entrys )
      if ( obj.Entrys._MaxIndex() )
         n := obj.Entrys._MaxIndex()
   n += 1
   ListVars
   Pause
   return obj.Entrys[n] := A_Now
}


Appreciate any help!!!

Thanks,
Shawn


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2010, 11:44 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Code:
;Instead
t1.newEntry := "Task_newEntry"
;Use
t1 := Object("title","one", "tags", Object("a","foo","b","bar")
            ,"base",Object("newEntry","Task_newEntry"))

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 20th, 2010, 2:22 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
jackieku wrote:
We do not provide a library ..., but I think it may be good to do.
I agree, but in this case I think it really helps the usability of the function. Even if you can remember the flags, some other user reading your code probably won't. If I were to provide a user-friendly wrapper, I'd have to recommend everyone use it over the built-in function...
greynite wrote:
The documentation says "When called, the parameter list contains a reference to the target object, followed by the parameters of the get, set or call operation."
Check the context - that only applies to meta-functions, i.e. __Get, __Set and __Call. Similar behaviour is briefly mentioned for other methods defined in base under Extensibility. Essentially, an object reference is passed only if/because the function is defined/called indirectly through a base object.
HotKeyIt wrote:
,"base",Object("newEntry","Task_newEntry"))
This should also work:
Code:
t1.base["newEntry"] := "Task_newEntry"  ; automatic init
NOT this:
Code:
t1.base.newEntry := "Task_newEntry"     ; base must exist


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 20th, 2010, 9:34 am 
Offline

Joined: January 8th, 2007, 1:14 pm
Posts: 83
Noticed that the RegexMatch in position mode returns "1" for non-matched patterns when in standard AHK it returns "0".

Code:
RegExMatch("this is a test", "P)(\Qdoes not match\E)", Match)


Using "AutoHotkey_L".
Code:
Global Variables (alphabetical)
--------------------------------------------------
0[1 of 3]: 0
ErrorLevel[1 of 3]: 0
Match[1 of 3]: 0
MatchLen1[1 of 3]: 0
MatchPos1[1 of 3]: 1


Using normal Autohotkey.

Code:
Global Variables (alphabetical)
--------------------------------------------------
0[1 of 3]: 0
ErrorLevel[1 of 3]: 0
Match[1 of 3]: 0
MatchLen1[1 of 3]: 0
MatchPos1[1 of 3]: 0


Is this intended or possibly a bug of some sort?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2010, 10:15 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
It's a bug caused by some Unicode-related changes. Thanks for reporting it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 5:03 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
The comparison of features link in version history seems dead: http://www.autohotkey.net/~Lexikos/AutoHotkey_L/docs/LvsU.htm.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 7:57 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Thanks, I had removed the file when I revised the documentation since most of it was rewritten in more detail elsewhere. (But there is no comparison elsewhere since jackieku now steers users towards AutoHotkey_L.) I've restored it and also updated the documentation download, which hadn't been updated last time due to an error in my update script.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 9:20 pm 
Offline

Joined: January 29th, 2009, 9:50 pm
Posts: 483
Location: Belgium
i gues this will never be supported:
Code:
Assoc := Object("!ut","TmpTorrent", "avi","Avifile","txt","txtfile","ahk","ahkfile","ahk_l","ahk_lfile")
MsgBox % "Assoc: avi:" Assoc.avi
MsgBox % "Assoc: ahk_l:" Assoc.ahk_l   ; not showing result no error
; MsgBox % "Assoc: !ut" Assoc.!ut      ; this failes with error at loadtime
; Enumerate! works fine shows all keys and values, sorted
enumAssoc := Assoc._NewEnum()
While enumAssoc[ext, Assoc]
    MsgBox,%ext%=%Assoc%

i can never directly ask the value of !ut but i need to loop to find it.
wich is out of the question for me.
this is my firs array tryout.
Lexikos, thanks for all the hard work you put in it :D

_________________
Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 9:40 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Object Documentation wrote:
Object.Param
When the first parameter is a known (literal) value consisting purely of alphanumeric characters and/or underscore ...
Code:
MsgBox % "Assoc: ahk_l = " Assoc.ahk_l   ; <-- works fine for me
MsgBox % "Assoc: !ut = " Assoc["!ut"]

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2010, 9:22 am 
Quote:
i gues this will never be supported:

LOL


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2010, 6:42 pm 
Offline

Joined: January 29th, 2009, 9:50 pm
Posts: 483
Location: Belgium
Code:
MsgBox % "Assoc: ahk_l = " Assoc.ahk_l   ; <-- works fine for me
Works for me to, had a typo, fixed it in the example but not in my code :lol:

_________________
Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 22nd, 2010, 8:13 pm 
Offline

Joined: May 17th, 2008, 5:00 am
Posts: 39
Location: Dallas, TX
Lexikos wrote:
greynite wrote:
The documentation says "When called, the parameter list contains a reference to the target object, followed by the parameters of the get, set or call operation."
Check the context - that only applies to meta-functions, i.e. __Get, __Set and __Call. Similar behaviour is briefly mentioned for other methods defined in base under Extensibility. Essentially, an object reference is passed only if/because the function is defined/called indirectly through a base object.

Ok I get it. So for direct calls, is there a "this" or "me" variable that gets set?

(Although I'm getting the feeling this is a silly question, that methods should be set in the .base, and data belongs in the specific instance of the class)

Thanks,
Shawn


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 23rd, 2010, 9:13 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
greynite wrote:
So for direct calls, is there a "this" or "me" variable that gets set?
No. If there was, there'd be no need for the differing behaviour, and no need to pass it as a parameter. (I chose the current approach for performance and practicality reasons.)
Quote:
Although I'm getting the feeling this is a silly question,
No. :)
Quote:
that methods should be set in the .base, and data belongs in the specific instance of the class
That's about it. My view is that when a value stored in an object is "called" directly, there's nothing inherently special about it and no reason to alter the parameter list. On the other hand, base exists to define the behaviour of the object, so functions called via this mechanism must be designed to accept (and probably require) a reference to the original object.

Of course, each object can have its own unique base if necessary. Alternatively, the behaviour of individual "methods" can be controlled by calling objects instead of function names:
Code:
lex := Object("name", "Lexikos", "says", Method("Person_Speak"))
lex.says("hello!")

Person_Speak(this, p1) {
    MsgBox % this.name " says " p1
}
Method(func_name) {  ; oversimplified, should really cache "base" object.
    return Object("", func_name, "base", Object("__Call", "Method_Call"))
}
Method_Call(m, this, p1="", p2="", p3="", p4="", p5="", p6="", p7="", p8="") {
    return m.(this,p1,p2,p3,p4,p5,p6,p7,p8)
}
There's another example of this technique under "Objects as Functions" in the docs.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1036 posts ]  Go to page Previous  1 ... 27, 28, 29, 30, 31, 32, 33 ... 70  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 9 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group