Page 1 of 1

Thread.ahkgetvar and method calls

Posted: 15 Dec 2017, 18:24
by nnnik
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

Thread := AhkThread()
Msgbox incoming crash
Thread.ahkgetvar._NewEnum()
Msgbox crashed
Is this by design or rather just a bug?

Re: Thread.ahkgetvar and method calls

Posted: 16 Dec 2017, 02:53
by Helgef
An exception on invalid usage would be more appropriate. In v2 you could use type() to avoid it.

Re: Thread.ahkgetvar and method calls

Posted: 16 Dec 2017, 03:20
by nnnik
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.

Re: Thread.ahkgetvar and method calls

Posted: 16 Dec 2017, 03:35
by Helgef
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 ;)

Re: Thread.ahkgetvar and method calls

Posted: 16 Dec 2017, 04:13
by nnnik
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.

Re: Thread.ahkgetvar and method calls

Posted: 16 Dec 2017, 06:34
by Helgef
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.

Re: Thread.ahkgetvar and method calls

Posted: 16 Dec 2017, 16:44
by nnnik
Good one I missed it

Re: Thread.ahkgetvar and method calls

Posted: 16 Dec 2017, 19:29
by HotKeyIt
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.

Re: Thread.ahkgetvar and method calls

Posted: 17 Dec 2017, 06:08
by nnnik
Thanks for the quick fix