nojanath / SublimeKSP

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

Macros containing callbacks with function calls inside are expanded within callback #372

Open JackWilliams-FractureSounds opened 1 year ago

JackWilliams-FractureSounds commented 1 year ago

For example, this compiles:

on init
  declare kccn
end on

function cc_notify   { invoke this from host's controller callback when using amode = 1 }
    kccn := CC_NUM   { latest CC that changed }
end function

on_cc_notify

macro on_cc_notify   { create controller callback and invoke cc_notify }
  on controller
    cc_notify
  end on
end macro

...But this doesn't:

on init
  declare kccn
end on

on_cc_notify

function cc_notify   { invoke this from host's controller callback when using amode = 1 }
    kccn := CC_NUM   { latest CC that changed }
end function

macro on_cc_notify   { create controller callback and invoke cc_notify }
  on controller
    cc_notify
  end on
end macro

The cc_notify function gets expanded within the on controller callback, which causes a syntax error

Compiled code:

on init
declare sksp_dummy
declare concat_it
declare concat_offset
declare string_it
declare list_it
declare preproc_i
  declare kccn
end on

  on controller
    cc_notify

function cc_notify   
    kccn := CC_NUM   
end function

  end on