/* }}} */
/* GopherLua original APIs {{{ */
// ToStringMeta returns string representation of given LValue.
// This method calls the `__tostring` meta method if defined.
429194
func (ls *LState) ToStringMeta(lv LValue) LValue {
	if fn, ok := ls.metaOp1(lv, "__tostring").assertFunction(); ok {
		ls.Push(fn)
		ls.Push(lv)
		ls.Call(1, 1)
		return ls.reg.Pop()
	} else {
		return LString(lv.String())
	}
}
909934
func ValueToString(val Value) (string, bool) {
	if val == nil || val.Err() {
		return "", false
	}
	switch v := val.(type) {
	case StringValue:
		return v.Val(), true
	case TimeValue:
		return fmt.Sprintf("%v", v.Val()), true
	case ByteSliceValue:
		return string(v.Val()), true
	case NumericValue, BoolValue, IntValue:
		return val.ToString(), true
	case Slice:
		// This is controversial, if we are demanding a "ToString"
		// should we:
		// 1)  take first?
		// 2)  append comma separated?
		// 3)  error?
		//
		// Our answer is that we are demanding a scalar string
		// and going to take first.  calling function would have had to do type detection
		// if they wanted something else.
		if v.Len() == 0 {
			return "", false
		}
		v1 := v.SliceValue()[0]
		if v1 == nil {
			return "", false
		}
		return v1.ToString(), true
	}
	return "", false
}
1079284
func (a *DerivativeAggregation) Meta(metaData map[string]interface{}) *DerivativeAggregation {
	a.meta = metaData
	return a
}
511276
func toString(v reflect.Value) (string, error) {
	switch v.Kind() {
	case reflect.String:
		return v.String(), nil
	case reflect.Interface:
		return toString(v.Elem())
	}
	return "", errors.New("unable to convert value to string")
}
1295941
func parseMeta(videoID, queryString string) (glod.Response, error) {
	var song glod.Response

	u, _ := url.Parse("?" + queryString)
	query := u.Query()

	if query.Get("errorcode") != "" || query.Get("status") == "fail" {
		return song, errors.New(query.Get("reason"))
	}

	song.Title = query.Get("title")
	song.Artist = query.Get("author")

	formatParam := strings.Split(query.Get("url_encoded_fmt_stream_map"), ",")
	var formats []Format
	for _, f := range formatParam {
		furl, _ := url.Parse("?" + f)
		fquery := furl.Query()

		itag, _ := strconv.Atoi(fquery.Get("itag"))

		formats = append(
			formats,
			Format{
				Itag:      itag,
				VideoType: fquery.Get("type"),
				Quality:   fquery.Get("quality"),
				URL:       fquery.Get("url"),
			})
	}
	if strings.Contains(formats[0].URL, "signature=") {
		song.StreamURL = formats[0].URL
	}
	return song, nil
}
19833
func Metadatify(i interface{}) (Metadata, error) {
	value := reflect.ValueOf(i)
	if value.Kind() == reflect.Map {
		m := map[string]interface{}{}
		for _, k := range value.MapKeys() {
			m[k.String()] = value.MapIndex(k).Interface()
		}
		return Metadata(m), nil
	}
	return nil, errors.New("is not a map")
}
910385
func (a *GeoBoundsAggregation) Meta(metaData map[string]interface{}) *GeoBoundsAggregation {
	a.meta = metaData
	return a
}
1360355
func parseMetadata(ctx context.Context, path, scheme string) (string, string, string, error) {
	rc, err := fetchMetadata(ctx, path, scheme)
	if err != nil {
		return "", "", "", err
	}
	defer rc.Close()

	imports, err := parseMetaGoImports(rc)
	if err != nil {
		return "", "", "", err
	}
	match := -1
	for i, im := range imports {
		if !strings.HasPrefix(path, im.Prefix) {
			continue
		}
		if match != -1 {
			return "", "", "", fmt.Errorf("multiple meta tags match import path %q", path)
		}
		match = i
	}
	if match == -1 {
		return "", "", "", fmt.Errorf("go-import metadata not found")
	}
	return imports[match].Prefix, imports[match].VCS, imports[match].RepoRoot, nil
}
514032
func objectMetaAndKind(typer runtime.ObjectTyper, obj runtime.Object) (*api.ObjectMeta, string, error) {
	objectMeta, err := api.ObjectMetaFor(obj)
	if err != nil {
		return nil, "", errors.NewInternalError(err)
	}
	_, kind, err := typer.ObjectVersionAndKind(obj)
	if err != nil {
		return nil, "", errors.NewInternalError(err)
	}
	return objectMeta, kind, nil
}
472569
func (s *Scheme) generateConvertMeta(srcVersion, destVersion string, in interface{}) (FieldMatchingFlags, *Meta) {
	t := reflect.TypeOf(in)
	return s.converter.inputDefaultFlags[t], &Meta{
		SrcVersion:     srcVersion,
		DestVersion:    destVersion,
		KeyNameMapping: s.converter.inputFieldMappingFuncs[t],
	}
}
522781
func ToString(v Value) string {
	if s, ok := v.(String); ok {
		return string(s)
	}
	return StringOf(v)
}
609401
func (a *IPRangeAggregation) Meta(metaData map[string]interface{}) *IPRangeAggregation {
	a.meta = metaData
	return a
}
1227115
func (u *User) ToStringMap() map[string]interface{} {
	datumIn := map[string]interface{}{
		"FirstName": string(u.FirstName),
		"LastName":  string(u.LastName),
	}

	if len(u.Errors) > 0 {
		datumIn["Errors"] = goavro.Union("array", u.Errors)
	} else {
		datumIn["Errors"] = goavro.Union("null", nil)
	}

	if u.Address != nil {
		addDatum := map[string]interface{}{
			"Address1": string(u.Address.Address1),
			"City":     string(u.Address.City),
			"State":    string(u.Address.State),
			"Zip":      int(u.Address.Zip),
		}
		if u.Address.Address2 != "" {
			addDatum["Address2"] = goavro.Union("string", u.Address.Address2)
		} else {
			addDatum["Address2"] = goavro.Union("null", nil)
		}

		//important need namespace and record name
		datumIn["Address"] = goavro.Union("my.namespace.com.address", addDatum)

	} else {
		datumIn["Address"] = goavro.Union("null", nil)
	}
	return datumIn
}
300720
func (a *SamplerAggregation) Meta(metaData map[string]interface{}) *SamplerAggregation {
	a.meta = metaData
	return a
}
1013104
func (a *MaxAggregation) Meta(metaData map[string]interface{}) *MaxAggregation {
	a.meta = metaData
	return a
}
103947
func (extr *ContentExtractor) GetMetaLanguage(document *goquery.Document) string {
	var language string
	shtml := document.Find("html")
	attr, _ := shtml.Attr("lang")
	if attr == "" {
		attr, _ = document.Attr("lang")
	}
	if attr == "" {
		selection := document.Find("meta").EachWithBreak(func(i int, s *goquery.Selection) bool {
			var exists bool
			attr, exists = s.Attr("http-equiv")
			if exists && attr == "content-language" {
				return false
			}
			return true
		})
		if selection != nil {
			attr, _ = selection.Attr("content")
		}
	}
	idx := strings.LastIndex(attr, "-")
	if idx == -1 {
		language = attr
	} else {
		language = attr[0:idx]
	}

	_, ok := sw[language]

	if language == "" || !ok {
		language = extr.config.stopWords.SimpleLanguageDetector(shtml.Text())
		if language == "" {
			language = defaultLanguage
		}
	}

	extr.config.targetLanguage = language
	return language
}
841133
func (a *GlobalAggregation) Meta(metaData map[string]interface{}) *GlobalAggregation {
	a.meta = metaData
	return a
}