Skip to content

Instantly share code, notes, and snippets.

@me2beats
Created October 25, 2020 02:25
Show Gist options
  • Save me2beats/9787a2278aa325e31edbd5b7ddabb719 to your computer and use it in GitHub Desktop.
Save me2beats/9787a2278aa325e31edbd5b7ddabb719 to your computer and use it in GitHub Desktop.
test Godot custom iterators
class_name NodeWalk
extends StackIterator
func _init(node).(node):
pass
func _iter_(current):
for i in current.get_children():
stack.push_back(i)
class_name StackIterator
var stack = []
var current
func _init(node:Node):
stack.append(node)
func _iter():
current = stack.pop_back()
if current == null:
return false
_iter_(current)
return true
# override it
func _iter_(current):
pass
func _iter_init(_arg):
return _iter()
func _iter_next(_arg):
return _iter()
func _iter_get(_arg):
return current
@me2beats
Copy link
Author

me2beats commented Oct 25, 2020

Questions:

  1. What is _arg for?
  2. Why I need to write this weird thing in NodeWalk:
func _init(node).(node):
	pass

answers:

  1. ?
  2. If a class requires a constructor param, then the extending classes must explicitly declare what to pass to it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment