GLBasic forum

Feature request => IDE/Syntax => Topic started by: Quentin on 2009-May-10

Title: Macros
Post by: Quentin on 2009-May-10
... could be a nice thing to make code easier to read. (especially for INLINE snippets)

Code (glbasic) Select

MACRO newcommand(var)
    INLINE
        var++;
        ...
    ENDINLINE
ENDMACRO


// use in GLBasic code
LOCAL counter%
newcommand(counter)
Title: Re: Macros
Post by: Schranz0r on 2009-May-10
FUNCTION can do the same...

EDIT:

Code (glbasic) Select
LOCAL my_var = 10
Add(my_var)

WHILE TRUE

PRINT my_var,10,10

SHOWSCREEN
WEND
END



FUNCTION Add: BYREF var
INLINE
var++;
ENDINLINE
ENDFUNCTION
Title: Re: Macros
Post by: Quentin on 2009-May-10
sure, but FUNCTION always does have overhead (calling, stack, ...)
Macro is a simple replacement of code, so produces bigger, but faster code.
Title: Re: Macros
Post by: Kitty Hello on 2009-May-11
macros are not type safe. I would have to run a pre-pre-compiler for the macros. A nice idea, though.
Title: Re: Macros
Post by: FutureCow on 2009-May-30
What about platform specific macros? That way you could do something like

if for iphone
  resolution = 100x200
else
  resolution = 800x600
endif