mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 12:32:21 +00:00
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package main
|
|
|
|
/*
|
|
// macOS:
|
|
// python3-config --cflags
|
|
// python3-config --ldflags
|
|
#cgo darwin CFLAGS: -I/Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m -I/Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m -fno-strict-aliasing -Wsign-compare -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -g
|
|
#cgo darwin LDFLAGS: -L/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/config-3.6m-darwin -lpython3.6m -ldl -framework CoreFoundation
|
|
|
|
// linux
|
|
#cgo linux pkg-config: python3
|
|
|
|
// windows
|
|
// should generate libpython3.a from python3.lib
|
|
|
|
#define Py_LIMITED_API
|
|
#include <Python.h>
|
|
|
|
static PyObject *
|
|
spam_system(PyObject *self, PyObject *args) {
|
|
const char *command;
|
|
if (!PyArg_ParseTuple(args, "s", &command)) {
|
|
return NULL;
|
|
}
|
|
|
|
int status = system(command);
|
|
return PyLong_FromLong(status);
|
|
}
|
|
|
|
static PyMethodDef modMethods[] = {
|
|
{"system", spam_system, METH_VARARGS, "Execute a shell command."},
|
|
{NULL, NULL, 0, NULL}
|
|
};
|
|
|
|
void* PyInit_gopkg(void) {
|
|
static struct PyModuleDef module = {
|
|
PyModuleDef_HEAD_INIT, "gopkg", NULL, -1, modMethods,
|
|
};
|
|
return (void*)PyModule_Create(&module);
|
|
}
|
|
*/
|
|
import "C"
|
|
|
|
import "fmt"
|
|
|
|
func main() {}
|
|
|
|
// export SayHello
|
|
func SayHello(name *C.char) {
|
|
fmt.Printf("hello %s!\n", C.GoString(name))
|
|
}
|