summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2020-04-15 01:23:24 +0200
committerGitHub <noreply@github.com>2020-04-15 01:23:24 +0200
commitf84bab3bc21be6a8f574a8e4a590cb540dee2fd5 (patch)
treed929b8b3c2567160f61c572492787869f52101b3 /src
parentBindings: Allow coercion between Vector3 subtypes. (#4646) (diff)
downloadcuberite-f84bab3bc21be6a8f574a8e4a590cb540dee2fd5.tar
cuberite-f84bab3bc21be6a8f574a8e4a590cb540dee2fd5.tar.gz
cuberite-f84bab3bc21be6a8f574a8e4a590cb540dee2fd5.tar.bz2
cuberite-f84bab3bc21be6a8f574a8e4a590cb540dee2fd5.tar.lz
cuberite-f84bab3bc21be6a8f574a8e4a590cb540dee2fd5.tar.xz
cuberite-f84bab3bc21be6a8f574a8e4a590cb540dee2fd5.tar.zst
cuberite-f84bab3bc21be6a8f574a8e4a590cb540dee2fd5.zip
Diffstat (limited to '')
-rw-r--r--src/Bindings/LuaState.cpp26
-rw-r--r--src/Bindings/LuaState.h4
-rw-r--r--src/Bindings/ManualBindings.cpp10
3 files changed, 35 insertions, 5 deletions
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 0541af793..b7f5f17e0 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -1877,6 +1877,32 @@ bool cLuaState::CheckParamFunctionOrNil(int a_StartParam, int a_EndParam)
+bool cLuaState::CheckParamVector3(int a_StartParam, int a_EndParam)
+{
+ ASSERT(IsValid());
+
+ if (a_EndParam < 0)
+ {
+ a_EndParam = a_StartParam;
+ }
+
+ for (int i = a_StartParam; i <= a_EndParam; ++i)
+ {
+ if (IsParamVector3(a_StartParam))
+ {
+ continue;
+ }
+
+ ApiParamError("Failed to read parameter #%d. Vector3 expected, got %s", i, GetTypeText(i).c_str());
+ return false;
+ }
+ return true;
+}
+
+
+
+
+
bool cLuaState::CheckParamUUID(int a_StartParam, int a_EndParam)
{
ASSERT(IsValid());
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index 6743a65d2..e2eacdaf4 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -798,6 +798,10 @@ public:
Accepts either cUUID instances or strings that contain UUIDs */
bool CheckParamUUID(int a_StartParam, int a_EndParam = -1);
+ /** Returns true if the specified parameters on the stack are Vector3s; also logs warning if not.
+ Accepts any Vector3 type instances or tables. */
+ bool CheckParamVector3(int a_StartParam, int a_EndParam = -1);
+
/** Returns true if the specified parameter on the stack is nil (indicating an end-of-parameters) */
bool CheckParamEnd(int a_Param);
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 063c7f582..5bf5062c9 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -2967,7 +2967,7 @@ static int tolua_cLineBlockTracer_FirstSolidHitTrace(lua_State * tolua_S)
{
// This is the Vector3-based variant of the call:
if (
- !L.CheckParamUserType(idx + 1, "Vector3<double>", idx + 2) ||
+ !L.CheckParamVector3(idx + 1, idx + 2) ||
!L.CheckParamEnd(idx + 3)
)
{
@@ -3061,11 +3061,11 @@ static int tolua_cLineBlockTracer_LineOfSightTrace(lua_State * tolua_S)
return 1;
}
- if (L.IsParamUserType(idx + 1, "Vector3<double>"))
+ if (L.IsParamVector3(idx + 1))
{
- // This is the Vector3d-based variant of the call:
+ // This is the Vector3-based variant of the call:
if (
- !L.CheckParamUserType(idx + 1, "Vector3<double>", idx + 2) ||
+ !L.CheckParamVector3(idx + 1, idx + 2) ||
// Optional param lineOfSight is not checked
!L.CheckParamEnd(idx + 4)
)
@@ -3089,7 +3089,7 @@ static int tolua_cLineBlockTracer_LineOfSightTrace(lua_State * tolua_S)
return 1;
}
- tolua_error(L, "cLineBlockTracer:LineOfSightTrace(): Invalid parameters, expected either a set of coords, or two Vector3d's", nullptr);
+ tolua_error(L, "cLineBlockTracer:LineOfSightTrace(): Invalid parameters, expected either a set of coords, or two Vector3's", nullptr);
return 0;
}