• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang types.ArgSource类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中fubsy/types.ArgSource的典型用法代码示例。如果您正苦于以下问题:Golang ArgSource类的具体用法?Golang ArgSource怎么用?Golang ArgSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ArgSource类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: fn_build

func fn_build(argsource types.ArgSource) (types.FuObject, []error) {
	rt := argsource.(RuntimeArgs).runtime
	args := argsource.Args()
	targets := rt.nodify(args[0])
	sources := rt.nodify(args[1])
	actionobj := args[2]

	fmt.Printf(
		"fn_build():\n"+
			"  targets: %T %v\n"+
			"  sources: %T %v\n"+
			"  actions: %T %v\n",
		targets, targets, sources, sources, actionobj, actionobj)

	var errs []error
	var action Action
	if actionstr, ok := actionobj.(types.FuString); ok {
		action = NewCommandAction(actionstr)
	} else {
		errs = append(errs, errors.New("build(): only command strings supported as actions right now, sorry"))
	}

	rule := NewBuildRule(rt, targets, sources)
	rule.action = action

	return rule, errs
}
开发者ID:sbinet,项目名称:fubsy,代码行数:27,代码来源:builtins.go


示例2: meth_FinderNode_prune

func meth_FinderNode_prune(args types.ArgSource) (types.FuObject, []error) {
	robj := args.Receiver().(*FinderNode)
	for _, arg := range args.Args() {
		robj.Prune(arg.String())
	}
	return nil, nil
}
开发者ID:sbinet,项目名称:fubsy,代码行数:7,代码来源:findernode.go


示例3: logFunctionCall

func logFunctionCall(callable types.FuCallable, args types.ArgSource) {
	argstrings := make([]string, len(args.Args()))
	for i, arg := range args.Args() {
		argstrings[i] = arg.String()
	}
	log.Info("%s(%s)", callable.Name(), strings.Join(argstrings, ", "))
}
开发者ID:sbinet,项目名称:fubsy,代码行数:7,代码来源:action.go


示例4: fn_remove

func fn_remove(argsource types.ArgSource) (types.FuObject, []error) {
	errs := make([]error, 0)
	for _, name := range argsource.Args() {
		err := os.RemoveAll(name.ValueString())
		if err != nil {
			errs = append(errs, err)
		}
	}
	return nil, errs
}
开发者ID:sbinet,项目名称:fubsy,代码行数:10,代码来源:builtins.go


示例5: fn_println

func fn_println(argsource types.ArgSource) (types.FuObject, []error) {
	for i, val := range argsource.Args() {
		if i > 0 {
			os.Stdout.WriteString(" ")
		}
		var s string
		if val == nil {
			s = "(nil)"
		} else {
			s = val.ValueString()
		}
		_, err := os.Stdout.WriteString(s)
		if err != nil {
			// this shouldn't happen, so bail immediately
			return nil, []error{err}
		}
	}
	os.Stdout.WriteString("\n")
	return nil, nil
}
开发者ID:sbinet,项目名称:fubsy,代码行数:20,代码来源:builtins.go


示例6: callPython

func (self PythonCallable) callPython(argsource types.ArgSource) (types.FuObject, []error) {
	args := argsource.Args()

	// build a slice of strings, which will then be converted to
	// Python strings in C (this way we only copy the bytes once, at
	// the cost of C code knowing the internals of Go slices and
	// strings)
	sargs := make([]string, len(args))
	for i, arg := range args {
		switch arg.(type) {
		case types.FuString:
			sargs[i] = arg.ValueString()
		default:
			err := fmt.Errorf(
				"bad argument type: all arguments must be strings, "+
					"but argument %d is %s %s",
				i+1, arg.Typename(), arg.String())
			return nil, []error{err}
		}
	}

	var cerror *C.char
	var cresult *C.char
	var result types.FuObject
	cresult = C.call_python(self.callable, unsafe.Pointer(&sargs), &cerror)

	if cerror != nil {
		err := C.GoString(cerror)
		return nil, []error{errors.New(err)}
	}
	if cresult != nil {
		result = types.MakeFuString(C.GoString(cresult))
	}

	return result, nil
}
开发者ID:sbinet,项目名称:fubsy,代码行数:36,代码来源:python.go


示例7: fn_ActionNode

func fn_ActionNode(argsource types.ArgSource) (types.FuObject, []error) {
	basename := argsource.Args()[0].ValueString()
	graph := argsource.(RuntimeArgs).Graph()
	return dag.MakeActionNode(graph, basename+":action"), nil
}
开发者ID:sbinet,项目名称:fubsy,代码行数:5,代码来源:builtins.go


示例8: fn_FileNode

func fn_FileNode(argsource types.ArgSource) (types.FuObject, []error) {
	name := argsource.Args()[0].ValueString()
	graph := argsource.(RuntimeArgs).Graph()
	return dag.MakeFileNode(graph, name), nil
}
开发者ID:sbinet,项目名称:fubsy,代码行数:5,代码来源:builtins.go


示例9: Test_evaluateCall_method

func Test_evaluateCall_method(t *testing.T) {
	// construct AST for "a.b.c(x)"
	astargs := []dsl.ASTExpression{dsl.NewASTName("x")}
	astcall := dsl.NewASTFunctionCall(
		dsl.NewASTSelection(
			dsl.NewASTSelection(dsl.NewASTName("a"), "b"), "c"),
		astargs)

	// make sure a is an object with attributes, and b is one of them
	// (N.B. having FileNodes be attributes of one another is weird
	// and would never happen in a real Fubsy script, but it's a
	// convenient way to setup this method call)
	aobj := dag.NewFileNode("a.txt")
	bobj := dag.NewFileNode("b.txt")
	aobj.ValueMap = types.NewValueMap()
	aobj.Assign("b", bobj)

	// make sure a.b.c is a method
	calls := make([]string, 0) // list of function names
	var meth_c types.FuCode
	meth_c = func(argsource types.ArgSource) (types.FuObject, []error) {
		args := argsource.Args()
		if len(args) != 1 {
			panic("c() called with wrong number of args")
		}
		calls = append(calls, "c")
		robj := argsource.Receiver()
		return nil, []error{
			fmt.Errorf("c failed: receiver: %s %v, arg: %s %v",
				robj.Typename(), robj, args[0].Typename(), args[0])}
	}
	bobj.ValueMap = types.NewValueMap()
	bobj.Assign("c", types.NewFixedFunction("c", 1, meth_c))

	rt := minimalRuntime()
	ns := rt.Namespace()
	ns.Assign("a", aobj)
	ns.Assign("x", types.MakeFuString("hello"))

	// what the hell, let's test the precall feature too
	var precalledCallable types.FuCallable
	var precalledArgs types.ArgSource
	precall := func(callable types.FuCallable, argsource types.ArgSource) {
		precalledCallable = callable
		precalledArgs = argsource
	}

	callable, args, errs := rt.prepareCall(astcall)
	assert.Equal(t, "c", callable.(*types.FuFunction).Name())
	assert.True(t, args.Receiver() == bobj)
	assert.Equal(t, 0, len(errs))

	result, errs := rt.evaluateCall(callable, args, precall)
	assert.Equal(t, precalledCallable, callable)
	assert.Equal(t, precalledArgs.Args(), types.MakeStringList("hello").List())
	assert.Nil(t, result)
	if len(errs) == 1 {
		assert.Equal(t,
			"c failed: receiver: FileNode \"b.txt\", arg: string \"hello\"",
			errs[0].Error())
	} else {
		t.Errorf("expected exactly 1 error, but got: %v", errs)
	}
}
开发者ID:sbinet,项目名称:fubsy,代码行数:64,代码来源:execute_test.go



注:本文中的fubsy/types.ArgSource类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang types.FuObject类代码示例发布时间:2022-05-24
下一篇:
Golang db.ModelTx类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap