#include "python_host_node.h" #include #include "python_stdlib.h" #ifdef MTGODOT_HAVE_PYTHON // Standard types only — PythonBoot.h keeps and the Win32 shims out of this translation // unit, which has to stay compilable next to godot-cpp. #include "platform/ScriptLib/PythonBoot.h" #include #endif using namespace godot; namespace mtgodot { #ifdef MTGODOT_HAVE_PYTHON String Metin2PythonHost::start(const String &stdlib_path) { String path = stdlib_path; if (path.is_empty()) { path = Metin2Python::stdlib_path(false); if (path.is_empty()) { return String("python27.zip unavailable: ") + Metin2Python::last_error(); } } std::string error; if (!PythonBoot::Start(path.utf8().get_data(), &error)) { return String::utf8(error.c_str()); } return String(); } bool Metin2PythonHost::is_running() { return PythonBoot::IsRunning(); } String Metin2PythonHost::run_main_script(const String &command_line) { std::string error; if (!PythonBoot::RunMainScript(command_line.utf8().get_data(), &error)) { return String::utf8(error.c_str()); } return String(); } String Metin2PythonHost::run_line(const String &source) { std::string error; if (!PythonBoot::RunLine(source.utf8().get_data(), &error)) { return String::utf8(error.c_str()); } return String(); } void Metin2PythonHost::stop() { PythonBoot::Stop(); } #else // Built without -DMTGODOT_EMBED_PYTHON=ON: the class is still registered so GDScript can tell "no // interpreter in this build" apart from "the interpreter failed to start". String Metin2PythonHost::start(const String &) { return String("this build has no embedded Python (-DMTGODOT_EMBED_PYTHON=ON)"); } bool Metin2PythonHost::is_running() { return false; } String Metin2PythonHost::run_main_script(const String &) { return String("this build has no embedded Python (-DMTGODOT_EMBED_PYTHON=ON)"); } String Metin2PythonHost::run_line(const String &) { return String("this build has no embedded Python (-DMTGODOT_EMBED_PYTHON=ON)"); } void Metin2PythonHost::stop() { } #endif void Metin2PythonHost::_bind_methods() { ClassDB::bind_static_method("Metin2PythonHost", D_METHOD("start", "stdlib_path"), &Metin2PythonHost::start, DEFVAL(String())); ClassDB::bind_static_method("Metin2PythonHost", D_METHOD("is_running"), &Metin2PythonHost::is_running); ClassDB::bind_static_method("Metin2PythonHost", D_METHOD("run_main_script", "command_line"), &Metin2PythonHost::run_main_script, DEFVAL(String())); ClassDB::bind_static_method("Metin2PythonHost", D_METHOD("run_line", "source"), &Metin2PythonHost::run_line); ClassDB::bind_static_method("Metin2PythonHost", D_METHOD("stop"), &Metin2PythonHost::stop); } } // namespace mtgodot