nojanath / SublimeKSP

Fork of Nils Liberg's SublimeKSP plugin. See README for details.
GNU General Public License v3.0
86 stars 18 forks source link

Overloaded macros #374

Closed JackWilliams-FractureSounds closed 1 year ago

JackWilliams-FractureSounds commented 1 year ago

Allows for different macros to be called depending on the number of arguments. When macros are being expanded they are temporarily renamed with "__[num-args]".

Will cause an 'duplicate macro' error if the new name matches a pre-existing macro.

For example:

on init
    test_macro()
    test_macro(a,b,c)
end on
macro test_macro
    message("macro with 0 arguments")
end macro
macro test_macro(#name#, #x#, #y#)
    message("macro with 3 arguments")
end macro

\/ Goes to...

on init
    test_macro__0()
    test_macro__3(a,b,c)
end on
macro test_macro__0
    message("macro with 0 arguments")
end macro
macro test_macro__3(#name#, #x#, #y#)
    message("macro with 3 arguments")
end macro

\/ Expands to...

on init
  message("macro with 0 arguments")
  message("macro with 3 arguments")
end on