@@ -5,7 +5,7 @@ package main
55#include <Python.h>
66
77void pry_eval_file(FILE* f, const char* file, int argn, const char *argv) {
8− const wchar_t* xargv[argn+1];
8+ wchar_t* xargv[argn+1];
99 const char* ptr = argv;
1010 for (int i = 0; i < argn; ++i) {
1111 xargv[i] = Py_DecodeLocale(ptr, NULL);
@@ -19,7 +19,7 @@ void pry_eval_file(FILE* f, const char* file, int argn, const char *argv) {
1919const char* pry_eval(const char *code, int start) {
2020
2121 PyObject *m, *d, *s, *v;
22− PyCodeObject *c;
22+ PyObject *c;
2323 m = PyImport_AddModule("__main__");
2424
2525 if (m == NULL) return NULL;
@@ -46,17 +46,24 @@ const char* pry_eval(const char *code, int start) {
4646 return str;
4747}
4848
49+void pry_set_prompts(const char* ps1, const char* ps2) {
50+ PyObject *po1 = PyUnicode_FromString(ps1);
51+ PyObject *po2 = PyUnicode_FromString(ps2);
52+ PySys_SetObject("ps1", po1);
53+ PySys_SetObject("ps2", po2);
54+ Py_DECREF(po1);
55+ Py_DECREF(po2);
56+}
57+
4958*/
5059import "C"
5160
5261import (
53− "unsafe"
5462 "strings"
63+ "unsafe"
5564)
5665
57−
5866type Python struct {
59−
6067}
6168
6269func (p Python) Open() {
@@ -83,10 +90,10 @@ func (p Python) EvalFile(file string, args []string) {
8390 handle := C.stdin
8491 cfile := C.CString(file)
8592 defer C.free(unsafe.Pointer(cfile))
86−
93+
8794 if file != "-" {
8895 cmode := C.CString("r")
89−
96+
9097 defer C.free(unsafe.Pointer(cmode))
9198 handle = C.fopen(cfile, cmode)
9299 defer C.fclose(handle)
@@ -94,7 +101,7 @@ func (p Python) EvalFile(file string, args []string) {
94101
95102 argv := C.CString(file + "\x00" + strings.Join(args, "\x00"))
96103 defer C.free(unsafe.Pointer(argv))
97− C.pry_eval_file(handle, cfile, C.int(len(args) + 1), argv)
104+ C.pry_eval_file(handle, cfile, C.int(len(args)+1), argv)
98105}
99106
100107func (p Python) REPLLikeEval(code string) {
@@ -109,7 +116,16 @@ func (p Python) REPL() {
109116 C.PyRun_InteractiveLoopFlags(C.stdin, fn, nil)
110117}
111118
112−func (p Python) Close() {
119+func (p Python) SetPrompts(ps1, ps2 string) {
120+ cps1 := C.CString(ps1)
121+ defer C.free(unsafe.Pointer(cps1))
122+ cps2 := C.CString(ps2)
123+ defer C.free(unsafe.Pointer(cps2))
124+
125+ C.pry_set_prompts(cps1, cps2)
126+}
127+
128+func (p Python) Close() {
113129 C.Py_Finalize()
114130}
115131