?login_element?

Subversion Repositories NedoOS

Rev

Rev 126 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

  1.     OUTPUT "checking_macro_args_within_lua.bin"
  2.  
  3.     ; define Lua functions rather only in PASS1, the Lua context is global across whole
  4.     ; assembling and across all passes, so just single pure function definition is enough.
  5.     LUA PASS1
  6.         function getMacroArgument(argname)
  7.             _pl(" DEFINE _LUA_GET_MACRO_ARGUMENT "..argname)
  8.             local result = sj.get_define("_LUA_GET_MACRO_ARGUMENT")
  9.             _pl(" UNDEFINE _LUA_GET_MACRO_ARGUMENT")
  10.             return result
  11.         end
  12.     ENDLUA
  13.  
  14.     ; macro using short Lua script, which does call the function above to figure out
  15.     ; the value of someArg0 within the Lua
  16.     MACRO someMacro someArg0
  17.         LUA ALLPASS
  18.             _pc(" db "..getMacroArgument("someArg0"))
  19.         ENDLUA
  20.     ENDM
  21.  
  22.     ; spawn the macro (should end as `db "ARG0_content"` final machine code.
  23.     someMacro "ARG0_content"
  24.  
  25. ;;-------------------------------------------------------------------------------
  26.     ; second example, with usage of LUA inside DUP-EDUP block (based on Issue #27)
  27.     LUA PASS1
  28.         AY8910_CLOCK_FREQUENCY=1000000
  29.         function getAyMidiFrequency(midiNumber)
  30.             return math.floor((AY8910_CLOCK_FREQUENCY/16.0)/(math.pow(2,(midiNumber-69)/12.0)*440)+0.5)
  31.         end
  32.     ENDLUA
  33.  
  34. midi_number=21
  35.     dup 108-21+1
  36.     LUA
  37.         _pc(' dw ' .. getAyMidiFrequency(sj.get_label("midi_number")))
  38.     ENDLUA
  39. midi_number=midi_number+1
  40.     edup
  41.