Refactored parse_signature
Hi fiddle developers.
This is just an idea. A proposal to improve the parse_signature method.
Background: I wanted to parse_signature recursively when the argument was a function (i.e. a function pointer). When I wrote a monkey patch for it, I noticed that parse_signature was unnecessarily complicated.
- Line 114 and line 117 are almost the same code.
- Each line is unnecessarily long.
- Some variable names are confusing.
- Also, the variables $1, $2, etc. looks old-fashioned.
2 - 4 are more of a library-wide issue, and are my personal opinions rather than objective facts. Each library has its own history.
Here, I am focusing on 1.
If you think the pull request is not good, just close it.
Thank you.
Hey, wait a minute. I think I made a mistake.
You modified the regular expressions, from \* to *.
Also, you are calling an extra parse_ctype(ret, tymap) instead of just TYPE_VOIDP.
Probably better to keep such call inside the case statement: [parse_ctype($1.strip, tymap), $2, $3].
Fixed. @Maumagnaguagno I appreciate the help.
I guess you need to propagate tymap to parse_ctype to avoid creating a new Hash in tymap ||= {}.
Yes, I think you're right. But this is the first time I've sent a PR to Fiddle. I think I'll leave it as is and see what the project owner has to say about it...
Anyway, thank you again.
I went back to work on the monkey patch one more time, but it wouldn't work without passing the tymap :facepalm:
I have to fix it. Maybe we should add a test for typealias...
I wanted to parse_signature recursively when the argument was a function (i.e. a function pointer).
Could you show a signature you want to parse?
An example: void uiSpinboxOnChanged(uiSpinbox *s, void (*f)(uiSpinbox *s, void *data), void *data)
Yes, thanks.
I would like to create a customized method. When you pass a block to that method, it will create a Fidle::Closure::BlockCaller with the appropriate type. To do this, each function needs to know the type information beforehand.
Idea:
We use [TYPE, SIZE] for sized array type. e.g.: [Fiddle::TYPE_CHAR, 80] for char x[80]
It may be a good idea that we use [Fiddle::TYPE_VOIDP, RETURN_TYPE, [ARGUMENT_TYPE, ...]] for function pointer. e.g.: [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOID, [Fiddle::TYPE_VOIDP, Fiddle::Type_VOIDP]] for void (*f)(uiSpinbox *s, void *data)