April 18, 2024, 07:42:20 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Clearing local variables.

Started by Ionic Wind Support Team, November 27, 2006, 08:29:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ionic Wind Support Team

Original post by Fletchie on the Pyxia forums.  Works in Emergence:
---------------------------------------------------------------------------------------------

The following function CL() - automatically clears/resets all local variables/strings/types in a subroutine to zero.

Call just after the 'defs' for the variables.

Can be useful if you have a lot of vars - and you need to make sure they're zero.

Don't use outside of a subroutine !!


type test
   def a:int
   def b:uint64
   def c:double
   def d:string
   def e:int
endtype
declare CL()
TestClear(1,2)
do:until inkey$<>""
end
'---------------------------------------------------
sub TestClear(a:int,b:int)
def var1:int
def var2:double
def var3:char
def t:test
   'Comment out CL() to see the difference...
   CL()
   print var1
   print var2
   print var3+0
   print t.a
   print t.b
   print t.c
   print len(t.d)
   print t.e
   return
endsub
'---------------------------------------------------
CL:
_asm
mov eax,esp            ; transfer esp to eax
add eax,16            ; add 16, skips the pushed EIP, esi,edi,ebx
xor edx,edx            ; Sets edx to zero
loopcl:
cmp eax,ebp            ; if eax equals ebp - we're done
je fincl
mov dword [eax],edx   ; clear 4 bytes
add eax,4
jmp loopcl            ; go-again
fincl:
ret
_endasm

Ionic Wind Support Team