Page 4 of 4

Re: [Lib] ObjDump / ObjLoad - Object Backup

Posted: 25 Jul 2018, 15:56
by SAbboushi

Code: Select all

SendObject :=	{
                  x: 2
                }
                        
x:=objdump(sendObject)

Re: [Lib] ObjDump / ObjLoad - Object Backup

Posted: 25 Jul 2018, 15:58
by HotKeyIt
Should be size:=ObjDump(sendObject,variable)
Data will be saved in variable!
Are you using v1 or v2?

Re: [Lib] ObjDump / ObjLoad - Object Backup

Posted: 25 Jul 2018, 16:18
by SAbboushi
Sorry - my bad. Example that fails using AHK v2 and objdump.ahk for v2:

Code: Select all

SendObject :=	{
                  x: 2
                }
                        
size := objdump(sendObject, variable)

Re: [Lib] ObjDump / ObjLoad - Object Backup

Posted: 26 Jul 2018, 10:41
by SAbboushi
HotKeyIt: Are you getting the same error?

Re: [Lib] ObjDump / ObjLoad - Object Backup

Posted: 26 Jul 2018, 11:22
by burque505
@SAbboushi, when I run this code

Code: Select all

SendObject :=	{
                  x: 2
                }
                        
size := objdump(sendObject, variable)

msgbox("The variable is " . variable)

ExitApp
I get the value of the variable as a Unicode character the forum isn't printing. Are those your results too?
Capture.PNG
Capture.PNG (16.47 KiB) Viewed 3373 times
Regards,
burque505

Re: [Lib] ObjDump / ObjLoad - Object Backup

Posted: 26 Jul 2018, 13:57
by SAbboushi
Thanks for your efforts but no - I get the same error I posted earlier
Error in #include file "J:\StandaloneApps\AutoHotkeyV2\Lib\objdump.ahk":
Type mismatch.

Line#
046: objects[obj]:=1
047: For k,v in obj
048: {
049: if IsObject(k)
050: sz+=objects.HasKey(k)?9:RawObjectSize(k,buf,objects)+9
051: Else
051: if Type(k)="String"
---> 052: sz+=StrPut(k)*2+9
053: Else
053: sz+=InStr(k,".")||k>4294967295?9:k>65535?5:k>255?3:k>-129?2:k>-32769?3:k>-2147483649?5:9
054: if IsObject(v)
055: sz+=objects.HasKey(v)?9:RawObjectSize(v,buf,objects)+9
056: Else
056: if Type(v)="String"
057: sz+=(buf?obj.GetCapacity(k):StrPut(v)*2)+9

The current thread will exit.
sz is unitialized and the math operation throws an error. I started to update the code to make it compliant with latest version of AHK V2, but it's not the only line that needs correcting. And I started correcting the other 2 object serializers that seem to suffer similar problems - don't have the time to debug such compressed unfriendly code for my simple application.

If anyone knows of an object serializer/deserializer that works with latest version of AHK V2, please let me know.

Re: [Lib] ObjDump / ObjLoad - Object Backup

Posted: 28 Jul 2018, 09:20
by HotKeyIt
Should be fixed now:

Code: Select all

SendObject :=	{
                  x: 2
                }
                        
size := objdump(sendObject, variable)

msgbox("The size of dumped memory is " size " bytes")
obj:=ObjLoad(&variable)
MsgBox obj.x
ExitApp

Re: [Lib] ObjDump / ObjLoad - Object Backup

Posted: 12 Aug 2019, 10:55
by bourdin07
i'd like to dump a COM Object but the app crash

Code: Select all

objDump(A_ScriptDir "\test.bin", ComObjCreate("MSXML2.DOMDocument"))
It will be really nice.

It is possible and how?

Re: [Lib] ObjDump / ObjLoad - Object Backup

Posted: 12 Aug 2019, 11:03
by swagfag
no. this is meant for ahk arrays and objects

Re: [Lib] ObjDump / ObjLoad - Object Backup

Posted: 10 Mar 2023, 14:01
by AHK_user
I would love to see this converted to the current V2 syntax

Re: [Lib] ObjDump / ObjLoad - Object Backup

Posted: 21 Oct 2023, 05:12
by ananthuthilakan
a noob question : why use this method when we can convert objects into json and then file append ? can any body point out the pros and cons

Re: [Lib] ObjDump / ObjLoad - Object Backup

Posted: 21 Oct 2023, 06:29
by teadrinker
Not everything that AHK objects support also JSON supports. For example, an AHK object may contain a reference to itself, the object's key may be another object.