diff options
author | Alexander Harkness <bearbin@gmail.com> | 2013-11-24 15:37:03 +0100 |
---|---|---|
committer | Alexander Harkness <bearbin@gmail.com> | 2013-11-24 15:37:03 +0100 |
commit | c3cd436ec3526962f0f0698ab2d75774247c340b (patch) | |
tree | af5fa89e891ede194f981399af8b830afc6dec97 /src/LuaState.cpp | |
parent | Removed pedantic build and added optimisation to debug builds. (diff) | |
parent | RCONClient: Initial implementation. (diff) | |
download | cuberite-c3cd436ec3526962f0f0698ab2d75774247c340b.tar cuberite-c3cd436ec3526962f0f0698ab2d75774247c340b.tar.gz cuberite-c3cd436ec3526962f0f0698ab2d75774247c340b.tar.bz2 cuberite-c3cd436ec3526962f0f0698ab2d75774247c340b.tar.lz cuberite-c3cd436ec3526962f0f0698ab2d75774247c340b.tar.xz cuberite-c3cd436ec3526962f0f0698ab2d75774247c340b.tar.zst cuberite-c3cd436ec3526962f0f0698ab2d75774247c340b.zip |
Diffstat (limited to 'src/LuaState.cpp')
-rw-r--r-- | src/LuaState.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/LuaState.cpp b/src/LuaState.cpp index 8d2fa8eca..644f4972c 100644 --- a/src/LuaState.cpp +++ b/src/LuaState.cpp @@ -739,6 +739,39 @@ bool cLuaState::CallFunction(int a_NumResults) +bool cLuaState::CheckParamUserTable(int a_StartParam, const char * a_UserTable, int a_EndParam) +{ + ASSERT(IsValid()); + + if (a_EndParam < 0) + { + a_EndParam = a_StartParam; + } + + tolua_Error tolua_err; + for (int i = a_StartParam; i <= a_EndParam; i++) + { + if (tolua_isusertable(m_LuaState, i, a_UserTable, 0, &tolua_err)) + { + 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("#ferror in function '%s'.", (entry.name != NULL) ? entry.name : "?"); + tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err); + return false; + } // for i - Param + + // All params checked ok + return true; +} + + + + + bool cLuaState::CheckParamUserType(int a_StartParam, const char * a_UserType, int a_EndParam) { ASSERT(IsValid()); @@ -838,6 +871,39 @@ bool cLuaState::CheckParamNumber(int a_StartParam, int a_EndParam) +bool cLuaState::CheckParamString(int a_StartParam, int a_EndParam) +{ + ASSERT(IsValid()); + + if (a_EndParam < 0) + { + a_EndParam = a_StartParam; + } + + tolua_Error tolua_err; + for (int i = a_StartParam; i <= a_EndParam; i++) + { + if (tolua_isstring(m_LuaState, i, 0, &tolua_err)) + { + 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("#ferror in function '%s'.", (entry.name != NULL) ? entry.name : "?"); + tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err); + return false; + } // for i - Param + + // All params checked ok + return true; +} + + + + + bool cLuaState::CheckParamEnd(int a_Param) { tolua_Error tolua_err; |