- bool isBoolean() const { return (bool)lua_isboolean(state, index); }
- bool isFunction() const { return (bool)lua_isfunction(state, index); }
- bool isNil() const { return (bool)lua_isnil(state, index); }
- bool isNone() const { return (bool)lua_isnone(state, index); }
- bool isValid() const { return state != 0 && !isNone(); }
- bool isNoneOrNil() const { return (bool)lua_isnoneornil(state, index); }
- bool isNumber() const { return (bool)lua_isnumber(state, index); }
- bool isString() const { return (bool)lua_isstring(state, index); }
- bool isTable() const { return (bool)lua_istable(state, index); }
- bool isThread() const { return (bool)lua_isthread(state, index); }
- bool isData() const { return (bool)lua_isuserdata(state, index); }
- bool isLightData() const { return (bool)lua_islightuserdata(state, index); }
+ bool isBoolean() const { return (bool)lua_isboolean(mState, index); }
+ bool isFunction() const { return (bool)lua_isfunction(mState, index); }
+ bool isNil() const { return (bool)lua_isnil(mState, index); }
+ bool isNone() const { return (bool)lua_isnone(mState, index); }
+ bool isValid() const { return mState != 0 && !isNone(); }
+ bool isNoneOrNil() const { return (bool)lua_isnoneornil(mState, index); }
+ bool isNumber() const { return (bool)lua_isnumber(mState, index); }
+ bool isString() const { return (bool)lua_isstring(mState, index); }
+ bool isTable() const { return (bool)lua_istable(mState, index); }
+ bool isThread() const { return (bool)lua_isthread(mState, index); }
+ bool isData() const { return (bool)lua_isuserdata(mState, index); }
+ bool isLightData() const { return (bool)lua_islightuserdata(mState, index); }
+
+ /**
+ * Check the value and throw an error if its the wrong type. There's a
+ * little caveat: This method never returns because it does a long jump.
+ * Consequently, constructed C++ objects which exist on the stack
+ * between the current frame and some lua function will not be
+ * destructed. That's not a problem for objects that only exist on the
+ * stack, but any objects that allocate memory on the heap (such as
+ * containers or strings) will leak. Therefore, you should only call
+ * this method after cleaning up such objects. The best thing to do for
+ * defining functions is to simply check all the parameters at the
+ * get-go before any C++ objects are even constructed.
+ */
+
+ void requireType(Type type) const
+ {
+ if (type != getType())
+ {
+ luaL_typerror(mState, index, lua_typename(mState, type));
+ }
+ }
+
+ void throwError(const char* error)
+ {
+ luaL_argerror(mState, index, error);
+ }
+
+
+ Slot& requireBoolean()
+ {
+ if (!isBoolean()) luaL_typerror(mState, index, "boolean");
+ return *this;
+ }
+ Slot& requireNumber()
+ {
+ if (!isNumber()) luaL_typerror(mState, index, "number");
+ return *this;
+ }
+ Slot& requireString()
+ {
+ if (!isString()) luaL_typerror(mState, index, "string");
+ return *this;
+ }
+ Slot& requireTable()
+ {
+ if (!isTable()) luaL_typerror(mState, index, "table");
+ return *this;
+ }
+ Slot& requireFunction()
+ {
+ if (!isFunction()) luaL_typerror(mState, index, "function");
+ return *this;
+ }
+ Slot& requireData()
+ {
+ if (!isData()) luaL_typerror(mState, index, "data");
+ return *this;
+ }
+ Slot& requireNil()
+ {
+ if (!isNil()) luaL_typerror(mState, index, "nil");
+ return *this;
+ }
+ Slot& requireThread()
+ {
+ if (!isThread()) luaL_typerror(mState, index, "thread");
+ return *this;
+ }
+