Пример #1
0
// writeFunc writes a syscall wrapper for f to w.
// It modifies f's data, so be warned!
func (m *module) writeFunc(w io.Writer, f *ast.FuncDecl) error {
	f.Recv = nil // Remove the bogus receiver (really the DLL name).
	err := m.printConfig.Fprint(w, m.fileSet, f)
	if err != nil {
		return err
	}
	fmt.Fprintln(w, " {")

	params, setupCode, resultCode, err := m.analyzeParameterList(f.Type)
	if err != nil {
		return err
	}

	prefix := ""
	if m.packageName != "com" {
		prefix = "com."
	}

	if setupCode != "" {
		fmt.Fprintln(w, setupCode)
	}
	fmt.Fprintf(w, "\t_res, _, _ := %sSyscall(proc%s.Addr(),\n\t\t%s)\n", prefix, f.Name.Name, strings.Join(params, ",\n\t\t"))

	fmt.Fprint(w, resultCode)
	fmt.Fprintln(w, "\treturn")

	fmt.Fprintln(w, "}")
	fmt.Fprintln(w)
	return nil
}