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
@@ -96,6 +96,7 @@ else
|
||||
# it shares the class layouts: a stale one after a header change is
|
||||
# the same memory-corruption hazard as a stale sks/document.so.
|
||||
$(MAKE) -C $(K)/ref clean
|
||||
$(MAKE) -C $(K)/kpy clean
|
||||
$(MAKE) clean
|
||||
$(MAKE) all
|
||||
endif
|
||||
|
||||
+2
-18
@@ -58,24 +58,8 @@ int main(int argc, char* argv[])
|
||||
expand_tilde(args.as_string("o")), args.as_bool("d"));
|
||||
|
||||
Machine M;
|
||||
M.m_state.open_frame("ktext");
|
||||
M.m_state.set("K_target", target);
|
||||
M.m_state.set("K_output_dir", output_dir);
|
||||
M.m_state.set("K_output_basename", output_basename);
|
||||
M.m_state.set("K_stdout_only", display_only ? "true" : "false");
|
||||
// The list form uses the standalone-"/" separator (filenames may
|
||||
// contain spaces); K_input_filename is the single root input file.
|
||||
M.m_state.set("K_input_filenames", join(input_filenames, " / "));
|
||||
M.m_state.set("K_input_filename",
|
||||
input_filenames.empty() ? "" : input_filenames[0]);
|
||||
M.m_state.set("K_verbose_level", std::to_string(verbose_level));
|
||||
|
||||
if (!input_filenames.empty()) {
|
||||
M.m_state.set(
|
||||
"K_input_dir",absolute_pathname(file_directory(input_filenames[0])));
|
||||
} else {
|
||||
M.m_state.set("K_input_dir", fs::current_path().string());
|
||||
}
|
||||
set_command_state(M, "ktext", target, input_filenames, output_dir,
|
||||
output_basename, display_only);
|
||||
|
||||
load_klammersets(M, word_split(args.as_string("klammersets")));
|
||||
|
||||
|
||||
Reference in new issue
Block a user