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

Fixed l/iterate macros from preventing compiling from cmdline #368

Closed JackWilliams-FractureSounds closed 1 year ago

JackWilliams-FractureSounds commented 1 year ago

Placeholders could not be accessed and so could not return the generated macro iterations. PR makes placeholders accessed by reference

Test code:

{#pragma save_compiled_source ../output.txt}
define SEQUENCER.PAR(#param#) := seq_store[SEQ_PARAM.#param#]

on init
    define NUM_MACROS := 1

    declare !sign[3]
    sign[0] := "-"
    sign[2] := "+"

    const SEQ_PARAM
        iterate_macro(MACRO_#n#_AMOUNT := #n#) := 1 to NUM_MACROS
    end const

    declare seq_store[NUM_MACROS]

    iterate_macro(declare ui_slider SeqMacro#n#Amt (-1000, 1000)) := 1 to NUM_MACROS
    iterate_macro(SeqMacro#n#Amt -> label := sign[math.is_greater(SEQUENCER.PAR(MACRO_#n#_AMOUNT), -1)] & ...
                                             abs(SEQUENCER.PAR(MACRO_#n#_AMOUNT) / 10) & "." & ...
                                             abs(SEQUENCER.PAR(MACRO_#n#_AMOUNT) mod 10) & " %") := 1 to NUM_MACROS
end on

function math.is_greater(a, b) -> return
    return := -sh_right(b - a, 31)
end function