From c9a9b3c9d0d4fed0b02d9935923bfd7dcbc45d1e Mon Sep 17 00:00:00 2001 From: Mattes D Date: Tue, 14 Apr 2020 16:43:21 +0200 Subject: Bindings: Allow coercion between Vector3 subtypes. (#4646) In manually bound functions, allows one to use any Vector3 value, as well as a {x, y, z} table, in Lua as any Vector3 parameter. Has example in Debuggers' /vector command. Unfortunately doesn't work in auto-bindings. --- src/Bindings/ManualBindings_World.cpp | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'src/Bindings/ManualBindings_World.cpp') diff --git a/src/Bindings/ManualBindings_World.cpp b/src/Bindings/ManualBindings_World.cpp index 7b072e435..cfefb4f7a 100644 --- a/src/Bindings/ManualBindings_World.cpp +++ b/src/Bindings/ManualBindings_World.cpp @@ -39,10 +39,8 @@ static bool CheckParamVectorOr3Numbers(cLuaState & L, const char * a_VectorName, template static bool GetStackVectorOr3Numbers(cLuaState & L, int a_Index, Vector3 & a_Return) { - Vector3 * UserType; - if (L.GetStackValue(a_Index, UserType)) + if (L.GetStackValue(a_Index, a_Return)) { - a_Return = *UserType; return true; } return L.GetStackValues(a_Index, a_Return.x, a_Return.y, a_Return.z); @@ -367,10 +365,10 @@ static int tolua_cWorld_DoExplosionAt(lua_State * tolua_S) case esBed: { // esBed receives a Vector3i SourceData param: - Vector3i * pos = nullptr; + Vector3i pos; L.GetStackValue(8, pos); SourceType = esBed; - SourceData = pos; + SourceData = &pos; break; } @@ -481,24 +479,19 @@ static int tolua_cWorld_DoWithNearestPlayer(lua_State * tolua_S) // Get parameters: cWorld * Self; - Vector3d * Position; + Vector3d Position; double RangeLimit; cLuaState::cRef FnRef; bool CheckLineOfSight = true, IgnoreSpectators = true; // Defaults for the optional params L.GetStackValues(1, Self, Position, RangeLimit, FnRef, CheckLineOfSight, IgnoreSpectators); - if (Position == nullptr) - { - return L.ApiParamError("Expected a non-nil Vector3d for parameter #2"); - } - if (!FnRef.IsValid()) { return L.ApiParamError("Expected a valid callback function for parameter #3"); } // Call the function: - bool res = Self->DoWithNearestPlayer(*Position, RangeLimit, [&](cPlayer & a_Player) + bool res = Self->DoWithNearestPlayer(Position, RangeLimit, [&](cPlayer & a_Player) { bool ret = false; L.Call(FnRef, &a_Player, cLuaState::Return, ret); @@ -895,7 +888,7 @@ static int tolua_cWorld_SpawnSplitExperienceOrbs(lua_State* tolua_S) } cWorld * self = nullptr; - Vector3d * Position = nullptr; + Vector3d Position; int Reward; L.GetStackValues(1, self, Position, Reward); if (self == nullptr) @@ -903,14 +896,9 @@ static int tolua_cWorld_SpawnSplitExperienceOrbs(lua_State* tolua_S) tolua_error(tolua_S, "Invalid 'self' in function 'SpawnSplitExperienceOrbs'", nullptr); return 0; } - if (Position == nullptr) - { - tolua_error(tolua_S, "Error in function 'SpawnSplitExperienceOrbs' arg #2. Value must not be nil.", nullptr); - return 0; - } // Execute and push result: - L.Push(self->SpawnExperienceOrb(Position->x, Position->y, Position->z, Reward)); + L.Push(self->SpawnExperienceOrb(Position, Reward)); return 1; } -- cgit v1.2.3