MCPcopy Create free account
hub / github.com/Norbyte/bg3se / LuaLoadExternalFile

Method LuaLoadExternalFile

BG3Extender/Extender/Shared/ExtensionState.cpp:356–378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

354 }
355
356 std::optional<int> ExtensionStateBase::LuaLoadExternalFile(STDString const & path)
357 {
358 std::ifstream f(path.c_str(), std::ios::in | std::ios::binary);
359 if (!f.good()) {
360 OsiError("File does not exist: " << path);
361 return {};
362 }
363
364 f.seekg(0, std::ios::end);
365 auto length = f.tellg();
366 f.seekg(0, std::ios::beg);
367 STDString s((uint32_t)length, '\0');
368 f.read(s.data(), length);
369 f.close();
370
371 LuaVirtualPin lua(*this);
372 if (!lua) {
373 OsiErrorS("Called when the Lua VM has not been initialized!");
374 return {};
375 }
376
377 return lua->LoadScript(s, path);
378 }
379
380 std::optional<int> ExtensionStateBase::LuaLoadGameFile(FileReaderPin & reader, STDString const & scriptName, int globalsIdx)
381 {

Callers

nothing calls this directly

Calls 2

LoadScriptMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected