Example #1
0
// Runs the specified Go source code in the context of 'w'
func runScript(w *eval.World, path, sourceCode string) error {
	var err error
	var code eval.Code

	fileSet := token.NewFileSet()
	fileSet.AddFile(path, fileSet.Base(), len(sourceCode))

	code, err = w.Compile(fileSet, sourceCode)
	if err != nil {
		str := strings.Replace(err.Error(), "input", path, 1)
		return errors.New(str)
	}

	_, err = code.Run()
	if err != nil {
		return err
	}

	return nil
}
Example #2
0
func defineConstants(w *eval.World) {
	GOOS := string_value_t(*flag_os)
	GOARCH := string_value_t(*flag_arch)
	GO_COMPILER := string_value_t(goCompiler_name)

	w.DefineConst("GOOS", eval.StringType, &GOOS)
	w.DefineConst("GOARCH", eval.StringType, &GOARCH)
	w.DefineConst("GO_COMPILER", eval.StringType, &GO_COMPILER)
}
Example #3
0
func defineFunctions(w *eval.World) {
	{
		var functionSignature func(string)
		funcType, funcValue := eval.FuncFromNativeTyped(wrapper_Package, functionSignature)
		w.DefineVar("Package", funcType, funcValue)
	}

	{
		var functionSignature func(string)
		funcType, funcValue := eval.FuncFromNativeTyped(wrapper_PackageFiles, functionSignature)
		w.DefineVar("PackageFiles", funcType, funcValue)
	}

	{
		var functionSignature func(string, string)
		funcType, funcValue := eval.FuncFromNativeTyped(wrapper_Executable, functionSignature)
		w.DefineVar("Executable", funcType, funcValue)
	}

	{
		var functionSignature func(string)
		funcType, funcValue := eval.FuncFromNativeTyped(wrapper_IgnoreDir, functionSignature)
		w.DefineVar("IgnoreDir", funcType, funcValue)
	}

	{
		var functionSignature func(string)
		funcType, funcValue := eval.FuncFromNativeTyped(wrapper_DisableGoFmt, functionSignature)
		w.DefineVar("DisableGoFmt", funcType, funcValue)
	}

	{
		var functionSignature func(uint)
		funcType, funcValue := eval.FuncFromNativeTyped(wrapper_MinGoamVersion, functionSignature)
		w.DefineVar("MinGoamVersion", funcType, funcValue)
	}

	{
		var functionSignature func(uint)
		funcType, funcValue := eval.FuncFromNativeTyped(wrapper_MinCompilerVersion, functionSignature)
		w.DefineVar("MinCompilerVersion", funcType, funcValue)
	}

	{
		var functionSignature func()
		funcType, funcValue := eval.FuncFromNativeTyped(wrapper_InstallPackage, functionSignature)
		w.DefineVar("InstallPackage", funcType, funcValue)
	}

	{
		var functionSignature func(string)
		funcType, funcValue := eval.FuncFromNativeTyped(wrapper_InstallExecutable, functionSignature)
		w.DefineVar("InstallExecutable", funcType, funcValue)
	}

	{
		var functionSignature func(string, string)
		funcType, funcValue := eval.FuncFromNativeTyped(wrapper_InstallDir, functionSignature)
		w.DefineVar("InstallDir", funcType, funcValue)
	}

	{
		var functionSignature func(string, string, string, []string)
		funcType, funcValue := eval.FuncFromNativeTyped(wrapper_RemotePackage, functionSignature)
		w.DefineVar("RemotePackage", funcType, funcValue)
	}
}