AutoHotkey Community

It is currently May 27th, 2012, 6:31 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 173 posts ]  Go to page Previous  1 ... 8, 9, 10, 11, 12  Next
Author Message
 Post subject:
PostPosted: August 4th, 2010, 9:06 pm 
can this be used to solve this problem:

http://www.autohotkey.com/forum/topic61031.html


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2010, 9:21 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Of course it is ;)

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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: August 5th, 2010, 6:35 pm 
Offline

Joined: February 29th, 2008, 8:36 pm
Posts: 901
Location: Vault 7
I just spent a good chunk of time trying to figure out why I couldn't get any of my old LowLevel.ahk stuff working. It might be worth mentioning that DEP can block key LowLevel functions and cause the scripts to crash. Other posts in other topics hint at such a conflict, but I'm saying it here explicitly to help any others who run into the same problem.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 5th, 2010, 10:34 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
RegisterCallback callbacks have that problem, but I think in this case __mcode is the problem (since RegisterCallback is only used to get a Func pointer--the callbacks aren't called). Try adding the following to __mcode after pbin is set but before it is returned:
Code:
    ptr := A_PtrSize ? "ptr" : "uint"
    DllCall("VirtualProtect", ptr, pbin, ptr, StrLen(Hex)//2, uint, 0x40, uintp, 0)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 5th, 2010, 10:57 pm 
Offline

Joined: February 29th, 2008, 8:36 pm
Posts: 901
Location: Vault 7
That fixed it! Sorry for not mentioning earlier that I already tracked the problem to __mcode. Now the world can finally play Half Life and use __getVar at the same time.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 8th, 2010, 12:36 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
__getFirstFunc required an update for compatibility with AutoHotkey_L revision 53. (However, it still isn't compatible with x64.) I've also added the VirtualProtect call in __mcode. As usual, I replaced the "v1.0.48" download in my first post.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 16th, 2010, 1:23 am 
Offline

Joined: August 2nd, 2009, 6:40 am
Posts: 215
I had bookmarked this thread a while back but didn't dig deep enough - as I couldn't see what I could use it for at the time, and never noticed the __static() function:
Which has finally cleanly enabled my attempt at non-Global Constants.
Thanks, Lexikos.

Requires: lowlevel.ahk's __static()
Purpose:
To get rid of global Constants, and have one Function that contains a group of static Constants, that can:
Quote:

  1. if( dx == ValidVar ) Then Return the Value of VarName.
    Query the value of a Constant on the fly.
  2. if( dx is integer):
    • if( init == 0): return Array%dx% (VarName)
    • if( init > 0 ):: return Value of Array%dx%
    Which lets us initialize ALL the constants in any given function.
    With only 2 lines of Code:
    • while( !init && tmpVar := OC2( ++i, init ) ) ;; init will be 0 until i > index0(size) of Constants array
      __ __static( %tmpVar% := OC2( i, i ) )

Code:
Lowlevel_init()

StaticTest()
StaticTest()
StaticTest("FS_IMAGE_ADDRESS")
StaticTest("NO_VAR")

StaticTest(dx="")
{
   static init:=0
   if( dx )
   {
      if( !init )
         return
      tmpVar := OC2( dx )
      MsgBox, %dx%: %tmpVar%
   return
   }
   i := 0
   while( !init && tmpVar := OC2( ++i, init ) )   ;; init will be 0 until i > index0(size) of OC's array
                    __static( %tmpVar% := OC2( i, i ) )
   MsgBox, FS_IMAGE_PAGETEXT: %FS_IMAGE_PAGETEXT%
return
}


OC2( dx, byRef init=0, calledBy="" )
{
   static
   static oc := "FS_IMAGE_NAME=1,FS_IMAGE_TITLEBAR=2,FS_IMAGE_PAGETEXT=4,FS_IMAGE_ADDRESS=8
      ,FS_IMAGE_ALTNAME=16,FS_PREFETCH_TITLE=32,FS_IMAGE_ADD_X=170,FS_IMAGE_ADD_Y=180
      ,FS_IMAGE_ALT_X=170,FS_IMAGE_ALT_Y=210"
   local oTmp0, oTmp1, oTmp2
   if( !FS_IMAGE_NAME )
   {
      StringSplit, aOC, oc, `,
      Loop, %aOC0%
      {
         RegExMatch( aOC%A_Index%, "^(.*)=(.*)$", oTmp )
         __static( %oTmp1% := oTmp2 )      ; Assign VAR=VAL, so function can return VAL when dx==validVAR
         __static( aOC%A_Index% := oTmp1 )   ; So we don't have to initialize the array again.
      }
   }
   if dx is integer
      return ( !init ? (aOC%dx% ? aOC%dx% : (init:=1) && 0) : ((retVal := aOC%dx%) ? %retVal% : ""))
return AssertBox( retVal := %dx%, A_ThisFunc, "Variable: (" dx ") doesn't exist!" )
}

AssertBox( msgOK, fn, msg="", fn_mod="" )
{
   if( msgOK )
      return MsgOK
   MsgBox,, `t%fn%() Assert FAILED,%fn%(%fn_mod%):`n(`n    %msg%`n)
   ErrorLevel := 1
   ;Exit
   Pause   ; To Enable Easy SystemTray Reload Tests
}

Prior to this,
1) The variables were globals -- which I didn't want.

2) The variables were static and had to be copy/pasted into each Function
&) Difficult to maintain if there were additions or changes to the constants.

3) The variables were static and contained in one File which had multiple hardlinks -- so they could be included into the relevant function. And set with a similiar while loop.
&) Messy solution still.
&) And to prevent the Array from being initialized each time, one had to manually static each array element, plus error checking:
Quote:
static aOC0, aOC1, aOC2, aOC3, aOC4, aOC5, aOC6, aOC7, aOC8, aOC9, aOC10
local iOC := 10 ; This needs to match the number of aOC variables ------------^


Previous Version:
Code:
OC( dx, byRef init )
{
   static
   static oc := "FS_IMAGE_NAME=1,FS_IMAGE_TITLEBAR=2,FS_IMAGE_PAGETEXT=4,FS_IMAGE_ADDRESS=8
      ,FS_IMAGE_ALTNAME=16,FS_PREFETCH_TITLE=32,FS_IMAGE_ADD_X=170,FS_IMAGE_ADD_Y=180
      ,FS_IMAGE_ALT_X=170,FS_IMAGE_ALT_Y=210"
   static aOC0, aOC1, aOC2, aOC3, aOC4, aOC5, aOC6, aOC7, aOC8, aOC9, aOC10
   local iOC := 10   ; This needs to match the number of aOC variables --^
   local oTmp0, oTmp1, oTmp2
   if( !aOC0 )
   {
      StringSplit, aOC, oc, `,
      onErrorExit( aOC0 != iOC, A_ThisFunc, "Invalid number of static variables. ", iOC . " != " aOC0 )
   }
   RegExMatch( aOC%dx%, "^(.*)=(.*)$", oTmp )
   return ( !init ? (oTmp1 ? oTmp1 : (init:=1) && 0) : oTmp2 )

onErrorExit( msgOK, fn, msg, fn_mod="", delay=3)
{
   if( !msgOK || !msg )
      return 0
   MsgBox, ,, %fn%(%fn_mod%): %msg%, %delay%
Exit
}


[Moderator's note: Added wrapping to static initializers.]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 16th, 2010, 4:39 am 
Crash&Burn wrote:
3) The variables were static and contained in one File which had multiple hardlinks -- so they could be included into the relevant function.
You can include the same file multiple times using #IncludeAgain, no need for hardlinks.
Quote:
&) And to prevent the Array from being initialized each time, one had to manually static each array element,
There's only one reason to declare a static var in an assume-static function: for once-off initialization. If you're not initializing them (static var:="value", var2:="value2"), there's no need to declare them individually.

The following simplification of your "Previous Version" appears to work okay, without declaring each array element and without the use of __static:
Code:
OC( dx, byRef init )
{
   static
   static oc := "
    (LTrim Join,
    FS_IMAGE_NAME=1
    FS_IMAGE_TITLEBAR=2
    FS_IMAGE_PAGETEXT=4
    FS_IMAGE_ADDRESS=8
    FS_IMAGE_ALTNAME=16
    FS_PREFETCH_TITLE=32
    FS_IMAGE_ADD_X=170
    FS_IMAGE_ADD_Y=180
    FS_IMAGE_ALT_X=170
    FS_IMAGE_ALT_Y=210
    )"
   local oTmp, oTmp1, oTmp2  ; oTmp, NOT oTmp0
   if( !aOC0 )
      StringSplit, aOC, oc, `,
   RegExMatch( aOC%dx%, "^(.*)=(.*)$", oTmp )
   return ( !init ? (oTmp1 ? oTmp1 : (init:=1) && 0) : oTmp2 )
}

F() {
    static
    local i := 0
    while( !init && tmpVar := OC( ++i, init ) )
       %tmpVar% := OC( i, i )
    ListVars
    Pause
}
F()
(Also note the browser-friendly continuation section.)

Are you aware of AutoHotkey_L? It has proper support for associative arrays, among many other things.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 16th, 2010, 6:30 pm 
Offline

Joined: August 2nd, 2009, 6:40 am
Posts: 215
Interesting. I had tried on multiple occasions to use the bracket
(
)

syntax, but I never could get that correct.

I also got turned around with Static's due to a question I posted here on the boards: wherein it seemed like the leading line: "static" didn't work as the helpfile indicated. My static tests needed a leading static type -- else they were assigned on every function call.

Yet in your modification of my "Previous Version" init doesn't even need to be initialized, and init as well as all the other vars (including all of AHKs pseudo-array vars) become type: static.

Odd about the local "; oTmp, NOT oTmp0" -- I was sure in the past when I used RegExMatch that Match0 was assigned -- must of mixed up CMD.exe batch syntax there.

Thanks for the insights, much appreciated.

lexios wrote:
Are you aware of AutoHotkey_L? It has proper support for associative arrays, among many other things.

Yes, but I'm using Win2K still, should be getting Win7 this Fall.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 16th, 2010, 11:20 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Crash&Burn wrote:
Odd about the local "; oTmp, NOT oTmp0" -- I was sure in the past when I used RegExMatch that Match0 was assigned
Maybe you confused it with StringSplit.
Quote:
Yes, but I'm using Win2K still, should be getting Win7 this Fall.
Even better - you can test Win2k support for me. :P Win2k (SP4+updates) support was added about a week ago, but I only mentioned it in the change log a couple days ago.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 29th, 2010, 12:10 am 
Offline

Joined: July 25th, 2010, 11:36 pm
Posts: 154
Need some help here: I downloaded the latest LowLevel_104800.zip on Nov. 11, 2010 and I cannot find any code in the forums that work with it. Either the function is unavailable or it crashes. Any suggestions appreciated...

_________________
“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 29th, 2010, 9:08 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Which version of AutoHotkey are you using?

Take note of the version/revision numbers in the first post in this thread. LowLevel consists of a bunch of hacks that depend on certain details that may change from version to version without warning. I haven't been maintaining the script for a while, so it's probably best just to avoid it.

AutoHotkey.dll implements some LowLevel features natively.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 18th, 2011, 2:53 pm 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
Quote:
AutoHotkey_L Revision 28+
# Some functions of LowLevel.ahk and code.ahk are not supported. Use at your own risk.


maybe this is already answered somewhere, but

Is there an elegant way (that will work going forward) to call "userfunctioniknownothingabout"

i want to be able to call "userfunctioniknownothingabout" without knowing its default parameters, also dont want to require user to do any thing special in their function.

also expect the default parameters for "userfunctioniknownothingabout" (1) to show up in msgbox

Code:
;fake code
;call function
objectmethod("","userfunctioniknownothingabout")
;some base ahk line of code
objectmethod("","MsgBox,Hi")
return

userfunctioniknownothingabout(p1=1,p2=1,p3=1){
   MsgBox % "p1=" . p1 . ",p2=" . p2 . ",p3=" . p3
}

objectmethod(object,p1="¬",p2="¬",p3="¬",p4="¬"){
   ;what id like to do
   loop ; get all params that were used,seperate them with comma
      p%A_Index% <> "¬" ? p .= p%A_Index% . ","
   StringTrimRight,p,p,1 ;get rid of training comma
   ;call function
   %p1%(%p%)
   ;or maybe some other line of code
   ;some base ahk line of code that is a command
   %p1%
}


i prefer not to use if/then or whatever to decide how many parameters to call it with

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 18th, 2011, 4:37 pm 
Can you take advantage of the variadic functions, or do u specifically need legacy ahk (it requires AHK_L 60+)

Code:
Join(sep, params*) {
    for index,param in params
        str .= param . sep
    return SubStr(str, 1, -StrLen(sep))
}
MsgBox % Join("`n", "one", "two", "three")


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 18th, 2011, 6:18 pm 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
i dont really see how that is relevant, could you explain more?

even utilizing that i dont see how i can avoid
Code:
;fake code
somefunctioniknownothingabout(p1=1,p2=1,p3=1){
   MsgBox % p1 . p2 . p3
}
myfunc(params*){
;some code here to turn params into p1 etc
if p3
  somefunctioniknownothingabout(p1,p2,p3)
elseif p2
  somefunctioniknownothingabout(p1,p2)
elseif p1
  somefunctioniknownothingabout(p1)
}


the point is to call somefunctioniknownothingabout with the parameters as passed to myfunc.

allowing somefunctioniknownothingabout to utilize its default parameters, so i cant pass it empty variables, and i dont want if/then ladder...


it would also be neat to do something like
Code:
;fake code
Address := Object(self)
labelname := Address . "_Timer"
script_to_add .= labelname . ":`n"
script_to_add .= "x=" . 1+1+1+1 . "`n"
script_to_add .= "somefunction(x)`n"
script_to_add .= "return`n"
Script.AddSection(script_to_add)
SetTimer, % labelname, -1

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 173 posts ]  Go to page Previous  1 ... 8, 9, 10, 11, 12  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Bing [Bot], Google [Bot], Yahoo [Bot] and 24 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