mirror of https://github.com/OpenTTD/OpenTTD
Merge 57cea4e98c
into a46a3a97f3
commit
eb9dd4e26e
|
@ -858,18 +858,32 @@ SQInteger ScriptList::_get(HSQUIRRELVM vm)
|
|||
SQInteger ScriptList::_set(HSQUIRRELVM vm)
|
||||
{
|
||||
if (sq_gettype(vm, 2) != OT_INTEGER) return SQ_ERROR;
|
||||
if (sq_gettype(vm, 3) != OT_INTEGER && sq_gettype(vm, 3) != OT_NULL) {
|
||||
return sq_throwerror(vm, "you can only assign integers to this list");
|
||||
}
|
||||
|
||||
SQInteger idx, val;
|
||||
SQInteger idx;
|
||||
sq_getinteger(vm, 2, &idx);
|
||||
if (sq_gettype(vm, 3) == OT_NULL) {
|
||||
this->RemoveItem(idx);
|
||||
return 0;
|
||||
|
||||
/* Retrieve the return value */
|
||||
SQInteger val;
|
||||
switch (sq_gettype(vm, 3)) {
|
||||
case OT_NULL:
|
||||
this->RemoveItem(idx);
|
||||
return 0;
|
||||
|
||||
case OT_BOOL: {
|
||||
SQBool v;
|
||||
sq_getbool(vm, 3, &v);
|
||||
val = v ? 1 : 0;
|
||||
break;
|
||||
}
|
||||
|
||||
case OT_INTEGER:
|
||||
sq_getinteger(vm, 3, &val);
|
||||
break;
|
||||
|
||||
default:
|
||||
return sq_throwerror(vm, "you can only assign integers to this list");
|
||||
}
|
||||
|
||||
sq_getinteger(vm, 3, &val);
|
||||
if (!this->HasItem(idx)) {
|
||||
this->AddItem(idx, val);
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue