Rev 539 | Blame | Compare with Previous | Last modification | View Log | Download
# file opened: lua_macro_arg2.asm1 0000 ; test the new way of lua `_c`/`sj.calc` function to do the define/macro_arg2 0000 ; substitution before the expression is evaluated, so using macro arguments3 0000 ; inside lua script should be now trivial, no more workaround through DEFINE.4 00005 0000 ; this example has been reworked to conform to updated lua5.4 and only official6 0000 ; documented Lua bindings, the `sj.insert_label` has no more the optional arguments7 0000 ; that said, you can use instead the regular asm syntax and `_pl` binding to create8 0000 ; any kind of special flavour of label (DEFL, EQU, global, local, ...)9 000010 0000 ; The extra options of `sj.insert_label` were promised to stay in v1.x11 0000 ; in the original test code, unless there is serious reason. Upgrade12 0000 ; to lua 5.4 is actually *that* serious reason, sorry.13 000014 0000 ; OBSOLETE by v1.20.0: now sj.get_define get search also macro arguments15 0000 MACRO testM arg1?16 0000 ~ LUA ALLPASS17 0000 ~ x = _c("arg1?") -- get value of evaluated macro argument18 0000 ~ -- if you want macro argument without evaluation or string value, use sj.get_define19 0000 ~ assert(x == 0+sj.get_define("arg1?", true)) -- enabling macro-arg search with second option20 0000 ~ _pl("!x = "..x) -- DEFL type label "x" set to value x21 0000 ~ _pc("dw arg1?, x, "..x) -- check all three sources of input value22 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" = OK26 0000 ~ e3 = _c("$FF&".._c("arg1?"))27 0000 ~ _pc("db /* e1, e2, e3 */ "..e1..","..e2..","..e3)28 0000 ~ ENDLUA29 0000 ~ .localMacroLabel: ; check which root the macro local label gets (should be per emit)30 0000 ENDM31 000032 0000 x = 8833 0000 BigLabel1:34 0000 testM 0x123434 0000 > LUA ALLPASS34 0000 ~ > x = _c("arg1?") -- get value of evaluated macro argument34 0000 ~ > -- if you want macro argument without evaluation or string value, use sj.get_define34 0000 ~ > assert(x == 0+sj.get_define("arg1?", true)) -- enabling macro-arg search with second option34 0000 ~ > _pl("!x = "..x) -- DEFL type label "x" set to value x34 0000 ~ > _pc("dw arg1?, x, "..x) -- check all three sources of input value34 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" = OK34 0000 ~ > e3 = _c("$FF&".._c("arg1?"))34 0000 ~ > _pc("db /* e1, e2, e3 */ "..e1..","..e2..","..e3)34 0000 >!x = 466034 0000 34 12 34 12 >dw 0x1234, x, 466034 0004 34 12 >lua_macro_arg2.asm(25): error: [LUA] Label not found: definelua_macro_arg2.asm(34): ^ emitted from here34 0006 00 00 34 >db 0,0,5234 0009 > ENDLUA34 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 = 7739 000D BigLabel2:40 000D testM 0x345640 000D > LUA ALLPASS40 000D ~ > x = _c("arg1?") -- get value of evaluated macro argument40 000D ~ > -- if you want macro argument without evaluation or string value, use sj.get_define40 000D ~ > assert(x == 0+sj.get_define("arg1?", true)) -- enabling macro-arg search with second option40 000D ~ > _pl("!x = "..x) -- DEFL type label "x" set to value x40 000D ~ > _pc("dw arg1?, x, "..x) -- check all three sources of input value40 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" = OK40 000D ~ > e3 = _c("$FF&".._c("arg1?"))40 000D ~ > _pc("db /* e1, e2, e3 */ "..e1..","..e2..","..e3)40 000D >!x = 1339840 000D 56 34 56 34 >dw 0x3456, x, 1339840 0011 56 34 >lua_macro_arg2.asm(25): error: [LUA] Label not found: definelua_macro_arg2.asm(40): ^ emitted from here40 0013 00 00 56 >db 0,0,8640 0016 > ENDLUA40 0016 >.localMacroLabel: ; check which root the macro local label gets (should be per emit)41 0016 .local2:42 0016 56 34 DW x43 0018 18 FC jr BigLabel2.local2 ; same checks as above, but second value44 001A# file closed: lua_macro_arg2.asmValue Label------ - -----------------------------------------------------------0x0009 X 0>localMacroLabel0x0016 X 1>localMacroLabel0x0000 X BigLabel10x0009 BigLabel1.local10x000D X BigLabel20x0016 BigLabel2.local20x3456 x