Page 1 of 1

templates and parameters

Posted: Fri Mar 11, 2016 1:47 am
by mwieder
I'm working on implementing an optional argument for the files() and folders() functions.
I've got things to the point where the parser will accept a parameter or not, and I'm returning the same result in each case.
So far so good.

But I'm stuck trying to implement the exec part of this. Both functions are currently implemented with a template that doesn't take arguments. I see a template for a variable number of math arguments, and I see one that requires a *lot* of rework of the affected functions and all I've been able to do when it finally compiles is throw a segment fault. I'm assuming I have to invoke get0or1parameters at some point, but it's looking like I'll have to create a new type of template for this situation, and that doesn't seem right.

So I'm going on the assumption that I'm missing something obvious, and maybe there's another function already doing this that I can use as a model.

I'm up for any ideas. I've had to modify seven files to get this far.

Re: templates and parameters

Posted: Fri Mar 11, 2016 5:41 pm
by LCMark
@mwieder: There isn't a template for functions which take 0 or 1 parameters... If you make MCTheFiles (and the folder variant) inherit from MCFunction again, just reinstate similar logic as is present in the MCMouse function class.

Re: templates and parameters

Posted: Fri Mar 11, 2016 5:49 pm
by LCMark
Btw - I take it you found that MCSystemInterface ListFolderEntries already supports a folder parameter - I believe @peter-b added that a while back, but we never got around to exposing it to script.

Re: templates and parameters

Posted: Fri Mar 11, 2016 7:39 pm
by mwieder
@LCMark - thanks, I'll poke around a bit more. Actually, the MCMouse class is what I was using as my model, since it can take an optional parameter, but I haven't yet found the secret key, since I just threw a segfault when I finally got code that compiled.

And no, I did *not* notice Peter-B's addition. I'll go dive in there.