Skip to content

Commit

Permalink
NewRobot is now a variadic function
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Jun 13, 2014
1 parent d05c26e commit 326283c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,31 @@ func (r Robots) Each(f func(*Robot)) {
}
}

func NewRobot(name string, c []Connection, d []Device, work func()) *Robot {
func NewRobot(name string, v ...interface{}) *Robot {
r := &Robot{
Name: name,
Work: work,
Commands: make(map[string]func(map[string]interface{}) interface{}),
}
r.initName()
log.Println("Initializing Robot", r.Name, "...")
r.initConnections(c)
r.initDevices(d)
if len(v) > 0 {
if v[0] == nil {
v[0] = []Connection{}
}
r.initConnections(v[0].([]Connection))
}
if len(v) > 1 {
if v[1] == nil {
v[1] = []Device{}
}
r.initDevices(v[1].([]Device))
}
if len(v) > 2 {
if v[2] == nil {
v[2] = func() {}
}
r.Work = v[2].(func())
}
return r
}

Expand Down

0 comments on commit 326283c

Please sign in to comment.