| 38 | } |
| 39 | |
| 40 | SQInteger 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 | |
| 70 | SQInteger SquirrelStd::notifyallexceptions(HSQUIRRELVM vm) |
| 71 | { |
nothing calls this directly
no test coverage detected