summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gtest/gtest_get_weixinnum.cpp8
-rw-r--r--gtest/gtest_tsg_lua_cache_exec.cpp92
-rw-r--r--gtest/gtest_tsg_lua_exec.cpp130
-rw-r--r--gtest/gtest_tsg_lua_exec_bytecode.cpp90
-rw-r--r--gtest/gtest_tsg_lua_exec_bytecode_file.cpp88
-rw-r--r--gtest/gtest_tsg_lua_exec_file.cpp130
-rw-r--r--gtest/script/handle_qqnum.lua10
-rw-r--r--gtest/script/handle_weixinnum.lua10
-rw-r--r--gtest/script/return_boolean_normal.lua4
-rw-r--r--gtest/script/return_boolean_normal.luajitbin109 -> 101 bytes
-rw-r--r--gtest/script/return_integer_normal.lua4
-rw-r--r--gtest/script/return_integer_normal.luajitbin109 -> 97 bytes
-rw-r--r--gtest/script/return_type_invaild.lua2
-rw-r--r--include/tsg_lua_interface.h10
-rw-r--r--src/tsg_lua_func.cpp196
-rw-r--r--src/tsg_lua_interface.h17
16 files changed, 441 insertions, 350 deletions
diff --git a/gtest/gtest_get_weixinnum.cpp b/gtest/gtest_get_weixinnum.cpp
index e7a30a2..1be9be2 100644
--- a/gtest/gtest_get_weixinnum.cpp
+++ b/gtest/gtest_get_weixinnum.cpp
@@ -36,7 +36,7 @@ TEST(tsg_lua_get_weixinnum, exec_cache_script)
int data_len;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
memset(out, 0, 255);
L = tsg_lua_vm_create();
@@ -59,7 +59,7 @@ TEST(tsg_lua_get_weixinnum, exec_cache_file)
int data_len;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
memset(out, 0, 255);
L = tsg_lua_vm_create();
@@ -81,7 +81,7 @@ TEST(tsg_lua_get_weixinnum, exec_script)
int data_len;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
memset(out, 0, 255);
L = tsg_lua_vm_create();
@@ -103,7 +103,7 @@ TEST(tsg_lua_get_weixinnum, exec_file)
int data_len;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
memset(out, 0, 255);
L = tsg_lua_vm_create();
diff --git a/gtest/gtest_tsg_lua_cache_exec.cpp b/gtest/gtest_tsg_lua_cache_exec.cpp
index 7fc2e1e..9907fc5 100644
--- a/gtest/gtest_tsg_lua_cache_exec.cpp
+++ b/gtest/gtest_tsg_lua_cache_exec.cpp
@@ -13,7 +13,7 @@ TEST(tsg_lua_cache_exec, normal_return_string)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_string_normal.lua";
@@ -33,7 +33,7 @@ TEST(tsg_lua_cache_exec, normal_return_boolean)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = BOOLEAN;
L = tsg_lua_vm_create();
const char *script = "./script/return_boolean_normal.lua";
memset(out, 0, 255);
@@ -52,7 +52,7 @@ TEST(tsg_lua_cache_exec, normal_return_integer)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = INTEGER;
L = tsg_lua_vm_create();
const char *script = "./script/return_integer_normal.lua";
memset(out, 0, 255);
@@ -71,7 +71,7 @@ TEST(tsg_lua_cache_exec, lua_vm_isnull)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_string_normal.lua";
@@ -83,7 +83,7 @@ TEST(tsg_lua_cache_exec, lua_vm_isnull)
/* check */
EXPECT_EQ(ERR_LUAVM_ISNULL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -92,7 +92,7 @@ TEST(tsg_lua_cache_exec, script_id_invaild)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
memset(out, 0, 255);
int script_id = 0;
@@ -101,7 +101,7 @@ TEST(tsg_lua_cache_exec, script_id_invaild)
/* check */
EXPECT_EQ(ERR_SCRIPT_ID_INVAILD, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -110,7 +110,7 @@ TEST(tsg_lua_cache_exec, input_isnull)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
char *input = NULL;
L = tsg_lua_vm_create();
@@ -122,7 +122,7 @@ TEST(tsg_lua_cache_exec, input_isnull)
/* check */
EXPECT_EQ(ERR_INPUT_ISNULL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -131,7 +131,7 @@ TEST(tsg_lua_cache_exec, in_len_invaild)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_string_normal.lua";
@@ -142,7 +142,7 @@ TEST(tsg_lua_cache_exec, in_len_invaild)
/* check */
EXPECT_EQ(ERR_IN_LEN_INVAILD, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -151,7 +151,7 @@ TEST(tsg_lua_cache_exec, string_expected_but_nil)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/string_expected_but_nil.lua";
@@ -162,7 +162,7 @@ TEST(tsg_lua_cache_exec, string_expected_but_nil)
/* check */
EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_NIL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -171,7 +171,7 @@ TEST(tsg_lua_cache_exec, string_expected_but_boolean)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/string_expected_but_boolean.lua";
@@ -182,7 +182,7 @@ TEST(tsg_lua_cache_exec, string_expected_but_boolean)
/* check */
EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_BOOL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -191,7 +191,7 @@ TEST(tsg_lua_cache_exec, call_global_but_nil)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/call_global_but_nil.lua";
@@ -202,37 +202,37 @@ TEST(tsg_lua_cache_exec, call_global_but_nil)
/* check */
EXPECT_EQ(ERR_SCRIPT_CALL_GLOBAL_BUT_NIL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
-TEST(tsg_lua_cache_exec, return_too_few)
-{
- tsg_lua_handle L = NULL;
- char out[255];
- size_t out_len = 0;
- size_t out_type = 0;
+// TEST(tsg_lua_cache_exec, return_too_few)
+// {
+// tsg_lua_handle L = NULL;
+// char out[255];
+// size_t out_len = 0;
+// size_t out_type = STRING;
- L = tsg_lua_vm_create();
- const char *script = "./script/return_too_few.lua";
- memset(out, 0, 255);
- int script_id = tsg_lua_cache_script_file(L, script);
- int ret = tsg_lua_cache_exec(L, script_id, data, strlen(data), out, &out_len, &out_type);
+// L = tsg_lua_vm_create();
+// const char *script = "./script/return_too_few.lua";
+// memset(out, 0, 255);
+// int script_id = tsg_lua_cache_script_file(L, script);
+// int ret = tsg_lua_cache_exec(L, script_id, data, strlen(data), out, &out_len, &out_type);
- /* check */
- EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret);
- EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
- EXPECT_STREQ("", out);
-}
+// /* check */
+// EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret);
+// EXPECT_EQ(0, out_len);
+// EXPECT_EQ(STRING, out_type);
+// EXPECT_STREQ("", out);
+// }
TEST(tsg_lua_cache_exec, return_too_much)
{
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_too_much.lua";
@@ -243,16 +243,16 @@ TEST(tsg_lua_cache_exec, return_too_much)
/* check */
EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_MUCH, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
-TEST(tsg_lua_cache_exec, return_type_invaild)
+TEST(tsg_lua_cache_exec, return_type_nil)
{
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_type_invaild.lua";
@@ -261,9 +261,9 @@ TEST(tsg_lua_cache_exec, return_type_invaild)
int ret = tsg_lua_cache_exec(L, script_id, data, strlen(data), out, &out_len, &out_type);
/* check */
- EXPECT_EQ(ERR_SCRIPT_RETURN_TYPE_INVAILD, ret);
- EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(ERR_RETUNR_NIL, ret);
+ EXPECT_EQ(5, out_len);
+ EXPECT_EQ(NIL, out_type);
EXPECT_STREQ("", out);
}
@@ -272,7 +272,7 @@ TEST(tsg_lua_cache_exec, return_length_iszero)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_length_iszero.lua";
@@ -283,7 +283,7 @@ TEST(tsg_lua_cache_exec, return_length_iszero)
/* check */
EXPECT_EQ(ERR_SCRIPT_RETURN_LEN_INVAILD, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -292,7 +292,7 @@ TEST(tsg_lua_cache_exec, string_expected_but_table)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/string_expected_but_table.lua";
@@ -303,7 +303,7 @@ TEST(tsg_lua_cache_exec, string_expected_but_table)
/* check */
EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_TABLE, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -312,7 +312,7 @@ TEST(tsg_lua_cache_exec, normal_return_string_sharp)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_string_normal_sharp.lua";
diff --git a/gtest/gtest_tsg_lua_exec.cpp b/gtest/gtest_tsg_lua_exec.cpp
index 1be5bcc..d69366e 100644
--- a/gtest/gtest_tsg_lua_exec.cpp
+++ b/gtest/gtest_tsg_lua_exec.cpp
@@ -31,7 +31,7 @@ TEST(tsg_lua_exec, normal_return_string)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
memset(out, 0, 255);
@@ -50,7 +50,7 @@ TEST(tsg_lua_exec, normal_return_boolean)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = BOOLEAN;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/return_boolean_normal.lua");
memset(out, 0, 255);
@@ -68,7 +68,7 @@ TEST(tsg_lua_exec, normal_return_integer)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = INTEGER;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/return_integer_normal.lua");
memset(out, 0, 255);
@@ -86,7 +86,7 @@ TEST(tsg_lua_exec, lua_vm_isnull)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
const char *script = get_script_buffer("./script/return_string_normal.lua");
memset(out, 0, sizeof(out));
@@ -95,7 +95,7 @@ TEST(tsg_lua_exec, lua_vm_isnull)
/* check */
EXPECT_EQ(ERR_LUAVM_ISNULL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -104,7 +104,7 @@ TEST(tsg_lua_exec, script_isnull)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = NULL;
memset(out, 0, 255);
@@ -113,7 +113,7 @@ TEST(tsg_lua_exec, script_isnull)
/* check */
EXPECT_EQ(ERR_SCRIPT_ISNULL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -122,7 +122,7 @@ TEST(tsg_lua_exec, input_isnull)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
char *input = NULL;
L = tsg_lua_vm_create();
@@ -133,7 +133,7 @@ TEST(tsg_lua_exec, input_isnull)
/* check */
EXPECT_EQ(ERR_INPUT_ISNULL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -142,7 +142,7 @@ TEST(tsg_lua_exec, in_len_invaild)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/return_string_normal.lua");
@@ -152,7 +152,7 @@ TEST(tsg_lua_exec, in_len_invaild)
/* check */
EXPECT_EQ(ERR_IN_LEN_INVAILD, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -161,7 +161,7 @@ TEST(tsg_lua_exec, end_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/end_expected.lua");
@@ -171,7 +171,7 @@ TEST(tsg_lua_exec, end_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_END_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -180,7 +180,7 @@ TEST(tsg_lua_exec, then_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/then_expected.lua");
@@ -190,7 +190,7 @@ TEST(tsg_lua_exec, then_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_THEN_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -199,7 +199,7 @@ TEST(tsg_lua_exec, do_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/do_expected.lua");
@@ -209,7 +209,7 @@ TEST(tsg_lua_exec, do_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_DO_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -218,7 +218,7 @@ TEST(tsg_lua_exec, eof_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/eof_expected.lua");
@@ -228,7 +228,7 @@ TEST(tsg_lua_exec, eof_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_EOF_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -237,7 +237,7 @@ TEST(tsg_lua_exec, equal_in_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/equal_in_expected.lua");
@@ -247,7 +247,7 @@ TEST(tsg_lua_exec, equal_in_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_EQUAL_IN_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -256,7 +256,7 @@ TEST(tsg_lua_exec, unexpected_symbol)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/unexpected_symbol.lua");
@@ -266,7 +266,7 @@ TEST(tsg_lua_exec, unexpected_symbol)
/* check */
EXPECT_EQ(ERR_SCRIPT_UNEXPECTED_SYMBOL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -275,7 +275,7 @@ TEST(tsg_lua_exec, name_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/name_expected.lua");
@@ -285,7 +285,7 @@ TEST(tsg_lua_exec, name_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_NAME_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -294,7 +294,7 @@ TEST(tsg_lua_exec, right_curves_bracket_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/right_curves_bracket_expected.lua");
@@ -304,7 +304,7 @@ TEST(tsg_lua_exec, right_curves_bracket_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_RIGHT_CURVES_BRACKET_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -313,7 +313,7 @@ TEST(tsg_lua_exec, right_curly_bracket_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/right_curly_bracket_expected.lua");
@@ -323,7 +323,7 @@ TEST(tsg_lua_exec, right_curly_bracket_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_RIGHT_CURLY_BRACKET_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -332,7 +332,7 @@ TEST(tsg_lua_exec, string_expected_but_nil)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/string_expected_but_nil.lua");
@@ -342,7 +342,7 @@ TEST(tsg_lua_exec, string_expected_but_nil)
/* check */
EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_NIL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -351,7 +351,7 @@ TEST(tsg_lua_exec, string_expected_but_boolean)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/string_expected_but_boolean.lua");
@@ -361,7 +361,7 @@ TEST(tsg_lua_exec, string_expected_but_boolean)
/* check */
EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_BOOL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -370,7 +370,7 @@ TEST(tsg_lua_exec, string_expected_but_table)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/string_expected_but_table.lua");
@@ -380,7 +380,7 @@ TEST(tsg_lua_exec, string_expected_but_table)
/* check */
EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_TABLE, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -389,7 +389,7 @@ TEST(tsg_lua_exec, call_global_but_nil)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/call_global_but_nil.lua");
@@ -399,36 +399,36 @@ TEST(tsg_lua_exec, call_global_but_nil)
/* check */
EXPECT_EQ(ERR_SCRIPT_CALL_GLOBAL_BUT_NIL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
-TEST(tsg_lua_exec, return_too_few)
-{
- tsg_lua_handle L = NULL;
- char out[255];
- size_t out_len = 0;
- size_t out_type = 0;
+// TEST(tsg_lua_exec, return_too_few)
+// {
+// tsg_lua_handle L = NULL;
+// char out[255];
+// size_t out_len = 0;
+// size_t out_type = STRING;
- L = tsg_lua_vm_create();
- const char *script = get_script_buffer("./script/return_too_few.lua");
- memset(out, 0, 255);
- int ret = tsg_lua_exec(L, script, strlen(script), data, strlen(data), out, &out_len, &out_type);
+// L = tsg_lua_vm_create();
+// const char *script = get_script_buffer("./script/return_too_few.lua");
+// memset(out, 0, 255);
+// int ret = tsg_lua_exec(L, script, strlen(script), data, strlen(data), out, &out_len, &out_type);
- /* check */
- EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret);
- EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
- EXPECT_STREQ("", out);
-}
+// /* check */
+// EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret);
+// EXPECT_EQ(0, out_len);
+// EXPECT_EQ(STRING, out_type);
+// EXPECT_STREQ("", out);
+// }
TEST(tsg_lua_exec, return_too_much)
{
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/return_too_much.lua");
@@ -438,16 +438,16 @@ TEST(tsg_lua_exec, return_too_much)
/* check */
EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_MUCH, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
-TEST(tsg_lua_exec, return_type_invaild)
+TEST(tsg_lua_exec, return_type_nil)
{
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/return_type_invaild.lua");
@@ -455,9 +455,9 @@ TEST(tsg_lua_exec, return_type_invaild)
int ret = tsg_lua_exec(L, script, strlen(script), data, strlen(data), out, &out_len, &out_type);
/* check */
- EXPECT_EQ(ERR_SCRIPT_RETURN_TYPE_INVAILD, ret);
- EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(ERR_RETUNR_NIL, ret);
+ EXPECT_EQ(5, out_len);
+ EXPECT_EQ(NIL, out_type);
EXPECT_STREQ("", out);
}
@@ -466,7 +466,7 @@ TEST(tsg_lua_exec, return_length_iszero)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/return_length_iszero.lua");
@@ -476,7 +476,7 @@ TEST(tsg_lua_exec, return_length_iszero)
/* check */
EXPECT_EQ(ERR_SCRIPT_RETURN_LEN_INVAILD, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
#if 0
@@ -485,7 +485,7 @@ TEST(tsg_lua_exec, function_invaild)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/function_invaild.lua");
@@ -495,7 +495,7 @@ TEST(tsg_lua_exec, function_invaild)
/* check */
EXPECT_EQ(ERR_SCRIPT_FUNCTION_INVAILD, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
#endif
@@ -505,7 +505,7 @@ TEST(tsg_lua_exec, sharp)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
memset(out, 0, 255);
diff --git a/gtest/gtest_tsg_lua_exec_bytecode.cpp b/gtest/gtest_tsg_lua_exec_bytecode.cpp
index 0d12b96..2975753 100644
--- a/gtest/gtest_tsg_lua_exec_bytecode.cpp
+++ b/gtest/gtest_tsg_lua_exec_bytecode.cpp
@@ -33,7 +33,7 @@ TEST(tsg_lua_exec_bytecode, normal_return_string)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
memset(out, 0, 255);
@@ -52,7 +52,7 @@ TEST(tsg_lua_exec_bytecode, normal_return_boolean)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = BOOLEAN;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/return_boolean_normal.luajit");
memset(out, 0, 255);
@@ -70,7 +70,7 @@ TEST(tsg_lua_exec_bytecode, normal_return_integer)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = INTEGER;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/return_integer_normal.luajit");
memset(out, 0, 255);
@@ -88,7 +88,7 @@ TEST(tsg_lua_exec_bytecode, lua_vm_isnull)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
const char *script = get_script_buffer("./script/return_string_normal.luajit");
memset(out, 0, sizeof(out));
@@ -97,7 +97,7 @@ TEST(tsg_lua_exec_bytecode, lua_vm_isnull)
/* check */
EXPECT_EQ(ERR_LUAVM_ISNULL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -106,7 +106,7 @@ TEST(tsg_lua_exec_bytecode, script_isnull)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = NULL;
memset(out, 0, 255);
@@ -115,7 +115,7 @@ TEST(tsg_lua_exec_bytecode, script_isnull)
/* check */
EXPECT_EQ(ERR_SCRIPT_ISNULL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -124,7 +124,7 @@ TEST(tsg_lua_exec_bytecode, input_isnull)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
char *input = NULL;
L = tsg_lua_vm_create();
@@ -135,7 +135,7 @@ TEST(tsg_lua_exec_bytecode, input_isnull)
/* check */
EXPECT_EQ(ERR_INPUT_ISNULL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -144,7 +144,7 @@ TEST(tsg_lua_exec_bytecode, in_len_invaild)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/return_string_normal.luajit");
@@ -154,7 +154,7 @@ TEST(tsg_lua_exec_bytecode, in_len_invaild)
/* check */
EXPECT_EQ(ERR_IN_LEN_INVAILD, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -163,7 +163,7 @@ TEST(tsg_lua_exec_bytecode, string_expected_but_nil)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/string_expected_but_nil.luajit");
@@ -173,7 +173,7 @@ TEST(tsg_lua_exec_bytecode, string_expected_but_nil)
/* check */
EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_NIL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -182,7 +182,7 @@ TEST(tsg_lua_exec_bytecode, string_expected_but_boolean)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/string_expected_but_boolean.luajit");
@@ -192,7 +192,7 @@ TEST(tsg_lua_exec_bytecode, string_expected_but_boolean)
/* check */
EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_BOOL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -201,7 +201,7 @@ TEST(tsg_lua_exec_bytecode, string_expected_but_table)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/string_expected_but_table.luajit");
@@ -211,7 +211,7 @@ TEST(tsg_lua_exec_bytecode, string_expected_but_table)
/* check */
EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_TABLE, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -220,7 +220,7 @@ TEST(tsg_lua_exec_bytecode, call_global_but_nil)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/call_global_but_nil.luajit");
@@ -230,36 +230,36 @@ TEST(tsg_lua_exec_bytecode, call_global_but_nil)
/* check */
EXPECT_EQ(ERR_SCRIPT_CALL_GLOBAL_BUT_NIL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
-TEST(tsg_lua_exec_bytecode, return_too_few)
-{
- tsg_lua_handle L = NULL;
- char out[255];
- size_t out_len = 0;
- size_t out_type = 0;
+// TEST(tsg_lua_exec_bytecode, return_too_few)
+// {
+// tsg_lua_handle L = NULL;
+// char out[255];
+// size_t out_len = 0;
+// size_t out_type = STRING;
- L = tsg_lua_vm_create();
- const char *script = get_script_buffer("./script/return_too_few.luajit");
- memset(out, 0, 255);
- int ret = tsg_lua_exec(L, script, script_len, data, strlen(data), out, &out_len, &out_type);
+// L = tsg_lua_vm_create();
+// const char *script = get_script_buffer("./script/return_too_few.luajit");
+// memset(out, 0, 255);
+// int ret = tsg_lua_exec(L, script, script_len, data, strlen(data), out, &out_len, &out_type);
- /* check */
- EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret);
- EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
- EXPECT_STREQ("", out);
-}
+// /* check */
+// EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret);
+// EXPECT_EQ(0, out_len);
+// EXPECT_EQ(STRING, out_type);
+// EXPECT_STREQ("", out);
+// }
TEST(tsg_lua_exec_bytecode, return_too_much)
{
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/return_too_much.luajit");
@@ -269,16 +269,16 @@ TEST(tsg_lua_exec_bytecode, return_too_much)
/* check */
EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_MUCH, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
-TEST(tsg_lua_exec_bytecode, return_type_invaild)
+TEST(tsg_lua_exec_bytecode, return_type_nil)
{
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/return_type_invaild.luajit");
@@ -286,9 +286,9 @@ TEST(tsg_lua_exec_bytecode, return_type_invaild)
int ret = tsg_lua_exec(L, script, script_len, data, strlen(data), out, &out_len, &out_type);
/* check */
- EXPECT_EQ(ERR_SCRIPT_RETURN_TYPE_INVAILD, ret);
- EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(ERR_RETUNR_NIL, ret);
+ EXPECT_EQ(5, out_len);
+ EXPECT_EQ(NIL, out_type);
EXPECT_STREQ("", out);
}
@@ -297,7 +297,7 @@ TEST(tsg_lua_exec_bytecode, return_length_iszero)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = get_script_buffer("./script/return_length_iszero.luajit");
@@ -307,7 +307,7 @@ TEST(tsg_lua_exec_bytecode, return_length_iszero)
/* check */
EXPECT_EQ(ERR_SCRIPT_RETURN_LEN_INVAILD, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -316,7 +316,7 @@ TEST(tsg_lua_exec_bytecode, normal_return_string_sharp)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
memset(out, 0, 255);
diff --git a/gtest/gtest_tsg_lua_exec_bytecode_file.cpp b/gtest/gtest_tsg_lua_exec_bytecode_file.cpp
index 18ae428..f99298c 100644
--- a/gtest/gtest_tsg_lua_exec_bytecode_file.cpp
+++ b/gtest/gtest_tsg_lua_exec_bytecode_file.cpp
@@ -13,7 +13,7 @@ TEST(tsg_lua_exec_bytecode_file, normal_return_string)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_string_normal.luajit";
@@ -32,7 +32,7 @@ TEST(tsg_lua_exec_bytecode_file, normal_return_boolean)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = BOOLEAN;
L = tsg_lua_vm_create();
const char *script = "./script/return_boolean_normal.luajit";
memset(out, 0, 255);
@@ -50,7 +50,7 @@ TEST(tsg_lua_exec_bytecode_file, normal_return_integer)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = INTEGER;
L = tsg_lua_vm_create();
const char *script = "./script/return_integer_normal.luajit";
memset(out, 0, 255);
@@ -68,7 +68,7 @@ TEST(tsg_lua_exec_bytecode_file, lua_vm_isnull)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
const char *script = "./script/return_string_normal.luajit";
memset(out, 0, sizeof(out));
@@ -77,7 +77,7 @@ TEST(tsg_lua_exec_bytecode_file, lua_vm_isnull)
/* check */
EXPECT_EQ(ERR_LUAVM_ISNULL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -86,7 +86,7 @@ TEST(tsg_lua_exec_bytecode_file, script_isnull)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = NULL;
memset(out, 0, 255);
@@ -95,7 +95,7 @@ TEST(tsg_lua_exec_bytecode_file, script_isnull)
/* check */
EXPECT_EQ(ERR_SCRIPT_ISNULL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -104,7 +104,7 @@ TEST(tsg_lua_exec_bytecode_file, input_isnull)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
char *input = NULL;
L = tsg_lua_vm_create();
@@ -115,7 +115,7 @@ TEST(tsg_lua_exec_bytecode_file, input_isnull)
/* check */
EXPECT_EQ(ERR_INPUT_ISNULL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -124,7 +124,7 @@ TEST(tsg_lua_exec_bytecode_file, in_len_invaild)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_string_normal.luajit";
@@ -134,7 +134,7 @@ TEST(tsg_lua_exec_bytecode_file, in_len_invaild)
/* check */
EXPECT_EQ(ERR_IN_LEN_INVAILD, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -143,7 +143,7 @@ TEST(tsg_lua_exec_bytecode_file, string_expected_but_nil)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/string_expected_but_nil.luajit";
@@ -153,7 +153,7 @@ TEST(tsg_lua_exec_bytecode_file, string_expected_but_nil)
/* check */
EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_NIL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -162,7 +162,7 @@ TEST(tsg_lua_exec_bytecode_file, string_expected_but_boolean)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/string_expected_but_boolean.luajit";
@@ -172,7 +172,7 @@ TEST(tsg_lua_exec_bytecode_file, string_expected_but_boolean)
/* check */
EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_BOOL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -181,7 +181,7 @@ TEST(tsg_lua_exec_bytecode_file, string_expected_but_table)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/string_expected_but_table.luajit";
@@ -191,7 +191,7 @@ TEST(tsg_lua_exec_bytecode_file, string_expected_but_table)
/* check */
EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_TABLE, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -200,7 +200,7 @@ TEST(tsg_lua_exec_bytecode_file, call_global_but_nil)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/call_global_but_nil.luajit";
@@ -210,36 +210,36 @@ TEST(tsg_lua_exec_bytecode_file, call_global_but_nil)
/* check */
EXPECT_EQ(ERR_SCRIPT_CALL_GLOBAL_BUT_NIL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
-TEST(tsg_lua_exec_bytecode_file, return_too_few)
-{
- tsg_lua_handle L = NULL;
- char out[255];
- size_t out_len = 0;
- size_t out_type = 0;
+// TEST(tsg_lua_exec_bytecode_file, return_too_few)
+// {
+// tsg_lua_handle L = NULL;
+// char out[255];
+// size_t out_len = 0;
+// size_t out_type = STRING;
- L = tsg_lua_vm_create();
- const char *script = "./script/return_too_few.luajit";
- memset(out, 0, 255);
- int ret = tsg_lua_exec_file(L, script, data, strlen(data), out, &out_len, &out_type);
+// L = tsg_lua_vm_create();
+// const char *script = "./script/return_too_few.luajit";
+// memset(out, 0, 255);
+// int ret = tsg_lua_exec_file(L, script, data, strlen(data), out, &out_len, &out_type);
- /* check */
- EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret);
- EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
- EXPECT_STREQ("", out);
-}
+// /* check */
+// EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret);
+// EXPECT_EQ(0, out_len);
+// EXPECT_EQ(STRING, out_type);
+// EXPECT_STREQ("", out);
+// }
TEST(tsg_lua_exec_bytecode_file, return_too_much)
{
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_too_much.luajit";
@@ -249,7 +249,7 @@ TEST(tsg_lua_exec_bytecode_file, return_too_much)
/* check */
EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_MUCH, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -258,7 +258,7 @@ TEST(tsg_lua_exec_bytecode_file, return_type_invaild)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_type_invaild.luajit";
@@ -266,9 +266,9 @@ TEST(tsg_lua_exec_bytecode_file, return_type_invaild)
int ret = tsg_lua_exec_file(L, script, data, strlen(data), out, &out_len, &out_type);
/* check */
- EXPECT_EQ(ERR_SCRIPT_RETURN_TYPE_INVAILD, ret);
- EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(ERR_RETUNR_NIL, ret);
+ EXPECT_EQ(5, out_len);
+ EXPECT_EQ(NIL, out_type);
EXPECT_STREQ("", out);
}
@@ -277,7 +277,7 @@ TEST(tsg_lua_exec_bytecode_file, return_length_iszero)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_length_iszero.luajit";
@@ -287,7 +287,7 @@ TEST(tsg_lua_exec_bytecode_file, return_length_iszero)
/* check */
EXPECT_EQ(ERR_SCRIPT_RETURN_LEN_INVAILD, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -296,7 +296,7 @@ TEST(tsg_lua_exec_bytecode_file, normal_return_string_sharp)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_string_normal_sharp.luajit";
diff --git a/gtest/gtest_tsg_lua_exec_file.cpp b/gtest/gtest_tsg_lua_exec_file.cpp
index 81fbe5c..041b58d 100644
--- a/gtest/gtest_tsg_lua_exec_file.cpp
+++ b/gtest/gtest_tsg_lua_exec_file.cpp
@@ -14,7 +14,7 @@ TEST(tsg_lua_exec_file, normal_return_string)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_string_normal.lua";
@@ -33,7 +33,7 @@ TEST(tsg_lua_exec_file, normal_return_boolean)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = BOOLEAN;
L = tsg_lua_vm_create();
const char *script = "./script/return_boolean_normal.lua";
memset(out, 0, 255);
@@ -51,7 +51,7 @@ TEST(tsg_lua_exec_file, normal_return_integer)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = INTEGER;
L = tsg_lua_vm_create();
const char *script = "./script/return_integer_normal.lua";
memset(out, 0, 255);
@@ -69,7 +69,7 @@ TEST(tsg_lua_exec_file, lua_vm_isnull)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
const char *script = "./script/return_string_normal.lua";
memset(out, 0, sizeof(out));
@@ -78,7 +78,7 @@ TEST(tsg_lua_exec_file, lua_vm_isnull)
/* check */
EXPECT_EQ(ERR_LUAVM_ISNULL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -87,7 +87,7 @@ TEST(tsg_lua_exec_file, script_isnull)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = NULL;
memset(out, 0, 255);
@@ -96,7 +96,7 @@ TEST(tsg_lua_exec_file, script_isnull)
/* check */
EXPECT_EQ(ERR_SCRIPT_ISNULL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -105,7 +105,7 @@ TEST(tsg_lua_exec_file, input_isnull)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
char *input = NULL;
L = tsg_lua_vm_create();
@@ -116,7 +116,7 @@ TEST(tsg_lua_exec_file, input_isnull)
/* check */
EXPECT_EQ(ERR_INPUT_ISNULL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -125,7 +125,7 @@ TEST(tsg_lua_exec_file, in_len_invaild)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_string_normal.lua";
@@ -135,7 +135,7 @@ TEST(tsg_lua_exec_file, in_len_invaild)
/* check */
EXPECT_EQ(ERR_IN_LEN_INVAILD, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -144,7 +144,7 @@ TEST(tsg_lua_exec_file, end_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/end_expected.lua";
@@ -154,7 +154,7 @@ TEST(tsg_lua_exec_file, end_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_END_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -163,7 +163,7 @@ TEST(tsg_lua_exec_file, then_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/then_expected.lua";
@@ -173,7 +173,7 @@ TEST(tsg_lua_exec_file, then_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_THEN_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -182,7 +182,7 @@ TEST(tsg_lua_exec_file, do_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/do_expected.lua";
@@ -192,7 +192,7 @@ TEST(tsg_lua_exec_file, do_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_DO_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -201,7 +201,7 @@ TEST(tsg_lua_exec_file, eof_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/eof_expected.lua";
@@ -211,7 +211,7 @@ TEST(tsg_lua_exec_file, eof_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_EOF_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -220,7 +220,7 @@ TEST(tsg_lua_exec_file, equal_in_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/equal_in_expected.lua";
@@ -230,7 +230,7 @@ TEST(tsg_lua_exec_file, equal_in_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_EQUAL_IN_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -239,7 +239,7 @@ TEST(tsg_lua_exec_file, unexpected_symbol)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/unexpected_symbol.lua";
@@ -249,7 +249,7 @@ TEST(tsg_lua_exec_file, unexpected_symbol)
/* check */
EXPECT_EQ(ERR_SCRIPT_UNEXPECTED_SYMBOL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -258,7 +258,7 @@ TEST(tsg_lua_exec_file, name_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/name_expected.lua";
@@ -268,7 +268,7 @@ TEST(tsg_lua_exec_file, name_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_NAME_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -277,7 +277,7 @@ TEST(tsg_lua_exec_file, right_curves_bracket_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/right_curves_bracket_expected.lua";
@@ -287,7 +287,7 @@ TEST(tsg_lua_exec_file, right_curves_bracket_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_RIGHT_CURVES_BRACKET_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -296,7 +296,7 @@ TEST(tsg_lua_exec_file, right_curly_bracket_expected)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/right_curly_bracket_expected.lua";
@@ -306,7 +306,7 @@ TEST(tsg_lua_exec_file, right_curly_bracket_expected)
/* check */
EXPECT_EQ(ERR_SCRIPT_RIGHT_CURLY_BRACKET_EXPECTED, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -315,7 +315,7 @@ TEST(tsg_lua_exec_file, string_expected_but_nil)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/string_expected_but_nil.lua";
@@ -325,7 +325,7 @@ TEST(tsg_lua_exec_file, string_expected_but_nil)
/* check */
EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_NIL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -334,7 +334,7 @@ TEST(tsg_lua_exec_file, string_expected_but_boolean)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/string_expected_but_boolean.lua";
@@ -344,7 +344,7 @@ TEST(tsg_lua_exec_file, string_expected_but_boolean)
/* check */
EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_BOOL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -353,7 +353,7 @@ TEST(tsg_lua_exec_file, string_expected_but_table)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/string_expected_but_table.lua";
@@ -363,7 +363,7 @@ TEST(tsg_lua_exec_file, string_expected_but_table)
/* check */
EXPECT_EQ(ERR_SCRIPT_STRING_EXPECTED_BUT_TABLE, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
@@ -372,7 +372,7 @@ TEST(tsg_lua_exec_file, call_global_but_nil)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/call_global_but_nil.lua";
@@ -382,36 +382,36 @@ TEST(tsg_lua_exec_file, call_global_but_nil)
/* check */
EXPECT_EQ(ERR_SCRIPT_CALL_GLOBAL_BUT_NIL, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
-TEST(tsg_lua_exec_file, return_too_few)
-{
- tsg_lua_handle L = NULL;
- char out[255];
- size_t out_len = 0;
- size_t out_type = 0;
+// TEST(tsg_lua_exec_file, return_too_few)
+// {
+// tsg_lua_handle L = NULL;
+// char out[255];
+// size_t out_len = 0;
+// size_t out_type = STRING;
- L = tsg_lua_vm_create();
- const char *script = "./script/return_too_few.lua";
- memset(out, 0, 255);
- int ret = tsg_lua_exec_file(L, script, data, strlen(data), out, &out_len, &out_type);
+// L = tsg_lua_vm_create();
+// const char *script = "./script/return_too_few.lua";
+// memset(out, 0, 255);
+// int ret = tsg_lua_exec_file(L, script, data, strlen(data), out, &out_len, &out_type);
- /* check */
- EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret);
- EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
- EXPECT_STREQ("", out);
-}
+// /* check */
+// EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_FEW, ret);
+// EXPECT_EQ(0, out_len);
+// EXPECT_EQ(STRING, out_type);
+// EXPECT_STREQ("", out);
+// }
TEST(tsg_lua_exec_file, return_too_much)
{
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_too_much.lua";
@@ -421,16 +421,16 @@ TEST(tsg_lua_exec_file, return_too_much)
/* check */
EXPECT_EQ(ERR_SCRIPT_RETURN_TOO_MUCH, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
-TEST(tsg_lua_exec_file, return_type_invaild)
+TEST(tsg_lua_exec_file, return_type_nil)
{
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_type_invaild.lua";
@@ -438,9 +438,9 @@ TEST(tsg_lua_exec_file, return_type_invaild)
int ret = tsg_lua_exec_file(L, script, data, strlen(data), out, &out_len, &out_type);
/* check */
- EXPECT_EQ(ERR_SCRIPT_RETURN_TYPE_INVAILD, ret);
- EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(ERR_RETUNR_NIL, ret);
+ EXPECT_EQ(5, out_len);
+ EXPECT_EQ(NIL, out_type);
EXPECT_STREQ("", out);
}
@@ -449,7 +449,7 @@ TEST(tsg_lua_exec_file, return_length_iszero)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_length_iszero.lua";
@@ -459,7 +459,7 @@ TEST(tsg_lua_exec_file, return_length_iszero)
/* check */
EXPECT_EQ(ERR_SCRIPT_RETURN_LEN_INVAILD, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
#if 0
@@ -468,7 +468,7 @@ TEST(tsg_lua_exec_file, function_invaild)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/function_invaild.lua";
@@ -478,7 +478,7 @@ TEST(tsg_lua_exec_file, function_invaild)
/* check */
EXPECT_EQ(ERR_SCRIPT_FUNCTION_INVAILD, ret);
EXPECT_EQ(0, out_len);
- EXPECT_EQ(0, out_type);
+ EXPECT_EQ(STRING, out_type);
EXPECT_STREQ("", out);
}
#endif
@@ -488,7 +488,7 @@ TEST(tsg_lua_exec_file, normal_return_string_sharp)
tsg_lua_handle L = NULL;
char out[255];
size_t out_len = 0;
- size_t out_type = 0;
+ size_t out_type = STRING;
L = tsg_lua_vm_create();
const char *script = "./script/return_string_normal_sharp.lua";
diff --git a/gtest/script/handle_qqnum.lua b/gtest/script/handle_qqnum.lua
index fc0d1a4..4994536 100644
--- a/gtest/script/handle_qqnum.lua
+++ b/gtest/script/handle_qqnum.lua
@@ -27,28 +27,28 @@ end
-- 命中特征"\0\0\0\0"
local _, _end = string.find(data, "\0\0\0\0")
if not _end then
- return 1, false
+ return false
end
-- 获取qqnum长度
local qqnum_len = string.byte(data, _end + 1)
if not qqnum_len then
- return 1,false
+ return false
end
locate = _end + 1
qqnum_len = qqnum_len - 4
-- 判断qqnum长度的合法性
if qqnum_len > 12 or qqnum_len > (data_len - locate) then
- return 1, false
+ return false
end
locate = locate + 1
-- 获取qqnum
local qqnum = string.sub(data, locate, locate + qqnum_len - 1)
if not qqnum then
- return 1, false
+ return false
end
-- 验证qqnum由全数字组成
if not tonumber(qqnum) then
- return 1, false
+ return false
end
return qqnum_len, qqnum
diff --git a/gtest/script/handle_weixinnum.lua b/gtest/script/handle_weixinnum.lua
index 1b8b448..e1b6db5 100644
--- a/gtest/script/handle_weixinnum.lua
+++ b/gtest/script/handle_weixinnum.lua
@@ -18,23 +18,23 @@ local locate = 0 -- 字符串中当前正在处理的位置
-- 查找字符串weixinnum位置
local _start, _end = string.find(data, feature)
if not _end then
- return 1, false
+ return false
end
-- 获取weixinnum数值字符串长度
-- weixinnum数值字符串长度不超过12,所以前三位必须为0
if ((string.byte(data, _end + 1) ~= 0) or (string.byte(data, _end + 2) ~=0 ) or (string.byte(data, _end + 3) ~= 0)) then
- return 1, false
+ return false
end
local weixinnum_len = string.byte(data, _end + offset)
if not weixinnum_len then
- return 1, false
+ return false
end
locate = _end + offset
-- 判断weixinnum数值字符串长度的合法性
if weixinnum_len > data_len - _end - offset or weixinnum_len > max_weixinnum_len then
- return 1, false
+ return false
end
-- 获取weixinnum数值字符串
@@ -43,5 +43,5 @@ local weixinnum = string.sub(data, locate + 1, locate + weixinnum_len)
if tonumber(weixinnum) then
return weixinnum_len, weixinnum
else
- return 1, false
+ return false
end
diff --git a/gtest/script/return_boolean_normal.lua b/gtest/script/return_boolean_normal.lua
index fbf1fbf..5856cc4 100644
--- a/gtest/script/return_boolean_normal.lua
+++ b/gtest/script/return_boolean_normal.lua
@@ -1,6 +1,6 @@
local str = TSG.data
local s_index, e_index = string.find(str, 'hello')
if s_index then
- return 1, true
-else return 1, false
+ return true
+else return false
end
diff --git a/gtest/script/return_boolean_normal.luajit b/gtest/script/return_boolean_normal.luajit
index 9bbbfbb..215e3f9 100644
--- a/gtest/script/return_boolean_normal.luajit
+++ b/gtest/script/return_boolean_normal.luajit
Binary files differ
diff --git a/gtest/script/return_integer_normal.lua b/gtest/script/return_integer_normal.lua
index ccb38fe..9c64643 100644
--- a/gtest/script/return_integer_normal.lua
+++ b/gtest/script/return_integer_normal.lua
@@ -1,7 +1,7 @@
local str = TSG.data
local s_index, e_index = string.find(str, 'world')
if s_index then
- return 8, s_index
+ return s_index
else
- return 1, false
+ return false
end
diff --git a/gtest/script/return_integer_normal.luajit b/gtest/script/return_integer_normal.luajit
index 3abd850..6dac219 100644
--- a/gtest/script/return_integer_normal.luajit
+++ b/gtest/script/return_integer_normal.luajit
Binary files differ
diff --git a/gtest/script/return_type_invaild.lua b/gtest/script/return_type_invaild.lua
index 2d4e33e..89fcb65 100644
--- a/gtest/script/return_type_invaild.lua
+++ b/gtest/script/return_type_invaild.lua
@@ -1,2 +1,2 @@
local str = "hello"
-return string.len(str), nil
+return string.len(str), nil
diff --git a/include/tsg_lua_interface.h b/include/tsg_lua_interface.h
index 20ca0c3..8cf4cae 100644
--- a/include/tsg_lua_interface.h
+++ b/include/tsg_lua_interface.h
@@ -8,6 +8,7 @@
enum type
{
+ NIL = 0,
STRING = 1,
INTEGER,
BOOLEAN,
@@ -70,7 +71,8 @@ tsg_lua_handle tsg_lua_vm_create();
* 输出参数:
* char *out 输出结果
* size_t *out_len 输出结果的长度
- * size_t *out_type 输出结果的类型
+ * 输入输出参数:
+ * size_t *out_type 要求输入一个不为NIL的预期类型, 调用完成后会输出结果的类型
* 返回值: int 成功,返回0;失败返回错误值err_value */
int tsg_lua_exec(tsg_lua_handle L, const char *script, size_t script_len, const char *in, size_t in_len, char *out, size_t *out_len, size_t *out_type);
@@ -82,7 +84,8 @@ int tsg_lua_exec(tsg_lua_handle L, const char *script, size_t script_len, const
* 输出参数:
* char *out 输出结果
* size_t *out_len 输出结果的长度
- * size_t *out_type 输出结果的类型
+ * 输入输出参数:
+ * size_t *out_type 要求输入一个不为NIL的预期类型, 调用完成后会输出结果的类型
* 返回值: int 成功,返回0;失败返回错误值err_value */
int tsg_lua_exec_file(tsg_lua_handle L, const char *script, const char *in, size_t in_len, char *out, size_t *out_len, size_t *out_type);
@@ -114,7 +117,8 @@ int tsg_lua_uncache_script(tsg_lua_handle L, size_t script_id);
* size_t in_len 输入待处理的数据的长度
* 输出参数: char *out 输出结果
* size_t *out_len 输出结果的长度
- * size_t *out_type 输出结果的类型
+ * 输入输出参数:
+ * size_t *out_type 要求输入一个不为NIL的预期类型, 调用完成后会输出结果的类型
* 返回值: int 成功,返回0;失败,返回错误值err_value */
int tsg_lua_cache_exec(tsg_lua_handle L, size_t script_id, const char *in, size_t in_len, char *out, size_t *out_len, size_t *out_type);
diff --git a/src/tsg_lua_func.cpp b/src/tsg_lua_func.cpp
index a24859b..4a95ab1 100644
--- a/src/tsg_lua_func.cpp
+++ b/src/tsg_lua_func.cpp
@@ -513,6 +513,7 @@ int tsg_lua_exec_file(tsg_lua_handle lua, const char *script, const char *in, si
int sharp = 0;
tsg_lua_clfactory_file_t lf;
jmp_buf *lua_exception;
+ int return_value = 0;
if (L == NULL)
{
@@ -537,6 +538,12 @@ int tsg_lua_exec_file(tsg_lua_handle lua, const char *script, const char *in, si
return ERR_IN_LEN_INVAILD;
}
+ if (out_type == NULL || *out_type < STRING || *out_type > BOOLEAN)
+ {
+ debuginfo("out_type is invailed", __FILE__, __LINE__);
+ return ERR_EXPECT_TYPE_IS_NIL;
+ }
+
lua_exception = (jmp_buf *)lua_getexdata(L);
lf.extraline = 0;
@@ -666,41 +673,53 @@ int tsg_lua_exec_file(tsg_lua_handle lua, const char *script, const char *in, si
return ERR_SCRIPT_EXEC_ERROR;
}
int num = lua_gettop(L);
- if (num < 2)
+ if (num == 0)
{
- char err_buf[255];
- sprintf((char *)err_buf,"num:%d", num);
- debuginfo(err_buf, __FILE__, __LINE__);
- return ERR_SCRIPT_RETURN_TOO_FEW;
+ //没有返回任何内容
+ debuginfo("script return nothing", __FILE__, __LINE__);
+ return ERR_RETURN_TYPE_NOT_MATCH_EXPECT;
+ }
+ else if (num == 2)
+ {
+ *out_len = lua_tonumber(L, -2);
+ if (*out_len < 1)
+ {
+ debuginfo("script out_len is 0", __FILE__, __LINE__);
+ return ERR_SCRIPT_RETURN_LEN_INVAILD;
+ }
}
- if (num > 2)
+ else if (num > 2)
{
char err_buf[255];
sprintf((char *)err_buf,"num:%d", num);
debuginfo(err_buf, __FILE__, __LINE__);
return ERR_SCRIPT_RETURN_TOO_MUCH;
}
- *out_len = lua_tonumber(L, -2);
- if (*out_len < 1)
- {
- debuginfo("script out_len is 0", __FILE__, __LINE__);
- return ERR_SCRIPT_RETURN_LEN_INVAILD;
- }
- switch(lua_type(L, -1))
+
+ size_t lua_ret_type = lua_type(L, -1);
+ size_t actual_out_type = NIL;
+
+ switch(lua_ret_type)
{
+ case LUA_TNIL:
+ debuginfo("script return nil", __FILE__, __LINE__);
+ actual_out_type = NIL;
+ *out_type = NIL;
+ return_value = ERR_RETUNR_NIL;
+ break;
case LUA_TSTRING:
memcpy(out, lua_tostring(L, -1), *out_len);
- *out_type = STRING;
+ actual_out_type = STRING;
break;
case LUA_TBOOLEAN:
out[0] = lua_toboolean(L, -1);
- //*out_len = 1;
- *out_type = BOOLEAN;
+ *out_len = 1;
+ actual_out_type = BOOLEAN;
break;
case LUA_TNUMBER:
*(long *)out = lua_tointeger(L, -1);
- //*out_len = 8;
- *out_type = INTEGER;
+ *out_len = 8;
+ actual_out_type = INTEGER;
break;
default:
char err_buf[255];
@@ -709,12 +728,20 @@ int tsg_lua_exec_file(tsg_lua_handle lua, const char *script, const char *in, si
*out_len = 0;
return ERR_SCRIPT_RETURN_TYPE_INVAILD;
}
+ if (actual_out_type != *out_type && actual_out_type != NIL)
+ {
+ char err_buf[255];
+ sprintf((char *)err_buf, "expect out_type is:%zu, actual out_type is:%zu", *out_type, actual_out_type);
+ debuginfo(err_buf, __FILE__, __LINE__);
+ *out_type = actual_out_type;
+ return_value = ERR_RETURN_TYPE_NOT_MATCH_EXPECT;
+ }
}else
{
return ERR_SCRIPT_EXEC_ERROR;
}
- return 0;
+ return return_value;
}
@@ -727,6 +754,7 @@ int tsg_lua_exec(tsg_lua_handle lua, const char *script, size_t script_len, cons
int sharp = 0;
tsg_lua_clfactory_buffer_t ls;
jmp_buf *lua_exception;
+ int return_value = 0;
memset(&ls, 0, sizeof(tsg_lua_clfactory_buffer_t));
@@ -753,6 +781,12 @@ int tsg_lua_exec(tsg_lua_handle lua, const char *script, size_t script_len, cons
return ERR_IN_LEN_INVAILD;
}
+ if (out_type == NULL || *out_type < STRING || *out_type > BOOLEAN)
+ {
+ debuginfo("out_type is invailed", __FILE__, __LINE__);
+ return ERR_EXPECT_TYPE_IS_NIL;
+ }
+
lua_exception = (jmp_buf *)lua_getexdata(L);
ls.s = script;
@@ -866,41 +900,53 @@ int tsg_lua_exec(tsg_lua_handle lua, const char *script, size_t script_len, cons
return ERR_SCRIPT_EXEC_ERROR;
}
int num = lua_gettop(L);
- if (num < 2)
+ if (num == 0)
{
- char err_buf[255];
- sprintf((char *)err_buf, "num:%d", num);
- debuginfo(err_buf, __FILE__, __LINE__);
- return ERR_SCRIPT_RETURN_TOO_FEW;
+ //没有返回任何内容
+ debuginfo("script return nothing", __FILE__, __LINE__);
+ return ERR_RETURN_TYPE_NOT_MATCH_EXPECT;
}
- if (num > 2)
+ else if (num == 2)
+ {
+ *out_len = lua_tonumber(L, -2);
+ if (*out_len < 1)
+ {
+ debuginfo("script out_len is 0", __FILE__, __LINE__);
+ return ERR_SCRIPT_RETURN_LEN_INVAILD;
+ }
+ }
+ else if (num > 2)
{
char err_buf[255];
sprintf((char *)err_buf, "num:%d", num);
debuginfo(err_buf, __FILE__, __LINE__);
return ERR_SCRIPT_RETURN_TOO_MUCH;
}
- *out_len = lua_tonumber(L, -2);
- if (*out_len < 1)
- {
- debuginfo("script out_len is 0", __FILE__, __LINE__);
- return ERR_SCRIPT_RETURN_LEN_INVAILD;
- }
- switch(lua_type(L, -1))
+
+ size_t lua_ret_type = lua_type(L, -1);
+ size_t actual_out_type = NIL;
+
+ switch(lua_ret_type)
{
+ case LUA_TNIL:
+ debuginfo("script return nil", __FILE__, __LINE__);
+ *out_type = NIL;
+ actual_out_type = NIL;
+ return_value = ERR_RETUNR_NIL;
+ break;
case LUA_TSTRING:
memcpy(out, lua_tostring(L, -1), *out_len);
- *out_type = STRING;
+ actual_out_type = STRING;
break;
case LUA_TBOOLEAN:
out[0] = lua_toboolean(L, -1);
- //*out_len = 1;
- *out_type = BOOLEAN;
+ *out_len = 1;
+ actual_out_type = BOOLEAN;
break;
case LUA_TNUMBER:
*(size_t *)out = lua_tointeger(L, -1);
- //*out_len = 8;
- *out_type = INTEGER;
+ *out_len = 8;
+ actual_out_type = INTEGER;
break;
default:
char err_buf[255];
@@ -909,12 +955,20 @@ int tsg_lua_exec(tsg_lua_handle lua, const char *script, size_t script_len, cons
*out_len = 0;
return ERR_SCRIPT_RETURN_TYPE_INVAILD;
}
+
+ if (actual_out_type != *out_type && actual_out_type != NIL)
+ {
+ char err_buf[255];
+ sprintf((char *)err_buf, "expect out_type is:%zu, actual out_type is:%zu ", *out_type, actual_out_type);
+ debuginfo(err_buf, __FILE__, __LINE__);
+ return_value = ERR_RETURN_TYPE_NOT_MATCH_EXPECT;
+ }
}else
{
return ERR_SCRIPT_EXEC_ERROR;
}
- return 0;
+ return return_value;
}
int tsg_lua_cache_script(tsg_lua_handle lua, const char *script, size_t script_len)
@@ -1191,6 +1245,7 @@ int tsg_lua_cache_exec(tsg_lua_handle lua, size_t script_id, const char *in, siz
{
lua_State *L = (lua_State *)lua;
jmp_buf *lua_exception;
+ int return_value = 0;
if (L == NULL)
{
@@ -1212,6 +1267,11 @@ int tsg_lua_cache_exec(tsg_lua_handle lua, size_t script_id, const char *in, siz
debuginfo("in_len is invailed", __FILE__, __LINE__);
return ERR_IN_LEN_INVAILD;
}
+ if (out_type == NULL || *out_type < STRING || *out_type > BOOLEAN)
+ {
+ debuginfo("out_type is invailed", __FILE__, __LINE__);
+ return ERR_EXPECT_TYPE_IS_NIL;
+ }
lua_settop(L, 0);
lua_exception = (jmp_buf *)lua_getexdata(L);
@@ -1236,14 +1296,22 @@ int tsg_lua_cache_exec(tsg_lua_handle lua, size_t script_id, const char *in, siz
return ERR_SCRIPT_EXEC_ERROR;
}
int num = lua_gettop(L);
- if (num < 2)
+ if (num == 0)
{
- char err_buf[255];
- sprintf((char *)err_buf,"num:%d", num);
- debuginfo(err_buf, __FILE__, __LINE__);
- return ERR_SCRIPT_RETURN_TOO_FEW;
+ //没有返回任何内容
+ debuginfo("script return nothing", __FILE__, __LINE__);
+ return ERR_RETURN_TYPE_NOT_MATCH_EXPECT;
}
- if (num > 2)
+ else if (num == 2)
+ {
+ *out_len = lua_tonumber(L, -2);
+ if (*out_len < 1)
+ {
+ debuginfo("script out_len is 0", __FILE__, __LINE__);
+ return ERR_SCRIPT_RETURN_LEN_INVAILD;
+ }
+ }
+ else if (num > 2)
{
char err_buf[255];
sprintf((char *)err_buf,"num:%d", num);
@@ -1251,27 +1319,30 @@ int tsg_lua_cache_exec(tsg_lua_handle lua, size_t script_id, const char *in, siz
return ERR_SCRIPT_RETURN_TOO_MUCH;
}
- *out_len = lua_tonumber(L, -2);
- if (*out_len < 1)
- {
- debuginfo("script out_len is 0", __FILE__, __LINE__);
- return ERR_SCRIPT_RETURN_LEN_INVAILD;
- }
- switch(lua_type(L, -1))
+ size_t lua_ret_type = lua_type(L, -1);
+ size_t actual_ret_type = 0;
+
+ switch(lua_ret_type)
{
+ case LUA_TNIL:
+ debuginfo("script return nil", __FILE__, __LINE__);
+ *out_type = NIL;
+ actual_ret_type = NIL;
+ return_value = ERR_RETUNR_NIL;
+ break;
case LUA_TSTRING:
memcpy(out, lua_tostring(L, -1), *out_len);
- *out_type = STRING;
- break;
+ actual_ret_type = STRING;
+ break;
case LUA_TBOOLEAN:
out[0] = lua_toboolean(L, -1);
- //*out_len = 1;
- *out_type = BOOLEAN;
+ *out_len = 1;
+ actual_ret_type = BOOLEAN;
break;
case LUA_TNUMBER:
*(size_t *)out = lua_tointeger(L, -1);
- //*out_len = 8;
- *out_type = INTEGER;
+ *out_len = 8;
+ actual_ret_type = INTEGER;
break;
default:
char err_buf[255];
@@ -1280,12 +1351,21 @@ int tsg_lua_cache_exec(tsg_lua_handle lua, size_t script_id, const char *in, siz
*out_len = 0;
return ERR_SCRIPT_RETURN_TYPE_INVAILD;
}
+
+ if (actual_ret_type != *out_type && actual_ret_type != NIL)
+ {
+ char err_buf[255];
+ sprintf((char *)err_buf, "expect out_type is:%zu, actual out_type is:%zu ", *out_type, actual_ret_type);
+ debuginfo(err_buf, __FILE__, __LINE__);
+ return_value = ERR_RETURN_TYPE_NOT_MATCH_EXPECT;
+ }
+
}else
{
return ERR_SCRIPT_EXEC_ERROR;
}
- return 0;
+ return return_value;
}
int tsg_destory_lua(tsg_lua_handle lua)
diff --git a/src/tsg_lua_interface.h b/src/tsg_lua_interface.h
index ae12b73..9c1f580 100644
--- a/src/tsg_lua_interface.h
+++ b/src/tsg_lua_interface.h
@@ -8,6 +8,7 @@
enum type
{
+ NIL = 0,
STRING = 1,
INTEGER,
BOOLEAN,
@@ -50,8 +51,11 @@ enum err_value
ERR_SCRIPT_ID_INVAILD = -33, /* 脚本ID无效 */
ERR_LUA_CACHE_FAILED = -34, /* 脚本缓存失败 */
ERR_MEM_NOT_ENOUGH = -35, /* 空间不足 */
- ERR_LUA_ID = -36, /* lua id 错误*/
- ERR_UNKNOWN = -37, /* 未知错误 */
+ ERR_LUA_ID = -36, /* lua id 错误*/
+ ERR_EXPECT_TYPE_IS_NIL = -37, /* 预期脚本返回类型为空 */
+ ERR_UNKNOWN = -38, /* 未知错误 */
+ ERR_RETUNR_NIL = 1, /* 脚本执行成功,但是返回空*/
+ ERR_RETURN_TYPE_NOT_MATCH_EXPECT = 2, /* 脚本执行成功,但是返回值类型与预期不符 */
};
typedef void* tsg_lua_handle;
@@ -70,7 +74,8 @@ tsg_lua_handle tsg_lua_vm_create();
* 输出参数:
* char *out 输出结果
* size_t *out_len 输出结果的长度
- * size_t *out_type 输出结果的类型
+ * 输入输出参数:
+ * size_t *out_type 要求输入一个不为NIL的预期类型, 调用完成后会输出结果的类型
* 返回值: int 成功,返回0;失败返回错误值err_value */
int tsg_lua_exec(tsg_lua_handle L, const char *script, size_t script_len, const char *in, size_t in_len, char *out, size_t *out_len, size_t *out_type);
@@ -82,7 +87,8 @@ int tsg_lua_exec(tsg_lua_handle L, const char *script, size_t script_len, const
* 输出参数:
* char *out 输出结果
* size_t *out_len 输出结果的长度
- * size_t *out_type 输出结果的类型
+ * 输入输出参数:
+ * size_t *out_type 要求输入一个不为NIL的预期类型, 调用完成后会输出结果的类型
* 返回值: int 成功,返回0;失败返回错误值err_value */
int tsg_lua_exec_file(tsg_lua_handle L, const char *script, const char *in, size_t in_len, char *out, size_t *out_len, size_t *out_type);
@@ -114,7 +120,8 @@ int tsg_lua_uncache_script(tsg_lua_handle L, size_t script_id);
* size_t in_len 输入待处理的数据的长度
* 输出参数: char *out 输出结果
* size_t *out_len 输出结果的长度
- * size_t *out_type 输出结果的类型
+ * 输入输出参数:
+ * size_t *out_type 要求输入一个不为NIL的预期类型, 调用完成后会输出结果的类型
* 返回值: int 成功,返回0;失败,返回错误值err_value */
int tsg_lua_cache_exec(tsg_lua_handle L, size_t script_id, const char *in, size_t in_len, char *out, size_t *out_len, size_t *out_type);