# file opened: lua_macro_arg2.asm
 1    0000                  ; test the new way of lua `_c`/`sj.calc` function to do the define/macro_arg
 2    0000                  ; substitution before the expression is evaluated, so using macro arguments
 3    0000                  ; inside lua script should be now trivial, no more workaround through DEFINE.
 4    0000
 5    0000                  ; this example has been reworked to conform to updated lua5.4 and only official
 6    0000                  ; documented Lua bindings, the `sj.insert_label` has no more the optional arguments
 7    0000                  ; that said, you can use instead the regular asm syntax and `_pl` binding to create
 8    0000                  ; any kind of special flavour of label (DEFL, EQU, global, local, ...)
 9    0000
10    0000                  ; The extra options of `sj.insert_label` were promised to stay in v1.x
11    0000                  ; in the original test code, unless there is serious reason. Upgrade
12    0000                  ; to lua 5.4 is actually *that* serious reason, sorry.
13    0000
14    0000                  ; OBSOLETE by v1.20.0: now sj.get_define get search also macro arguments
15    0000                  MACRO testM arg1?
16    0000 ~                    LUA ALLPASS
17    0000 ~                        x = _c("arg1?")     -- get value of evaluated macro argument
18    0000 ~                        -- if you want macro argument without evaluation or string value, use sj.get_define
19    0000 ~                        assert(x == 0+sj.get_define("arg1?", true)) -- enabling macro-arg search with second option
20    0000 ~                        _pl("!x = "..x)         -- DEFL type label "x" set to value x
21    0000 ~                        _pc("dw arg1?, x, "..x) -- check all three sources of input value
22    0000 ~                            -- _pc does it's own substitution, the label "x" should be set and lua "x"
23    0000 ~                        -- test _c a bit more for handling weird things...
24    0000 ~                        e1 = _c("/* ehm")
25    0000 ~                        e2 = _c("define arg1? xx")  -- will emit error "Label not found: define" = OK
26    0000 ~                        e3 = _c("$FF&".._c("arg1?"))
27    0000 ~                        _pc("db /* e1, e2, e3 */ "..e1..","..e2..","..e3)
28    0000 ~                    ENDLUA
29    0000 ~            .localMacroLabel:   ; check which root the macro local label gets (should be per emit)
30    0000                  ENDM
31    0000
32    0000              x   = 88
33    0000              BigLabel1:
34    0000                  testM 0x1234
34    0000             >        LUA ALLPASS
34    0000 ~           >            x = _c("arg1?")     -- get value of evaluated macro argument
34    0000 ~           >            -- if you want macro argument without evaluation or string value, use sj.get_define
34    0000 ~           >            assert(x == 0+sj.get_define("arg1?", true)) -- enabling macro-arg search with second option
34    0000 ~           >            _pl("!x = "..x)         -- DEFL type label "x" set to value x
34    0000 ~           >            _pc("dw arg1?, x, "..x) -- check all three sources of input value
34    0000 ~           >                -- _pc does it's own substitution, the label "x" should be set and lua "x"
34    0000 ~           >            -- test _c a bit more for handling weird things...
34    0000 ~           >            e1 = _c("/* ehm")
34    0000 ~           >            e2 = _c("define arg1? xx")  -- will emit error "Label not found: define" = OK
34    0000 ~           >            e3 = _c("$FF&".._c("arg1?"))
34    0000 ~           >            _pc("db /* e1, e2, e3 */ "..e1..","..e2..","..e3)
34    0000             >!x = 4660
34    0000 34 12 34 12 >dw 0x1234, x, 4660
34    0004 34 12       >
lua_macro_arg2.asm(25): error: [LUA] Label not found: define
lua_macro_arg2.asm(34): ^ emitted from here
34    0006 00 00 34    >db   0,0,52
34    0009             >        ENDLUA
34    0009             >.localMacroLabel:   ; check which root the macro local label gets (should be per emit)
35    0009              .local1:
36    0009 34 12            DW  x                       ; check that symbol "x" was set by _pl("!x = "..x)
37    000B 18 FC            jr      BigLabel1.local1    ; check "big" label was not modified by _pl("!x = "..x)
38    000D              x   = 77
39    000D              BigLabel2:
40    000D                  testM 0x3456
40    000D             >        LUA ALLPASS
40    000D ~           >            x = _c("arg1?")     -- get value of evaluated macro argument
40    000D ~           >            -- if you want macro argument without evaluation or string value, use sj.get_define
40    000D ~           >            assert(x == 0+sj.get_define("arg1?", true)) -- enabling macro-arg search with second option
40    000D ~           >            _pl("!x = "..x)         -- DEFL type label "x" set to value x
40    000D ~           >            _pc("dw arg1?, x, "..x) -- check all three sources of input value
40    000D ~           >                -- _pc does it's own substitution, the label "x" should be set and lua "x"
40    000D ~           >            -- test _c a bit more for handling weird things...
40    000D ~           >            e1 = _c("/* ehm")
40    000D ~           >            e2 = _c("define arg1? xx")  -- will emit error "Label not found: define" = OK
40    000D ~           >            e3 = _c("$FF&".._c("arg1?"))
40    000D ~           >            _pc("db /* e1, e2, e3 */ "..e1..","..e2..","..e3)
40    000D             >!x = 13398
40    000D 56 34 56 34 >dw 0x3456, x, 13398
40    0011 56 34       >
lua_macro_arg2.asm(25): error: [LUA] Label not found: define
lua_macro_arg2.asm(40): ^ emitted from here
40    0013 00 00 56    >db   0,0,86
40    0016             >        ENDLUA
40    0016             >.localMacroLabel:   ; check which root the macro local label gets (should be per emit)
41    0016              .local2:
42    0016 56 34            DW  x
43    0018 18 FC            jr      BigLabel2.local2    ; same checks as above, but second value
44    001A
# file closed: lua_macro_arg2.asm

Value    Label
------ - -----------------------------------------------------------
0x0009 X 0>localMacroLabel
0x0016 X 1>localMacroLabel
0x0000 X BigLabel1
0x0009   BigLabel1.local1
0x000D X BigLabel2
0x0016   BigLabel2.local2
0x3456   x
