Browse Source

Add more dynarray iteration functions

windows-imgui
Macoy Madson 9 months ago
parent
commit
21e172b732
  1. 27
      src/DynamicArray.cake

27
src/DynamicArray.cake

@ -43,6 +43,25 @@
(token-splice-rest body tokens)))
(return true))
(defmacro each-item-in-dynarray (dynarray any index-name symbol
item-name symbol item-type any
&rest body any)
(tokenize-push output
(each-in-dynarray (token-splice dynarray) (token-splice index-name)
(var (token-splice item-name item-type) (at (token-splice index-name dynarray)))
(token-splice-rest body tokens)))
(return true))
(defmacro each-item-addr-in-dynarray (dynarray any index-name symbol
item-name symbol ptr-to-item-type any
&rest body any)
(tokenize-push output
(each-in-dynarray (token-splice dynarray) (token-splice index-name)
(var (token-splice item-name ptr-to-item-type)
(addr (at (token-splice index-name dynarray))))
(token-splice-rest body tokens)))
(return true))
(defmacro dynarray-length-sizeof (dynarray any)
(tokenize-push output
(* (dynarray-length (token-splice dynarray))
@ -151,12 +170,16 @@
(fprintf stderr "\nDelete swap:\n")
(dynarray-delete-swap my-dynarray 1)
(each-in-dynarray my-dynarray i (fprintf stderr "%d " (at i my-dynarray)))
(each-item-in-dynarray my-dynarray i current-int int (fprintf stderr "%d " current-int))
(fprintf stderr "\nItems with addresses:\n")
(each-item-addr-in-dynarray my-dynarray i current-int (* int)
(fprintf stderr "%d %p\n" (deref current-int) current-int))
(fprintf stderr "\nCapacity after all that: %d\n"
(type-cast (dynarray-capacity my-dynarray) int))
(fprintf stderr "Size of array: %d\n" (dynarray-length-sizeof my-dynarray))
(fprintf stderr "Size of array: %d\n" (type-cast (dynarray-length-sizeof my-dynarray) int))
(dynarray-free my-dynarray)
(return 0))

Loading…
Cancel
Save