MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / start

Method start

Source/Falcor/Utils/Scripting/Scripting.cpp:41–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39std::unique_ptr<Scripting::Context> Scripting::sDefaultContext;
40
41void Scripting::start()
42{
43 if (!sRunning)
44 {
45 sRunning = true;
46
47#ifdef FALCOR_PYTHON_EXECUTABLE
48#if FALCOR_WINDOWS
49 static std::filesystem::path pythonHome{std::filesystem::path{FALCOR_PYTHON_EXECUTABLE}.parent_path()};
50#else
51 static std::filesystem::path pythonHome{std::filesystem::path{FALCOR_PYTHON_EXECUTABLE}.parent_path().parent_path()};
52#endif
53#else
54 static std::filesystem::path pythonHome{getRuntimeDirectory() / "pythondist"};
55#endif
56 Py_SetPythonHome(pythonHome.wstring().c_str());
57
58 try
59 {
60 pybind11::initialize_interpreter();
61 sDefaultContext.reset(new Context());
62 // Extend python search path with the directory containing the falcor python module.
63 std::string pythonPath = (getRuntimeDirectory() / "python").generic_string();
64 Scripting::runScript(fmt::format("import sys; sys.path.append(\"{}\")\n", pythonPath));
65 // Set an environment variable to inform the falcor module that it's being loaded from an embedded interpreter.
66 Scripting::runScript("import os; os.environ[\"FALCOR_EMBEDDED_PYTHON\"] = \"1\"");
67
68 // Import falcor into default scripting context.
69 Scripting::runScript("from falcor import *");
70 }
71 catch (const std::exception& e)
72 {
73 FALCOR_THROW("Failed to start the Python interpreter: {}", e.what());
74 }
75 }
76}
77
78void Scripting::shutdown()
79{

Callers

nothing calls this directly

Calls 3

runScriptFunction · 0.85
whatMethod · 0.80
resetMethod · 0.45

Tested by

no test coverage detected