MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / Load

Method Load

src/openrct2/scripting/Plugin.cpp:42–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42void Plugin::Load()
43{
44 if (_context)
45 {
46 JS_FreeContext(_context);
47 }
48
49 if (!_path.empty())
50 {
51 LoadCodeFromFile();
52 }
53
54 auto& scriptEngine = OpenRCT2::GetContext()->GetScriptEngine();
55 _context = scriptEngine.CreateContext();
56 JS_SetContextOpaque(_context, this);
57
58 JSValue registerFunc = JS_NewCFunction(_context, registerPlugin, "registerPlugin", 1);
59 JSValue glb = JS_GetGlobalObject(_context);
60 JS_SetPropertyStr(_context, glb, "registerPlugin", registerFunc);
61 JS_FreeValue(_context, glb);
62
63 JSValue res = JS_Eval(_context, _code.c_str(), _code.length(), _path.c_str(), JS_EVAL_TYPE_GLOBAL);
64 if (JS_IsException(res))
65 {
66 JSValue exceptionVal = JS_GetException(_context);
67 std::string details = Stringify(_context, exceptionVal);
68 JS_FreeValue(_context, exceptionVal);
69 JS_FreeValue(_context, res);
70 JS_FreeContext(_context);
71 throw std::runtime_error("Failed to load plug-in script: " + _path + "\n" + details);
72 }
73 JS_FreeValue(_context, res);
74
75 _hasLoaded = true;
76}
77
78void Plugin::Start()
79{

Callers 4

HandleCommandConvertFunction · 0.45
RegisterPluginMethod · 0.45
LoadPluginMethod · 0.45
ReloadPluginMethod · 0.45

Calls 3

GetContextFunction · 0.85
CreateContextMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected