MisterW
Joined: 20 Jul 2005 Posts: 65
|
Posted: Fri Jun 16, 2006 12:28 pm Post subject: Dictionary (Hash,Associative Array,map...) using perlahk |
|
|
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() |
|
|