Procedure - Integer arguments stored in a local array
Posted: Mon Jun 08, 2020 3:01 pm
From the idea of FlatEarth :
; '____' 4 characters code to store the arguments of a procedure in a local array.
; array name is Arg()
; be careful to ArgCount which has been defined as a local integer
; -9223372036854775808 for X64
; 2147483648 for X86
; this is a reserved argument value
; only for integers and pointors
; 16 arguments maximum : you can expand this availability. Please request if needed.
; Good luck !
; '____' 4 characters code to store the arguments of a procedure in a local array.
; array name is Arg()
; be careful to ArgCount which has been defined as a local integer
; -9223372036854775808 for X64
; 2147483648 for X86
; this is a reserved argument value
; only for integers and pointors
; 16 arguments maximum : you can expand this availability. Please request if needed.
; Good luck !
Code: Select all
;*************************************************************************************
; from the idea of FlatEarth
;
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
#None = 1 << 31
CompilerElse
#None = 1 << 63
CompilerEndIf
Macro Ar_
Argument# MacroExpandedCount = #None
EndMacro
Macro ____
Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_)
Protected ArgCount.I
For ArgCount = 0 To 15
If PeekI(@Argument1 + ArgCount * SizeOf(Integer) ) = #None
Break
EndIf
Next
Dim Arg.I(ArgCount)
Arg(0) = ArgCount
For ArgCount = 1 To Arg(0)
Arg(ArgCount) = PeekI(@Argument1 + (ArgCount - 1) * SizeOf(Integer) )
Next
ArgCount ! (0
EndMacro
;- Syntax example
Procedure Test(____)
For I = 1 To Arg(0)
Debug Arg(I)
Next
EndProcedure
Test(1,2,5,10,20) ; <--- add up to 16 arguments