static */
| 29 | } |
| 30 | |
| 31 | /* static */ SQInteger ScriptInfo::Constructor(HSQUIRRELVM vm, ScriptInfo &info) |
| 32 | { |
| 33 | /* Set some basic info from the parent */ |
| 34 | Squirrel::GetInstance(vm, &info.SQ_instance, 2); |
| 35 | /* Make sure the instance stays alive over time */ |
| 36 | sq_addref(vm, &info.SQ_instance); |
| 37 | |
| 38 | info.scanner = (ScriptScanner *)Squirrel::GetGlobalPointer(vm); |
| 39 | info.engine = info.scanner->GetEngine(); |
| 40 | |
| 41 | /* Ensure the mandatory functions exist */ |
| 42 | static const std::string_view required_functions[] = { |
| 43 | "GetAuthor", |
| 44 | "GetName", |
| 45 | "GetShortName", |
| 46 | "GetDescription", |
| 47 | "GetVersion", |
| 48 | "GetDate", |
| 49 | "CreateInstance", |
| 50 | }; |
| 51 | for (const auto &required_function : required_functions) { |
| 52 | if (!info.CheckMethod(required_function)) return SQ_ERROR; |
| 53 | } |
| 54 | |
| 55 | /* Get location information of the scanner */ |
| 56 | info.main_script = info.scanner->GetMainScript(); |
| 57 | info.tar_file = info.scanner->GetTarFile(); |
| 58 | |
| 59 | /* Cache the data the info file gives us. */ |
| 60 | if (!info.engine->CallStringMethod(info.SQ_instance, "GetAuthor", &info.author, MAX_GET_OPS)) return SQ_ERROR; |
| 61 | if (!info.engine->CallStringMethod(info.SQ_instance, "GetName", &info.name, MAX_GET_OPS)) return SQ_ERROR; |
| 62 | if (!info.engine->CallStringMethod(info.SQ_instance, "GetShortName", &info.short_name, MAX_GET_OPS)) return SQ_ERROR; |
| 63 | if (!info.engine->CallStringMethod(info.SQ_instance, "GetDescription", &info.description, MAX_GET_OPS)) return SQ_ERROR; |
| 64 | if (!info.engine->CallStringMethod(info.SQ_instance, "GetDate", &info.date, MAX_GET_OPS)) return SQ_ERROR; |
| 65 | if (!info.engine->CallIntegerMethod(info.SQ_instance, "GetVersion", &info.version, MAX_GET_OPS)) return SQ_ERROR; |
| 66 | if (info.version < 0) return SQ_ERROR; |
| 67 | if (!info.engine->CallStringMethod(info.SQ_instance, "CreateInstance", &info.instance_name, MAX_CREATEINSTANCE_OPS)) return SQ_ERROR; |
| 68 | |
| 69 | /* The GetURL function is optional. */ |
| 70 | if (info.engine->MethodExists(info.SQ_instance, "GetURL")) { |
| 71 | if (!info.engine->CallStringMethod(info.SQ_instance, "GetURL", &info.url, MAX_GET_OPS)) return SQ_ERROR; |
| 72 | } |
| 73 | |
| 74 | /* Check if we have settings */ |
| 75 | if (info.engine->MethodExists(info.SQ_instance, "GetSettings")) { |
| 76 | if (!info.GetSettings()) return SQ_ERROR; |
| 77 | } |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | bool ScriptInfo::GetSettings() |
| 83 | { |
nothing calls this directly
no test coverage detected