Oxygen Basic

Information => Reference => Topic started by: Brian Alvarez on February 08, 2021, 01:48:15 PM

Title: Macro parameter question
Post by: Brian Alvarez on February 08, 2021, 01:48:15 PM
 Hello, I would like a macro to generate a certain block of code only if one of the passed parameters is not a literal null. What  can i use to achieve this safely?

 Right now i am using:

Code: [Select]
#if typecodeof(p) <> 0

#endif

 Is this safe? is there a better way? Is it possible?
Title: Re: Macro parameter question
Post by: Charles Pegge on February 09, 2021, 05:04:24 AM
Hi Brian,

Typecodeof will work for null, literals and variables but not for parameters consisting of expressions and functions.

Title: Re: Macro parameter question
Post by: Brian Alvarez on February 09, 2021, 09:51:25 AM

 I see. Does Typecodeof(null) return 0?
Title: Re: Macro parameter question
Post by: Charles Pegge on February 09, 2021, 10:19:54 AM
Yes, but this might be a better option. I am tweaking the match metafunction to support expressions as well as single words:

Code: [Select]
macro mf(p)
#if not match((p),(null))
   print "not null"
#else
   print "null"
#endif
end macro

mf null
mf 0
mf 1/4

Title: Re: Macro parameter question
Post by: Brian Alvarez on February 09, 2021, 11:05:11 AM
 Thanks Charles, i will implement it. :)