The Python binding (kpy/): klammertext.Machine from a script
Assembled from klammertext-dev ed13dfaa5b7a. kpy/klammertext.cpp is a CPython extension module giving a Python script an instance of the Machine class -- ktext in-process, set up through the same functions the command uses. Errors map one-to-one to Python exceptions under the C++ names; an @eval's Python exception is chained as __cause__. Built by make -C mac, found through PYTHONPATH (env/runtime.env sets it), tested by tst/kpy_test.sh. Three engine changes came with it: Error::message(), set_command_state(), and the @eval error report carrying its traceback. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uv7KWxafinDPraswEf4GsC
This commit is contained in:
1 parent
e4f1307aa9
commit
760fda5470
17 files changed
+1241
-78
No files matched your search
@@ -17,6 +17,17 @@ public:
|
||||
std::vector<std::string> parse_modules(std::string code);
|
||||
void import_module(const std::string& module_name, bool verify = true);
|
||||
std::string get_result(PyObject* result_object);
|
||||
// The Python exception currently raised (there must be one): clear it,
|
||||
// return the formatted traceback, and keep the exception object in the
|
||||
// slot below. ktext puts the text into the Error it throws; the Python
|
||||
// binding (kpy/) additionally chains the object as the Error's __cause__,
|
||||
// so a script sees the ZeroDivisionError its @eval raised, with its
|
||||
// traceback, and not only a description of it.
|
||||
std::string fetch_python_exception();
|
||||
// Take ownership of the exception kept by the last fetch (nullptr if
|
||||
// none); the slot is cleared. ktext never calls this: it terminates on
|
||||
// the Error, and the interpreter is torn down with the process.
|
||||
static PyObject* take_last_exception();
|
||||
std::string eval_expression(const std::string& expression, bool import_modules = true);
|
||||
std::string eval_statements(const std::string& script);
|
||||
std::string eval(std::string code);
|
||||
@@ -29,4 +40,5 @@ public:
|
||||
Locator m_loc;
|
||||
PyObject* m_globals;
|
||||
PyObject* m_locals;
|
||||
static PyObject* s_last_exception;
|
||||
};
|
||||
Reference in new issue
Block a user