Skip to content

Commit

Permalink
allow execute pyzfx through in-memory code string
Browse files Browse the repository at this point in the history
  • Loading branch information
littlemine committed Sep 27, 2024
1 parent f3564aa commit d32b26e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions projects/PyZpc/pyzfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,18 @@ struct PyZfx : INode {
if (PyDict_SetItemString(zenoModDict, "_args", argsDict) < 0)
throw makeError("failed to set zpy._args");

if (path.empty()) {
if (has_input("code")) { // path.empty()
auto code = get_input2<std::string>("code");
mainMod = PyRun_StringFlags(code.c_str(), Py_file_input, globals, globals, NULL);
} else {
auto tmpFile = zs::abs_exe_directory() + "/pyzfx.py";
if (std::FILE* f = std::fopen(tmpFile.c_str(), "w")) {
std::fwrite(code.data(), sizeof(char), code.size(), f);
std::fclose(f);
// *
path = tmpFile;
}
// mainMod = PyRun_StringFlags(code.c_str(), Py_file_input, globals, globals, NULL);
}
{
FILE *fp = fopen(path.c_str(), "r");
if (!fp) {
perror(path.c_str());
Expand Down

0 comments on commit d32b26e

Please sign in to comment.