summaryrefslogtreecommitdiff
path: root/Runtime/Lua
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-28 16:24:34 +0800
committerchai <chaifix@163.com>2021-10-28 16:24:34 +0800
commit40d40edcdeef4978a0d9c7333b7007d1fa4c0bc6 (patch)
tree5b96c37f9bd85dd0be7a8b880a1de24914ae2880 /Runtime/Lua
parent92dd401d75e19281dc7a01492ab3c0996de330fc (diff)
*misc
Diffstat (limited to 'Runtime/Lua')
-rw-r--r--Runtime/Lua/LuaBind/LuaBindState.cpp156
-rw-r--r--Runtime/Lua/LuaBind/LuaBindState.h3
2 files changed, 90 insertions, 69 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) {
diff --git a/Runtime/Lua/LuaBind/LuaBindState.h b/Runtime/Lua/LuaBind/LuaBindState.h
index a47ed5d..528c81a 100644
--- a/Runtime/Lua/LuaBind/LuaBindState.h
+++ b/Runtime/Lua/LuaBind/LuaBindState.h
@@ -65,7 +65,8 @@ namespace LuaBind
void SetTop(int top);
int GetTop();
- bool CheckParams(int idx, cc8* format);
+ bool CheckParams(int idx, cc8* format, int len);
+ bool CheckParams(int idx, cc8* format);
int AbsIndex(int idx);
void Call(int nArgs, int nResults, ErrorHandler handler = NULL);