 |
AutoHotkey Community Let's help each other out
|
AutoHotkey_L: Arrays, Debugger, x64, COM, #If expression ...
Goto page Previous 1, 2, 3 ... 29, 30, 31 ... 68, 69, 70 Next
|
| View previous topic :: View next topic |
| Author |
Message |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Tue Mar 16, 2010 2:08 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
jackieku
Joined: 30 Nov 2008 Posts: 73
|
Posted: Tue Mar 16, 2010 3:41 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
greynite
Joined: 17 May 2008 Posts: 39 Location: Dallas, TX
|
Posted: Fri Mar 19, 2010 10:10 pm Post subject: Having trouble with call to user defined meta-function |
|
|
I'm trying to call a user define function "newEntry" thusly:
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:.. 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 |
|
| Back to top |
|
 |
HotKeyIt
Joined: 18 Jun 2008 Posts: 4653 Location: AHK Forum
|
Posted: Fri Mar 19, 2010 10:44 pm Post subject: |
|
|
| 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  |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7299 Location: Australia
|
Posted: Sat Mar 20, 2010 1:22 am Post subject: Re: Having trouble with call to user defined meta-function |
|
|
| 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 |
|
|
| Back to top |
|
 |
Mystiq
Joined: 08 Jan 2007 Posts: 83
|
Posted: Sat Mar 20, 2010 8:34 am Post subject: RegexMatch position mode bug? |
|
|
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? |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7299 Location: Australia
|
Posted: Sat Mar 20, 2010 9:15 am Post subject: |
|
|
| It's a bug caused by some Unicode-related changes. Thanks for reporting it. |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7299 Location: Australia
|
Posted: Sun Mar 21, 2010 6:57 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
emmanuel d
Joined: 29 Jan 2009 Posts: 436 Location: Belgium
|
Posted: Sun Mar 21, 2010 8:20 pm Post subject: |
|
|
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  _________________ Stopwatch
emdkplayer
http://www.autohotkey.com/forum/viewtopic.php?p=306819
the code i post falls under the:
WTFYW license
, wich meens its free to use |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Sun Mar 21, 2010 8:40 pm Post subject: |
|
|
| 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"] |
_________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference |
|
| Back to top |
|
 |
majkinetor ! Guest
|
Posted: Mon Mar 22, 2010 8:22 am Post subject: |
|
|
| Quote: | | i gues this will never be supported: |
LOL |
|
| Back to top |
|
 |
emmanuel d
Joined: 29 Jan 2009 Posts: 436 Location: Belgium
|
Posted: Mon Mar 22, 2010 5:42 pm Post subject: |
|
|
| 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  _________________ Stopwatch
emdkplayer
http://www.autohotkey.com/forum/viewtopic.php?p=306819
the code i post falls under the:
WTFYW license
, wich meens its free to use |
|
| Back to top |
|
 |
greynite
Joined: 17 May 2008 Posts: 39 Location: Dallas, TX
|
Posted: Mon Mar 22, 2010 7:13 pm Post subject: Re: Having trouble with call to user defined meta-function |
|
|
| 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 |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7299 Location: Australia
|
Posted: Tue Mar 23, 2010 8:13 am Post subject: Re: Having trouble with call to user defined meta-function |
|
|
| 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. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|