Basing on Vexorians location stack (which I did not get to work...) I tried to write a list...
As it is little surprise, this one does not work, too...
If someone enjoys to seek for mistakes, whose kind he does not even know, this should be a piece of special cake for him.
A list is defined by it's head element.
So to "create" a list, you need to create a location and store data (for example a dummy real) in it's X-coordinate. Then the function "List_Add" can be used with the variable pointing on this location to create a list.
... Yet it is not possible to remove the head without destroying the whole list.
So dummy data in the first element is a good idea.
The common functions for type casting:
The functions for movement inside the list...
Way is defined as from head to foot (LIFO):
The functions to insert/extract/remove data:
As it is little surprise, this one does not work, too...
If someone enjoys to seek for mistakes, whose kind he does not even know, this should be a piece of special cake for him.
A list is defined by it's head element.
So to "create" a list, you need to create a location and store data (for example a dummy real) in it's X-coordinate. Then the function "List_Add" can be used with the variable pointing on this location to create a list.
... Yet it is not possible to remove the head without destroying the whole list.
So dummy data in the first element is a good idea.
The common functions for type casting:
JASS:
function R2E takes real r returns effect
return r
return null
endfunction
function R2Loc takes real r returns lightning
return r
return null
endfunction
function R2U takes real r returns unit
return r
return null
endfunction
function H2R takes handle h returns real
return h
return 0.
endfunction
The functions for movement inside the list...
Way is defined as from head to foot (LIFO):
JASS:
function List_NextElement takes location l returns location
return R2Loc(GetLocationY(l))
endfunction
function List_LastElement takes location l returns location
local location element = l
if l != null then
loop
exitwhen List_NextElement(element) == null
set element = List_NextElement(element)
endloop
endif
return element
endfunction
The functions to insert/extract/remove data:
JASS:
function List_Add takes location l,real i returns nothing
local location element
if l == null then
set l = Location(i,0)
else
set element = l
loop
exitwhen List_NextElement(element) == null
set element = List_NextElement(element)
endloop
call MoveLocation(element,GetLocationX(element),H2R(Location(i,0)))
endif
set element = null
endfunction
function List_Remove takes location l,location toRemove returns nothing
local location element
if l != null then
set element = l
if element != toRemove then
loop
exitwhen List_NextElement(element) == toRemove or List_NextElement(element) == null
set element = List_NextElement(element)
endloop
if List_NextElement(element) != null then
call MoveLocation(element,GetLocationX(element),H2R(List_NextElement(List_NextElement(element))))
endif
endif
endif
set element = null
endfunction
function List_Destroy takes location l returns nothing
local location element
if l != null then
loop
exitwhen List_NextElement(l) == null
set element = l
loop
exitwhen List_NextElement(List_NextElement(element)) == null
set element = List_NextElement(element)
endloop
call RemoveLocation(List_NextElement(element))
call MoveLocation(element,GetLocationX(element),0)
endloop
call RemoveLocation(l)
endif
set element = null
set l = null
endfunction