Skip to content

Instantly share code, notes, and snippets.

@tinku99
Created November 6, 2011 04:56
Show Gist options
  • Select an option

  • Save tinku99/1342493 to your computer and use it in GitHub Desktop.

Select an option

Save tinku99/1342493 to your computer and use it in GitHub Desktop.
convert between autohotkey objects and safearrays (comobjarray)
/*
Author: Naveen Garg
license: GPL v2
*/
testahkobj2comarray:
o := {a: 4, b: 5}
a := ahkobj2comarray(o)
o2 := comarray2ahkobj(a)
if (tostring(o) != tostring(o2))
msgbox error
msgbox % "o: `n" tostring(o)
msgbox % "o2: `n" tostring(o2)
return
ahkobj2comarray(o){
for k, v in o
{
n := A_Index
}
arr := ComObjArray(VT_VARIANT:=12, n, 2)
for k, v in o
{
if IsObject(k) or Isobject(v)
{
throw "error objects not allowed"
}
arr[A_Index - 1, 0] := k
arr[A_Index - 1, 1] := v
}
return arr
}
comarray2ahkobj(arr){
o := object()
n := arr.MaxIndex(1)
loop % n + 1
{
o[arr[A_Index - 1, 0]] := arr[A_Index - 1, 1]
}
return o
}
#include tostring.ahk
/*
Author: IsNull
http://www.autohotkey.com/forum/topic59244.html
license: not specified
default license for forum where initially posted:GPL v2
*/
ToString(this){
if(!IsObject(this))
return, this
str := ""
fields := this._NewEnum()
while fields[k, v]
{
if(!IsObject(v)){
str .= !IsFunc(v) ? "[" k "] := " v "`n" : k "() calls " v "`n"
}else{
subobje := ToString(v)
str .= "[" k "]<ob>`n" _multab(subobje)
}
}
return, str
}
_multab(str){
Loop, parse, str, `n, `r
newstr .= A_Tab A_LoopField "`n"
return, newstr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment