|
![](/i/fill.gif) |
clipka wrote:
> You *can* write a macro this way:
>
> #macro myMacro(p1,p2)
> #if (p2 > 0)
> #declare this = sphere { p1, p2 }
> #else
> // nothing
> #end
> #end
You can also get rid of the reference to the global
variable name from within the macro by using the more
cumbersome:
#macro myMacro(p1,p2,outobjcreated,outobj)
#if (p2 > 0)
#local outobjcreated = true;
#local outobj = sphere { p1, p2 }
#else
#local outobjcreated = false;
#end
#end
// Need to be initialized, value irrelevant
#declare myoutobjcreated = false;
#declare myoutobj = false;
myMacro(<0,0,0>, -1, myoutobjcreated, myoutobj)
#if (myoutobjcreated)
#debug "Object myoutobj is ready for use"
#else
#debug "No object created"
#end
I'm still puzzling whether one could get rid of the myobjcreated
variable. I tried assigning "false" to myoutobj but I don't know
of any way to test whether a variable contains a float or an object,
and #if will raise an error if it is an object. I also tried
"#undeffing" outobj but that seems to only undef the local
variable name outobj, not the passed variable. Makes sense
in a general way but not so much with the output semantics
for variables passed to macro parameters: If I can change
the value of the passed variable, I should also be able
to reset it to some kind of null reference.
Post a reply to this message
|
![](/i/fill.gif) |