示例#1
0
文件: ops.go 项目: jeremiah/go-xslate
func txFetchArrayElement(st *State) {
	defer st.Advance()

	array := reflect.ValueOf(st.StackPop())
	switch array.Kind() {
	case reflect.Array, reflect.Slice:
	default:
		st.Warnf("cannot index into non-array/slice element")
		return
	}

	idx := st.StackPop()
	v := array.Index(int(idx.(int64)))
	st.sa = v.Interface()
}
示例#2
0
文件: ops.go 项目: jeremiah/go-xslate
func txForStart(st *State) {
	array := reflect.ValueOf(st.sa)

	switch array.Kind() {
	case reflect.Array, reflect.Slice:
		// Normal case. nothing to do
	default:
		// Oh you silly goose. You didn't give me a array.
		// Use a dummy array
		array = reflect.ValueOf([]struct{}{})
	}

	cf := st.CurrentFrame()
	cf.SetLvar(0, nil) // item
	cf.SetLvar(1, NewLoopVar(-1, array))

	st.Advance()
}