MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / loadMeasure

Method loadMeasure

ruby/engine/RubyEngine.cpp:207–226  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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
207ScriptObject 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
228int RubyEngine::numberOfArguments(ScriptObject& methodObject, std::string_view methodName) {
229 auto val = std::any_cast<VALUE>(methodObject.object);

Callers 3

TEST_FFunction · 0.45
getMeasureInfoMethod · 0.45
applyMeasuresMethod · 0.45

Calls 1

locationMethod · 0.45

Tested by 1

TEST_FFunction · 0.36