MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / require

Method require

src/script/squirrel_std.cpp:40–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40SQInteger SquirrelStd::require(HSQUIRRELVM vm)
41{
42 SQInteger top = sq_gettop(vm);
43 std::string_view filename;
44
45 sq_getstring(vm, 2, filename);
46
47 /* Get the script-name of the current file, so we can work relative from it */
48 SQStackInfos si;
49 sq_stackinfos(vm, 1, &si);
50
51 /* Keep the dir, remove the rest */
52 std::string path{si.source};
53 auto p = path.find_last_of(PATHSEPCHAR);
54 /* Keep the PATHSEPCHAR there, remove the rest */
55 if (p != std::string::npos) path.erase(p + 1);
56 path += filename;
57#if (PATHSEPCHAR != '/')
58 std::transform(path.begin(), path.end(), path.begin(), [](char &c) { return c == '/' ? PATHSEPCHAR : c; });
59#endif
60
61 Squirrel *engine = (Squirrel *)sq_getforeignptr(vm);
62 bool ret = engine->LoadScript(vm, path);
63
64 /* Reset the top, so the stack stays correct */
65 sq_settop(vm, top);
66
67 return ret ? 0 : SQ_ERROR;
68}
69
70SQInteger SquirrelStd::notifyallexceptions(HSQUIRRELVM vm)
71{

Callers

nothing calls this directly

Calls 9

sq_gettopFunction · 0.85
sq_getstringFunction · 0.85
sq_stackinfosFunction · 0.85
sq_getforeignptrFunction · 0.85
sq_settopFunction · 0.85
LoadScriptMethod · 0.80
eraseMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected