diff options
Diffstat (limited to 'Runtime/Lua/LuaBind/LuaBindState.cpp')
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindState.cpp | 156 |
1 files changed, 88 insertions, 68 deletions
diff --git a/Runtime/Lua/LuaBind/LuaBindState.cpp b/Runtime/Lua/LuaBind/LuaBindState.cpp index 137acbf..9210768 100644 --- a/Runtime/Lua/LuaBind/LuaBindState.cpp +++ b/Runtime/Lua/LuaBind/LuaBindState.cpp @@ -4,6 +4,7 @@ #include "LuaBindClass.hpp" #include "LuaBindInternal.h" +#include <string.h> #include <string> namespace LuaBind @@ -539,75 +540,94 @@ namespace LuaBind return true; } - bool State::CheckParams(int idx, cc8* format) - { - idx = AbsIndex(idx); - - for (int i = 0; format[i]; ++i) { - - int pos = idx + i; - int type = LUA_TNIL; - int expected = LUA_TNONE; - - if (pos <= GetTop()) { - type = lua_type(mState, pos); - } - - switch (format[i]) { - - // boolean - case 'B': - if (type != LUA_TBOOLEAN) expected = LUA_TBOOLEAN; - break; - - // coroutine - case 'C': - if (type != LUA_TTHREAD) expected = LUA_TTHREAD; - break; - - // function - case 'F': - if (type != LUA_TFUNCTION) expected = LUA_TFUNCTION; - break; - - // light userdata - case 'L': - if (type != LUA_TLIGHTUSERDATA) expected = LUA_TLIGHTUSERDATA; - break; - - // number - case 'N': - if (type != LUA_TNUMBER) expected = LUA_TNUMBER; - break; - - // string - case 'S': - if (type != LUA_TSTRING) expected = LUA_TSTRING; - break; - - // table - case 'T': - if (type != LUA_TTABLE) expected = LUA_TTABLE; - break; - - // userdata - case 'U': - if (type != LUA_TUSERDATA) expected = LUA_TUSERDATA; - break; - - // any type - case '*': - case '.': - break; - } - - if (expected != LUA_TNONE) { - return false; - } - } + bool State::CheckParams(int idx, cc8* format, int len) + { + idx = AbsIndex(idx); + + for (int i = 0; i < len; ++i) { + int pos = idx + i; + int type = LUA_TNIL; + bool expected = true; + if (pos <= GetTop()) { + type = lua_type(mState, pos); + } + + switch (format[i]) { + + // boolean + case 'B': + if (type != LUA_TBOOLEAN) expected = false; + break; + + // coroutine + case 'C': + if (type != LUA_TTHREAD) expected = false; + break; + + // function + case 'F': + if (type != LUA_TFUNCTION) expected = false; + break; + + // light userdata + case 'L': + if (type != LUA_TLIGHTUSERDATA) expected = false; + break; + + // number + case 'N': + if (type != LUA_TNUMBER) expected = false; + break; + + // string + case 'S': + if (type != LUA_TSTRING) expected = false; + break; + + // table + case 'T': + if (type != LUA_TTABLE) expected = false; + break; + + // userdata + case 'U': + if (type != LUA_TUSERDATA) expected = false; + break; + + // any type + case '*': + break; + + // not nil + case '+': + if (type == LUA_TNIL) expected = false; + break; + } + + if (!expected) { + return false; + } + } + + return true; + } - return true; - } + bool State::CheckParams(int idx, cc8* fmt) + { + cc8* blank = fmt + strlen(fmt); + while (*fmt) { + int len = blank - fmt; + const char* end = strchr(fmt, '|'); + if (end != NULL){ + len = end - fmt; + } + if (CheckParams(idx, fmt, len)){ + return true; + } + fmt = fmt + len + (end != NULL ? 1 : 0); + } + return false; + } template <> bool State::GetValue < bool >(int idx, const bool value) { |