summaryrefslogtreecommitdiffstats
path: root/src/Bindings
diff options
context:
space:
mode:
authorandrew <xdotftw@gmail.com>2014-01-21 19:40:41 +0100
committerandrew <xdotftw@gmail.com>2014-01-21 19:40:41 +0100
commit9bd8f74b598866539e3e5133188326bd7d14a827 (patch)
tree15f411bd03371e555250b898f3883c0fa20c2b8b /src/Bindings
parentScoreboard SendTo() (diff)
parentFix a crash but somewhere... (diff)
downloadcuberite-9bd8f74b598866539e3e5133188326bd7d14a827.tar
cuberite-9bd8f74b598866539e3e5133188326bd7d14a827.tar.gz
cuberite-9bd8f74b598866539e3e5133188326bd7d14a827.tar.bz2
cuberite-9bd8f74b598866539e3e5133188326bd7d14a827.tar.lz
cuberite-9bd8f74b598866539e3e5133188326bd7d14a827.tar.xz
cuberite-9bd8f74b598866539e3e5133188326bd7d14a827.tar.zst
cuberite-9bd8f74b598866539e3e5133188326bd7d14a827.zip
Diffstat (limited to 'src/Bindings')
-rw-r--r--src/Bindings/LuaState.cpp34
-rw-r--r--src/Bindings/LuaState.h3
-rw-r--r--src/Bindings/ManualBindings.cpp24
3 files changed, 51 insertions, 10 deletions
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 00e62fcf6..bfee1d037 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -914,6 +914,40 @@ bool cLuaState::CheckParamString(int a_StartParam, int a_EndParam)
+bool cLuaState::CheckParamFunction(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 (lua_isfunction(m_LuaState, i))
+ {
+ continue;
+ }
+ // Not the correct parameter
+ lua_Debug entry;
+ VERIFY(lua_getstack(m_LuaState, 0, &entry));
+ VERIFY(lua_getinfo (m_LuaState, "n", &entry));
+ AString ErrMsg = Printf("Error in function '%s' parameter #%d. Function expected, got %s",
+ (entry.name != NULL) ? entry.name : "?", i, GetTypeText(i).c_str()
+ );
+ LogStackTrace();
+ return false;
+ } // for i - Param
+
+ // All params checked ok
+ return true;
+}
+
+
+
+
+
bool cLuaState::CheckParamEnd(int a_Param)
{
tolua_Error tolua_err;
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index 414e5e4b2..f8b67f5cd 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -815,6 +815,9 @@ public:
/// Returns true if the specified parameters on the stack are strings; also logs warning if not
bool CheckParamString(int a_StartParam, int a_EndParam = -1);
+ /// Returns true if the specified parameters on the stack are functions; also logs warning if not
+ bool CheckParamFunction(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 3ebe7b294..2206dd371 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -986,11 +986,10 @@ static int tolua_cWorld_QueueTask(lua_State * tolua_S)
class cLuaScheduledWorldTask :
- public cWorld::cScheduledTask
+ public cWorld::cTask
{
public:
- cLuaScheduledWorldTask(cPluginLua & a_Plugin, int a_FnRef, int a_Ticks) :
- cScheduledTask(a_Ticks),
+ cLuaScheduledWorldTask(cPluginLua & a_Plugin, int a_FnRef) :
m_Plugin(a_Plugin),
m_FnRef(a_FnRef)
{
@@ -1025,14 +1024,19 @@ static int tolua_cWorld_ScheduleTask(lua_State * tolua_S)
}
// Retrieve the args:
- cWorld * self = (cWorld *)tolua_tousertype(tolua_S, 1, 0);
- if (self == NULL)
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamUserType(1, "cWorld") ||
+ !L.CheckParamNumber (2) ||
+ !L.CheckParamFunction(3)
+ )
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Not called on an object instance");
+ return 0;
}
- if (!lua_isfunction(tolua_S, 2))
+ cWorld * World = (cWorld *)tolua_tousertype(tolua_S, 1, NULL);
+ if (World == NULL)
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #1");
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Not called on an object instance");
}
// Create a reference to the function:
@@ -1042,9 +1046,9 @@ static int tolua_cWorld_ScheduleTask(lua_State * tolua_S)
return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #1");
}
- int Ticks = (int) tolua_tonumber (tolua_S, 3, 0);
+ int DelayTicks = (int)tolua_tonumber(tolua_S, 2, 0);
- self->ScheduleTask(new cLuaScheduledWorldTask(*Plugin, FnRef, Ticks));
+ World->ScheduleTask(DelayTicks, new cLuaScheduledWorldTask(*Plugin, FnRef));
return 0;
}