mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 22:28:56 +00:00
(svn r15441) -Cleanup: Use a return value instead of passing a pointer to where the result should be stored.
This commit is contained in:
parent
1eeb0f6748
commit
8d25202067
@ -119,20 +119,19 @@ const char *AIFileInfo::GetMainScript()
|
|||||||
return this->main_script;
|
return this->main_script;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AIFileInfo::CheckMethods(SQInteger *res, const char *name)
|
bool AIFileInfo::CheckMethod(const char *name)
|
||||||
{
|
{
|
||||||
if (!this->engine->MethodExists(*this->SQ_instance, name)) {
|
if (!this->engine->MethodExists(*this->SQ_instance, name)) {
|
||||||
char error[1024];
|
char error[1024];
|
||||||
snprintf(error, sizeof(error), "your info.nut/library.nut doesn't have the method '%s'", name);
|
snprintf(error, sizeof(error), "your info.nut/library.nut doesn't have the method '%s'", name);
|
||||||
this->engine->ThrowError(error);
|
this->engine->ThrowError(error);
|
||||||
*res = SQ_ERROR;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ SQInteger AIFileInfo::Constructor(HSQUIRRELVM vm, AIFileInfo *info, bool library)
|
/* static */ SQInteger AIFileInfo::Constructor(HSQUIRRELVM vm, AIFileInfo *info, bool library)
|
||||||
{
|
{
|
||||||
SQInteger res = 0;
|
|
||||||
|
|
||||||
/* Set some basic info from the parent */
|
/* Set some basic info from the parent */
|
||||||
info->SQ_instance = MallocT<SQObject>(1);
|
info->SQ_instance = MallocT<SQObject>(1);
|
||||||
Squirrel::GetInstance(vm, info->SQ_instance, 2);
|
Squirrel::GetInstance(vm, info->SQ_instance, 2);
|
||||||
@ -141,20 +140,21 @@ void AIFileInfo::CheckMethods(SQInteger *res, const char *name)
|
|||||||
info->base = ((AIScanner *)Squirrel::GetGlobalPointer(vm));
|
info->base = ((AIScanner *)Squirrel::GetGlobalPointer(vm));
|
||||||
info->engine = info->base->GetEngine();
|
info->engine = info->base->GetEngine();
|
||||||
|
|
||||||
/* Check if all needed fields are there */
|
static const char * const required_functions[] = {
|
||||||
info->CheckMethods(&res, "GetAuthor");
|
"GetAuthor",
|
||||||
info->CheckMethods(&res, "GetName");
|
"GetName",
|
||||||
info->CheckMethods(&res, "GetShortName");
|
"GetShortName",
|
||||||
info->CheckMethods(&res, "GetDescription");
|
"GetDescription",
|
||||||
info->CheckMethods(&res, "GetVersion");
|
"GetVersion",
|
||||||
info->CheckMethods(&res, "GetDate");
|
"GetDate",
|
||||||
info->CheckMethods(&res, "CreateInstance");
|
"CreateInstance",
|
||||||
if (library) {
|
};
|
||||||
info->CheckMethods(&res, "GetCategory");
|
for (size_t i = 0; i < lengthof(required_functions); i++) {
|
||||||
|
if (!info->CheckMethod(required_functions[i])) return SQ_ERROR;
|
||||||
|
}
|
||||||
|
if (library) {
|
||||||
|
if (!info->CheckMethod("GetCategory")) return SQ_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Abort if one method was missing */
|
|
||||||
if (res != 0) return res;
|
|
||||||
|
|
||||||
info->main_script = strdup(info->base->GetMainScript());
|
info->main_script = strdup(info->base->GetMainScript());
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Check if a given method exists.
|
* Check if a given method exists.
|
||||||
*/
|
*/
|
||||||
void CheckMethods(SQInteger *res, const char *name);
|
bool CheckMethod(const char *name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the creation of a FileInfo object.
|
* Process the creation of a FileInfo object.
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
const IndustrySpec *ins = ::GetIndustrySpec(industry_type);
|
const IndustrySpec *ins = ::GetIndustrySpec(industry_type);
|
||||||
|
|
||||||
AIList *list = new AIList();
|
AIList *list = new AIList();
|
||||||
for (int i = 0; i < 2; i++) {
|
for (size_t i = 0; i < lengthof(ins->produced_cargo); i++) {
|
||||||
if (ins->produced_cargo[i] != CT_INVALID) list->AddItem(ins->produced_cargo[i], 0);
|
if (ins->produced_cargo[i] != CT_INVALID) list->AddItem(ins->produced_cargo[i], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +70,7 @@
|
|||||||
const IndustrySpec *ins = ::GetIndustrySpec(industry_type);
|
const IndustrySpec *ins = ::GetIndustrySpec(industry_type);
|
||||||
|
|
||||||
AIList *list = new AIList();
|
AIList *list = new AIList();
|
||||||
for (int i = 0; i < 3; i++) {
|
for (size_t i = 0; i < lengthof(ins->accepts_cargo); i++) {
|
||||||
if (ins->accepts_cargo[i] != CT_INVALID) list->AddItem(ins->accepts_cargo[i], 0);
|
if (ins->accepts_cargo[i] != CT_INVALID) list->AddItem(ins->accepts_cargo[i], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user