AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Dictionary (Hash,Associative Array,map...) using perlahk

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
MisterW



Joined: 20 Jul 2005
Posts: 65

PostPosted: Fri Jun 16, 2006 12:28 pm    Post subject: Dictionary (Hash,Associative Array,map...) using perlahk Reply with quote

Here's a pretty basic implementation of a Dictionary (also called hash) using thomasl's nifty perlahk dll
see:
http://www.autohotkey.com/forum/viewtopic.php?t=4593
for discussion and http://www.autohotkey.net/file/users/Members/thomasl/perlahk.zip
for the dll code

I'm constantly frustrated by ahk's support for complex data structures so I'm hoping this might be a path to an easy solution.

Presumably some of the issues with this solution (including speed) could be fixed by adding more functions to the dll? (ie: direct support for HV's)

Code:

Perl_Module=0

perlinit()
{
   global Perl_Module
   Perl_Module := DLLCall("LoadLibrary","str","perlahk.dll","UInt")
   DllCall("perlahk\PerlInit","int",0)
}

perlexit()
{
   global Perl_Module
   DllCall("perlahk\PerlExit")
   DllCall("FreeLibrary","UInt",PERL_Module)
}

; run some perl code
perl(code) {
   DllCall("perlahk\PerlEval","str",code)
}

; here string is a variable defined using VarSetCapacity
perlstr(name,ByRef string)
{
   DllCall("perlahk\PerlGetStr","str",name,"str",string)
}

; get an integer
perlint(name)
{
   return DllCall("perlahk\PerlGetInt","str",name)
}


CreateMap(mapname)
{
   perl("%" . mapname . " = ();")
}

Clearmap(mapname)
{
   CreateMap(mapname)
}

Fetch(mapname,key)
{
   perl("$courier = $" . mapname . "{" . key . "};")
   perl("$package_size = length($courier);")
   size := perlint("package_size")
   VarSetCapacity(str,size + 5)
   perlstr("courier",str)
   return str
}

; this assumes string doesn't contain a ' char as it is used as a delimiter
; find a better solution
Store(mapname,key,value)
{
   perl("$" . mapname . "{" . key . "} = '" . value . "';")
}

;----------------------------------

/*
CreateMap(mapname)
Fetch(mapname,key)
Store(mapname,key,value)
Clearmap(mapname)
*/

perlinit()

CreateMap("skivvy")
Store("skivvy","Murray","Red")
Store("skivvy","Anthony","Blue")
Store("skivvy","Greg","Yellow")
Store("skivvy","Geoff","Purple")

Skivy_Color := Fetch("skivvy","Greg")

msgbox Greg wears a %Skivy_Color% skivvy

perlexit()
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Sat Jun 17, 2006 4:26 am    Post subject: Reply with quote

Nice-looking data structure and presentation. This should help others with some of the AHK limitations you mentioned.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group