Skip to content

Commit 44acd1e

Browse files
committed
Luabind - Replace RTE::Vector get/set properties with def_readwrite
This only replaces the get/set pairs where the clear intent is to let the Lua code read or write the vectors at will, and where the getters/setters don't do anything at all. Rationale: the getters all return `const RTE::Vector&` - a *constant* reference, modifying through which breaks programmer and compiler assumptions. This makes innocent looking Lua code like `Thing.Pos.X = 5` ill-defined. In particular, Oberon00's fork of Luabind errors out on code like the above exactly due to this circumstance. This commit fixes most instances of this. I can't guarantee that this commit is comprehensive. I vote for getting rid of all the useless getters/setters like these in the first place, which would then make it easier to ensure that the Lua code does not run into this on accident.
1 parent 3bfd541 commit 44acd1e

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

Source/Entities/Attachable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace RTE {
1010
/// An articulated, detachable part of an Actor's body.
1111
class Attachable : public MOSRotating {
1212
friend class MOSRotating;
13+
friend struct EntityLuaBindings;
1314

1415
public:
1516
EntityAllocation(Attachable);

Source/Entities/LimbPath.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace RTE {
1717
/// A set of Vector:s making up a motion path for a AtomGroup's limb. The
1818
/// path is continuous.
1919
class LimbPath : public Entity {
20+
friend struct EntityLuaBindings;
2021

2122
/// Public member variable, method and friend function declarations
2223
public:

Source/Entities/SceneObject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace RTE {
1515
/// The base class shared by Both TerrainObject:s and MovableObject:s, ie
1616
/// anything that can be places in a scene.
1717
class SceneObject : public Entity {
18+
friend struct EntityLuaBindings;
1819

1920
/// Public member variable, method and friend function declarations
2021
public:
@@ -285,6 +286,7 @@ namespace RTE {
285286

286287
// Member variables
287288
static Entity::ClassInfo m_sClass;
289+
288290
// Absolute position of the center of this in the scene, in pixels
289291
Vector m_Pos;
290292
// How much this SceneObject costs to purchase, in oz's of gold.

Source/Entities/SoundContainer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace RTE {
1212

1313
/// A container for sounds that represent a specific sound effect.
1414
class SoundContainer : public Entity {
15+
friend struct EntityLuaBindings;
1516

1617
public:
1718
EntityAllocation(SoundContainer);

Source/Lua/LuaBindingsEntities.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,8 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, Arm) {
538538
LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, Attachable) {
539539
return ConcreteTypeLuaClassDefinition(Attachable, MOSRotating)
540540

541-
.property("ParentOffset", &Attachable::GetParentOffset, &Attachable::SetParentOffset)
542541
.property("JointStrength", &Attachable::GetJointStrength, &Attachable::SetJointStrength)
543542
.property("JointStiffness", &Attachable::GetJointStiffness, &Attachable::SetJointStiffness)
544-
.property("JointOffset", &Attachable::GetJointOffset, &Attachable::SetJointOffset)
545-
.property("JointPos", &Attachable::GetJointPos)
546543
.property("DeleteWhenRemovedFromParent", &Attachable::GetDeleteWhenRemovedFromParent, &Attachable::SetDeleteWhenRemovedFromParent)
547544
.property("GibWhenRemovedFromParent", &Attachable::GetGibWhenRemovedFromParent, &Attachable::SetGibWhenRemovedFromParent)
548545
.property("ApplyTransferredForcesAtOffset", &Attachable::GetApplyTransferredForcesAtOffset, &Attachable::SetApplyTransferredForcesAtOffset)
@@ -560,6 +557,10 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, Attachable) {
560557
.property("InheritsVelWhenDetached", &Attachable::InheritsVelocityWhenDetached, &Attachable::SetInheritsVelocityWhenDetached)
561558
.property("InheritsAngularVelWhenDetached", &Attachable::InheritsAngularVelocityWhenDetached, &Attachable::SetInheritsAngularVelocityWhenDetached)
562559

560+
.def_readwrite("ParentOffset", &Attachable::m_ParentOffset)
561+
.def_readwrite("JointOffset", &Attachable::m_JointOffset)
562+
.def_readwrite("JointPos", &Attachable::m_JointPos)
563+
563564
.def("IsAttached", &Attachable::IsAttached)
564565
.def("IsAttachedTo", &Attachable::IsAttachedTo)
565566

@@ -740,12 +741,13 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, Leg) {
740741
LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, LimbPath) {
741742
return luabind::class_<LimbPath>("LimbPath")
742743

743-
.property("StartOffset", &LimbPath::GetStartOffset, &LimbPath::SetStartOffset)
744744
.property("SegmentCount", &LimbPath::GetSegCount)
745745
.property("BaseTravelSpeedMultiplier", &LimbPath::GetBaseTravelSpeedMultiplier, &LimbPath::SetBaseTravelSpeedMultiplier)
746746
.property("TravelSpeed", &LimbPath::GetTravelSpeed, &LimbPath::SetTravelSpeed)
747747
.property("PushForce", &LimbPath::GetPushForce, &LimbPath::SetPushForce)
748748

749+
.def_readwrite("StartOffset", &LimbPath::m_Start)
750+
749751
.def("GetSegment", &LimbPath::GetSegment);
750752
}
751753

@@ -865,8 +867,6 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, MOSRotating) {
865867
.property("IndividualRadius", &MOSRotating::GetIndividualRadius)
866868
.property("IndividualDiameter", &MOSRotating::GetIndividualDiameter)
867869
.property("IndividualMass", &MOSRotating::GetIndividualMass)
868-
.property("RecoilForce", &MOSRotating::GetRecoilForce)
869-
.property("RecoilOffset", &MOSRotating::GetRecoilOffset)
870870
.property("TravelImpulse", &MOSRotating::GetTravelImpulse, &MOSRotating::SetTravelImpulse)
871871
.property("GibWoundLimit", (int(MOSRotating::*)() const) & MOSRotating::GetGibWoundLimit, &MOSRotating::SetGibWoundLimit)
872872
.property("GibSound", &MOSRotating::GetGibSound, &LuaAdaptersPropertyOwnershipSafetyFaker::MOSRotatingSetGibSound)
@@ -877,6 +877,8 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, MOSRotating) {
877877
.property("WoundCount", (int(MOSRotating::*)() const) & MOSRotating::GetWoundCount)
878878
.property("OrientToVel", &MOSRotating::GetOrientToVel, &MOSRotating::SetOrientToVel)
879879

880+
.def_readwrite("RecoilForce", &MOSRotating::m_RecoilForce)
881+
.def_readwrite("RecoilOffset", &MOSRotating::m_RecoilOffset)
880882
.def_readonly("Attachables", &MOSRotating::m_Attachables, luabind::return_stl_iterator)
881883
.def_readonly("Wounds", &MOSRotating::m_Wounds, luabind::return_stl_iterator)
882884
.def_readonly("Gibs", &MOSRotating::m_Gibs, luabind::return_stl_iterator)
@@ -920,9 +922,9 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, MOSRotating) {
920922
LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, MovableObject) {
921923
return AbstractTypeLuaClassDefinition(MovableObject, SceneObject)
922924

925+
923926
.property("Material", &MovableObject::GetMaterial)
924927
.property("Mass", &MovableObject::GetMass, &MovableObject::SetMass)
925-
.property("Vel", &MovableObject::GetVel, &MovableObject::SetVel)
926928
.property("PrevPos", &MovableObject::GetPrevPos)
927929
.property("PrevVel", &MovableObject::GetPrevVel)
928930
.property("DistanceTravelled", &MovableObject::GetDistanceTravelled)
@@ -969,6 +971,8 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, MovableObject) {
969971
.property("SimUpdatesBetweenScriptedUpdates", &MovableObject::GetSimUpdatesBetweenScriptedUpdates, &MovableObject::SetSimUpdatesBetweenScriptedUpdates)
970972
.property("PostEffectEnabled", &MovableObject::GetPostEffectEnabled, &MovableObject::SetPostEffectEnabled)
971973

974+
.def_readwrite("Vel", &MovableObject::m_Vel)
975+
972976
.def("GetParent", (MOSRotating * (MovableObject::*)()) & MovableObject::GetParent)
973977
.def("GetParent", (const MOSRotating* (MovableObject::*)() const) & MovableObject::GetParent)
974978
.def("GetRootParent", (MovableObject * (MovableObject::*)()) & MovableObject::GetRootParent)
@@ -1259,7 +1263,6 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, StaticSceneLayer)
12591263
LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, SceneObject) {
12601264
return AbstractTypeLuaClassDefinition(SceneObject, Entity)
12611265

1262-
.property("Pos", &SceneObject::GetPos, &SceneObject::SetPos)
12631266
.property("HFlipped", &SceneObject::IsHFlipped, &SceneObject::SetHFlipped)
12641267
.property("RotAngle", &SceneObject::GetRotAngle, &SceneObject::SetRotAngle)
12651268
.property("Team", &SceneObject::GetTeam, &SceneObject::SetTeam)
@@ -1268,6 +1271,8 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, SceneObject) {
12681271

12691272
.property("BuyableMode", &LuaAdaptersSceneObject::GetBuyableMode)
12701273

1274+
.def_readwrite("Pos", &SceneObject::m_Pos)
1275+
12711276
.def("IsOnScenePoint", &SceneObject::IsOnScenePoint)
12721277
.def("GetGoldValue", &SceneObject::GetGoldValueOld)
12731278
.def("GetGoldValue", &SceneObject::GetGoldValue)
@@ -1305,6 +1310,8 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, SoundContainer) {
13051310

13061311
.def(luabind::constructor<>())
13071312

1313+
.def_readwrite("Pos", &SoundContainer::m_Pos)
1314+
13081315
.property("SoundOverlapMode", &SoundContainer::GetSoundOverlapMode, &SoundContainer::SetSoundOverlapMode)
13091316
.property("BusRouting", &SoundContainer::GetBusRouting, &SoundContainer::SetBusRouting)
13101317
.property("Immobile", &SoundContainer::IsImmobile, &SoundContainer::SetImmobile)
@@ -1314,7 +1321,6 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, SoundContainer) {
13141321
.property("Loops", &SoundContainer::GetLoopSetting, &SoundContainer::SetLoopSetting)
13151322
.property("Priority", &SoundContainer::GetPriority, &SoundContainer::SetPriority)
13161323
.property("AffectedByGlobalPitch", &SoundContainer::IsAffectedByGlobalPitch, &SoundContainer::SetAffectedByGlobalPitch)
1317-
.property("Pos", &SoundContainer::GetPosition, &SoundContainer::SetPosition)
13181324
.property("Volume", &SoundContainer::GetVolume, &SoundContainer::SetVolume)
13191325
.property("Pitch", &SoundContainer::GetPitch, &SoundContainer::SetPitch)
13201326
.property("Paused", &SoundContainer::IsPaused, &SoundContainer::SetPaused)

0 commit comments

Comments
 (0)