Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
My Rhythmic Crotch
Jan 13, 2011

I have been looking for a new language to try, and I'm on Go now after trying D. I'm stuck on this bit of code:
code:
package main

import "fmt"
import "reflect"

type Master struct {}

func (master *Master) Execute(i int, j int) {
	fmt.Println("did something")
}

func Invoke(any interface{}, name string, args... interface{}) {

	inputs := make([]reflect.Value, len(args))
	for i, param := range args {
		inputs[i] = reflect.ValueOf(param)
		fmt.Println(param)
	}
	
	reflect.ValueOf(any).MethodByName(name).Call(inputs)
}

func main() {
	Invoke(Master{}, "Execute", 1, 2)
}
It panics like so:
code:
panic: reflect: call of reflect.Value.Call on zero Value
But I don't understand why. It seems to be building the list of inputs to pass to Call, so I don't understand why it thinks the inputs are a "zero Value" :raise:

Adbot
ADBOT LOVES YOU

My Rhythmic Crotch
Jan 13, 2011

Wow, nice catch. Thanks for that.

My Rhythmic Crotch
Jan 13, 2011

Another oddity: http://play.golang.org/p/BMtgxj-0Af

Unmarshaling any number always gives me a float64 :raise:

Is there a way to force encoding/decoding an integer? I'm reading the json encoder but not seeing it.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply