Skip to content

Commit 004fdae

Browse files
committed
Clean up a couple minor issues in lua.cpp
A few comparisons weren't excluding their upper bounds properly, and the documentation for the l_Wing length function was the documentation for the l_Mission_Wings length function.
1 parent 8fcb1ee commit 004fdae

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

code/parse/lua.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,7 +3232,7 @@ ADE_VIRTVAR(Name, l_Shiptype, "string", "Ship type name", "string", "Ship type n
32323232
if(!ade_get_args(L, "o|s", l_Shiptype.Get(&idx), &s))
32333233
return ade_set_error(L, "s", "");
32343234

3235-
if(idx < 0 || idx > (int)Ship_types.size())
3235+
if(idx < 0 || idx >= (int)Ship_types.size())
32363236
return ade_set_error(L, "s", "");
32373237

32383238
if(ADE_SETTING_VAR && s != NULL) {
@@ -3913,7 +3913,7 @@ ADE_FUNC(__tostring, l_Weaponclass, NULL, "Weapon class name", "string", "Weapon
39133913
if(!ade_get_args(L, "o|s", l_Weaponclass.Get(&idx), &s))
39143914
return ade_set_error(L, "s", "");
39153915

3916-
if(idx < 0 || idx > Num_weapon_types)
3916+
if(idx < 0 || idx >= Num_weapon_types)
39173917
return ade_set_error(L, "s", "");
39183918

39193919
return ade_set_args(L, "s", Weapon_info[idx].name);
@@ -3925,10 +3925,10 @@ ADE_FUNC(__eq, l_Weaponclass, "weaponclass, weaponclass", "Checks if the two cla
39253925
if(!ade_get_args(L, "oo", l_Weaponclass.Get(&idx1), l_Weaponclass.Get(&idx2)))
39263926
return ade_set_error(L, "b", false);
39273927

3928-
if(idx1 < 0 || idx1 > Num_weapon_types)
3928+
if(idx1 < 0 || idx1 >= Num_weapon_types)
39293929
return ade_set_error(L, "b", false);
39303930

3931-
if(idx2 < 0 || idx2 > Num_weapon_types)
3931+
if(idx2 < 0 || idx2 >= Num_weapon_types)
39323932
return ade_set_error(L, "b", false);
39333933

39343934
return ade_set_args(L, "b", idx1 == idx2);
@@ -3942,7 +3942,7 @@ ADE_VIRTVAR(Name, l_Weaponclass, "string", "Weapon class name", "string", "Weapo
39423942
if(!ade_get_args(L, "o|s", l_Weaponclass.Get(&idx), &s))
39433943
return ade_set_error(L, "s", "");
39443944

3945-
if(idx < 0 || idx > Num_weapon_types)
3945+
if(idx < 0 || idx >= Num_weapon_types)
39463946
return ade_set_error(L, "s", "");
39473947

39483948
if(ADE_SETTING_VAR && s != NULL) {
@@ -3959,7 +3959,7 @@ ADE_VIRTVAR(Title, l_Weaponclass, "string", "Weapon class title", "string", "Wea
39593959
if(!ade_get_args(L, "o|s", l_Weaponclass.Get(&idx), &s))
39603960
return ade_set_error(L, "s", "");
39613961

3962-
if(idx < 0 || idx > Num_weapon_types)
3962+
if(idx < 0 || idx >= Num_weapon_types)
39633963
return ade_set_error(L, "s", "");
39643964

39653965
if(ADE_SETTING_VAR && s != NULL) {
@@ -4004,7 +4004,7 @@ ADE_VIRTVAR(TechTitle, l_Weaponclass, "string", "Weapon class tech title", "stri
40044004
if(!ade_get_args(L, "o|s", l_Weaponclass.Get(&idx), &s))
40054005
return ade_set_error(L, "s", "");
40064006

4007-
if(idx < 0 || idx > Num_weapon_types)
4007+
if(idx < 0 || idx >= Num_weapon_types)
40084008
return ade_set_error(L, "s", "");
40094009

40104010
if(ADE_SETTING_VAR && s != NULL) {
@@ -4021,7 +4021,7 @@ ADE_VIRTVAR(TechAnimationFilename, l_Weaponclass, "string", "Weapon class animat
40214021
if(!ade_get_args(L, "o|s", l_Weaponclass.Get(&idx), &s))
40224022
return ade_set_error(L, "s", "");
40234023

4024-
if(idx < 0 || idx > Num_weapon_types)
4024+
if(idx < 0 || idx >= Num_weapon_types)
40254025
return ade_set_error(L, "s", "");
40264026

40274027
if(ADE_SETTING_VAR && s != NULL) {
@@ -4066,7 +4066,7 @@ ADE_VIRTVAR(Model, l_Weaponclass, "model", "Model", "model", "Weapon class model
40664066
if(!ade_get_args(L, "o|o", l_Weaponclass.Get(&weapon_info_idx), l_Model.GetPtr(&mdl)))
40674067
return ade_set_error(L, "o", l_Model.Set(-1));
40684068

4069-
if(weapon_info_idx < 0 || weapon_info_idx > Num_weapon_types)
4069+
if(weapon_info_idx < 0 || weapon_info_idx >= Num_weapon_types)
40704070
return ade_set_error(L, "o", l_Model.Set(-1));
40714071

40724072
weapon_info *wip = &Weapon_info[weapon_info_idx];
@@ -4087,7 +4087,7 @@ ADE_VIRTVAR(ArmorFactor, l_Weaponclass, "number", "Amount of weapon damage appli
40874087
if(!ade_get_args(L, "o|f", l_Weaponclass.Get(&idx), &f))
40884088
return ade_set_error(L, "f", 0.0f);
40894089

4090-
if(idx < 0 || idx > Num_weapon_types)
4090+
if(idx < 0 || idx >= Num_weapon_types)
40914091
return ade_set_error(L, "f", 0.0f);
40924092

40934093
if(ADE_SETTING_VAR) {
@@ -4104,7 +4104,7 @@ ADE_VIRTVAR(Damage, l_Weaponclass, "number", "Amount of damage that weapon deals
41044104
if(!ade_get_args(L, "o|f", l_Weaponclass.Get(&idx), &f))
41054105
return ade_set_error(L, "f", 0.0f);
41064106

4107-
if(idx < 0 || idx > Num_weapon_types)
4107+
if(idx < 0 || idx >= Num_weapon_types)
41084108
return ade_set_error(L, "f", 0.0f);
41094109

41104110
if(ADE_SETTING_VAR) {
@@ -4121,7 +4121,7 @@ ADE_VIRTVAR(FireWait, l_Weaponclass, "number", "Weapon fire wait (cooldown time)
41214121
if(!ade_get_args(L, "o|f", l_Weaponclass.Get(&idx), &f))
41224122
return ade_set_error(L, "f", 0.0f);
41234123

4124-
if(idx < 0 || idx > Num_weapon_types)
4124+
if(idx < 0 || idx >= Num_weapon_types)
41254125
return ade_set_error(L, "f", 0.0f);
41264126

41274127
if(ADE_SETTING_VAR) {
@@ -4138,7 +4138,7 @@ ADE_VIRTVAR(FreeFlightTime, l_Weaponclass, "number", "The time the weapon will f
41384138
if(!ade_get_args(L, "o|f", l_Weaponclass.Get(&idx), &f))
41394139
return ade_set_error(L, "f", 0.0f);
41404140

4141-
if(idx < 0 || idx > Num_weapon_types)
4141+
if(idx < 0 || idx >= Num_weapon_types)
41424142
return ade_set_error(L, "f", 0.0f);
41434143

41444144
if(ADE_SETTING_VAR) {
@@ -4155,7 +4155,7 @@ ADE_VIRTVAR(LifeMax, l_Weaponclass, "number", "Life of weapon in seconds", "numb
41554155
if(!ade_get_args(L, "o|f", l_Weaponclass.Get(&idx), &f))
41564156
return ade_set_error(L, "f", 0.0f);
41574157

4158-
if(idx < 0 || idx > Num_weapon_types)
4158+
if(idx < 0 || idx >= Num_weapon_types)
41594159
return ade_set_error(L, "f", 0.0f);
41604160

41614161
if(ADE_SETTING_VAR) {
@@ -4172,7 +4172,7 @@ ADE_VIRTVAR(Range, l_Weaponclass, "number", "Range of weapon in meters", "number
41724172
if(!ade_get_args(L, "o|f", l_Weaponclass.Get(&idx), &f))
41734173
return ade_set_error(L, "f", 0.0f);
41744174

4175-
if(idx < 0 || idx > Num_weapon_types)
4175+
if(idx < 0 || idx >= Num_weapon_types)
41764176
return ade_set_error(L, "f", 0.0f);
41774177

41784178
if(ADE_SETTING_VAR) {
@@ -4189,7 +4189,7 @@ ADE_VIRTVAR(Mass, l_Weaponclass, "number", "Weapon mass", "number", "Weapon mass
41894189
if(!ade_get_args(L, "o|f", l_Weaponclass.Get(&idx), &f))
41904190
return ade_set_error(L, "f", 0.0f);
41914191

4192-
if(idx < 0 || idx > Num_weapon_types)
4192+
if(idx < 0 || idx >= Num_weapon_types)
41934193
return ade_set_error(L, "f", 0.0f);
41944194

41954195
if(ADE_SETTING_VAR) {
@@ -4206,7 +4206,7 @@ ADE_VIRTVAR(ShieldFactor, l_Weaponclass, "number", "Amount of weapon damage appl
42064206
if(!ade_get_args(L, "o|f", l_Weaponclass.Get(&idx), &f))
42074207
return ade_set_error(L, "f", 0.0f);
42084208

4209-
if(idx < 0 || idx > Num_weapon_types)
4209+
if(idx < 0 || idx >= Num_weapon_types)
42104210
return ade_set_error(L, "f", 0.0f);
42114211

42124212
if(ADE_SETTING_VAR) {
@@ -4223,7 +4223,7 @@ ADE_VIRTVAR(SubsystemFactor, l_Weaponclass, "number", "Amount of weapon damage a
42234223
if(!ade_get_args(L, "o|f", l_Weaponclass.Get(&idx), &f))
42244224
return ade_set_error(L, "f", 0.0f);
42254225

4226-
if(idx < 0 || idx > Num_weapon_types)
4226+
if(idx < 0 || idx >= Num_weapon_types)
42274227
return ade_set_error(L, "f", 0.0f);
42284228

42294229
if(ADE_SETTING_VAR) {
@@ -4240,7 +4240,7 @@ ADE_VIRTVAR(TargetLOD, l_Weaponclass, "number", "LOD used for weapon model in th
42404240
if(!ade_get_args(L, "o|i", l_Weaponclass.Get(&idx), &lod))
42414241
return ade_set_error(L, "i", 0);
42424242

4243-
if(idx < 0 || idx > Num_weapon_types)
4243+
if(idx < 0 || idx >= Num_weapon_types)
42444244
return ade_set_error(L, "i", 0);
42454245

42464246
if(ADE_SETTING_VAR) {
@@ -4257,7 +4257,7 @@ ADE_VIRTVAR(Speed, l_Weaponclass, "number", "Weapon max speed, aka $Velocity in
42574257
if(!ade_get_args(L, "o|f", l_Weaponclass.Get(&idx), &spd))
42584258
return ade_set_error(L, "f", 0.0f);
42594259

4260-
if(idx < 0 || idx > Num_weapon_types)
4260+
if(idx < 0 || idx >= Num_weapon_types)
42614261
return ade_set_error(L, "f", 0.0f);
42624262

42634263
if(ADE_SETTING_VAR) {
@@ -4274,7 +4274,7 @@ ADE_VIRTVAR(Bomb, l_Weaponclass, "boolean", "Is weapon class flagged as bomb", "
42744274
if(!ade_get_args(L, "o|b", l_Weaponclass.Get(&idx), &newVal))
42754275
return ADE_RETURN_FALSE;
42764276

4277-
if(idx < 0 || idx > Num_weapon_types)
4277+
if(idx < 0 || idx >= Num_weapon_types)
42784278
return ADE_RETURN_FALSE;
42794279

42804280
weapon_info *info = &Weapon_info[idx];
@@ -4305,7 +4305,7 @@ ADE_VIRTVAR(CargoSize, l_Weaponclass, "number", "The cargo size of this weapon c
43054305
if(!ade_get_args(L, "o|f", l_Weaponclass.Get(&idx), &newVal))
43064306
return ade_set_args(L, "f", -1.0f);
43074307

4308-
if(idx < 0 || idx > Num_weapon_types)
4308+
if(idx < 0 || idx >= Num_weapon_types)
43094309
return ade_set_args(L, "f", -1.0f);
43104310

43114311
weapon_info *info = &Weapon_info[idx];
@@ -8214,7 +8214,7 @@ struct sound_entry_h
82148214

82158215
bool IsValid()
82168216
{
8217-
if (idx < 0 || idx > (int) Snds.size())
8217+
if (idx < 0 || idx >= (int) Snds.size())
82188218
return false;
82198219

82208220
return true;
@@ -8819,7 +8819,7 @@ ADE_INDEXER(l_Wing, "number Index", "Array of ships in the wing", "ship", "Ship
88198819
return ade_set_args(L, "o", l_Ship.Set(object_h(&Objects[Ships[Wings[wdx].ship_index[sdx]].objnum])));
88208820
}
88218821

8822-
ADE_FUNC(__len, l_Wing, NULL, "Number of wings in mission", "number", "Number of wings in mission")
8822+
ADE_FUNC(__len, l_Wing, NULL, "Gets the number of ships in the wing", "number", "Number of ships in wing")
88238823
{
88248824
int wdx;
88258825
if(!ade_get_args(L, "o", l_Wing.Get(&wdx)))

0 commit comments

Comments
 (0)