Ideally this would return a openstudio::measure::OSMeasure* or a shared_ptr but this poses memory management issue for the underlying ScriptObject (and VALUE or PyObject), so just return the ScriptObject
| 205 | // Ideally this would return a openstudio::measure::OSMeasure* or a shared_ptr<openstudio::measure::OSMeasure> but this poses memory management |
| 206 | // issue for the underlying ScriptObject (and VALUE or PyObject), so just return the ScriptObject |
| 207 | ScriptObject RubyEngine::loadMeasure(const openstudio::path& measureScriptPath, std::string_view className) { |
| 208 | |
| 209 | ScriptObject result; |
| 210 | try { |
| 211 | auto importCmd = fmt::format("load '{}'", measureScriptPath.generic_string()); |
| 212 | exec(importCmd); |
| 213 | } catch (const RubyException& e) { |
| 214 | auto msg = |
| 215 | fmt::format("Failed to load measure '{}' from '{}': {}\nlocation={}", className, measureScriptPath.generic_string(), e.what(), e.location()); |
| 216 | fmt::print(stderr, "{}\n", msg); |
| 217 | } |
| 218 | try { |
| 219 | result = eval(fmt::format("{}.new()", className)); |
| 220 | } catch (const RubyException& e) { |
| 221 | auto msg = fmt::format("Failed to instantiate measure '{}' from '{}': {}\nlocation={}", className, measureScriptPath.generic_string(), e.what(), |
| 222 | e.location()); |
| 223 | fmt::print(stderr, "{}\n", msg); |
| 224 | } |
| 225 | return result; |
| 226 | } |
| 227 | |
| 228 | int RubyEngine::numberOfArguments(ScriptObject& methodObject, std::string_view methodName) { |
| 229 | auto val = std::any_cast<VALUE>(methodObject.object); |