Thread.ahkgetvar and method calls

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
User avatar
nnnik
Posts: 2967
Joined: 30 Sep 2013, 01:01
Location: Germany

Thread.ahkgetvar and method calls

15 Dec 2017, 18:24

I recently enhanced my display function - that turns an object into a string.
After sending it to RUNIE for testing he complained that his script breaks when he uses it on a specific object.
After some debugging I found out that AHK_H exits when I use a for loop on a Thread Object, more specifically when using a for-loop to access the .ahkgetvar field of the thread.
This is the code that makes AHK_H crash:

Code: [Select all] [Download] GeSHi © Codebox Plus

Thread := AhkThread()
Msgbox incoming crash
Thread.ahkgetvar._NewEnum()
Msgbox crashed

Is this by design or rather just a bug?
Recommends AHK Studio
Helgef
Posts: 3033
Joined: 17 Jul 2016, 01:02
Contact:

Re: Thread.ahkgetvar and method calls

16 Dec 2017, 02:53

An exception on invalid usage would be more appropriate. In v2 you could use type() to avoid it.
User avatar
nnnik
Posts: 2967
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Thread.ahkgetvar and method calls

16 Dec 2017, 03:20

Well I can't add exceptions for each and every type of object that doesn't support _NewEnum.
In my opinion every object should support _NewEnum - it's a standard action that every object should support, at least every built in object.
Recommends AHK Studio
Helgef
Posts: 3033
Joined: 17 Jul 2016, 01:02
Contact:

Re: Thread.ahkgetvar and method calls

16 Dec 2017, 03:35

No, I mean ahk should throw, not you. I guess in v1 it should silently fail instead :think: . V2 throws when trying to call non existent methods, just as v1 throws on non existent functions. Not having newenum is the more usual case ;)
User avatar
nnnik
Posts: 2967
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Thread.ahkgetvar and method calls

16 Dec 2017, 04:13

Hmm yeah though Objects without _NewEnum probably only make up a really, really small fraction of all object instances - the types often don't have _NewEnum themselves.
In AHK_L:
  • AccociativeArray : true ( makes up 70% of all my instances ) ( I divided class into associative array and FuncObjects )
  • FuncObject : false ( makes up 25% of my code ( all the methods are essentially func objects ) )
  • FileObject : false ( makes up <1% of my instances )
  • BoundFuncs : false ( makes up ~1% of my instances )
  • Com : implementation specific ( makes up 2-3% of my instances )
I should probably use a try statement to catch stuff like this - though this would only help after this gets fixed.
Recommends AHK Studio
Helgef
Posts: 3033
Joined: 17 Jul 2016, 01:02
Contact:

Re: Thread.ahkgetvar and method calls

16 Dec 2017, 06:34

First, I see I misread your previous post, you didn't suggest you would throw any exceptions, sorry.
In AHK_L:

Indeed I meant in AHK_L, I don't know about all objects in AHK_H. And yeah, most instances probably has _newenum. In addition to your list, RegExMatch objects, doesn't have _newenum.

Finally, it seems that v2 also silently fails when trying to use a for loop with an object which doesn't support it, I think that is a mistake, it should be handled with try if desired, otherwise it should be assumed to be a mistake, and one should be notified. For example, funcObj._newEnum() causes an exception, but not for k in funcObj. Note, should refers only to my opinion, it is debatable of course.

Cheers.
User avatar
nnnik
Posts: 2967
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Thread.ahkgetvar and method calls

16 Dec 2017, 16:44

Good one I missed it
Recommends AHK Studio
HotKeyIt
Posts: 1649
Joined: 29 Sep 2013, 18:35
Contact:

Re: Thread.ahkgetvar and method calls

16 Dec 2017, 19:29

That should be fixed now.
When calling a DynaCall object you can specify a different return type then previously defined, e.g. Thread.ahkgetvar.ptr("var"), now calling Thread.ahkgetvar._NewEnum() or for loop will result in error.
User avatar
nnnik
Posts: 2967
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Thread.ahkgetvar and method calls

17 Dec 2017, 06:08

Thanks for the quick fix
Recommends AHK Studio

Return to “AutoHotkey_H”

Who is online

Users browsing this forum: No registered users and 3 guests