summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author“pengxuanzheng” <[email protected]>2022-07-19 07:00:35 +0000
committer“pengxuanzheng” <[email protected]>2022-07-19 07:36:03 +0000
commita51a298b5a7e5067873b7854687b3ead6d13d8b7 (patch)
tree9c60776971d58be129e53a64131b9095b19ba5ce
parented86120fa4072ce922550ae1304e889e15694ef6 (diff)
✨ feat(TSG-11154): 增加remove命令,可以用来移除特定的lua API
-rw-r--r--gtest/CMakeLists.txt2
-rw-r--r--gtest/gtest_lua_remove_cmd.cpp17
-rw-r--r--gtest/script/remove_print.lua5
-rw-r--r--src/tsg_lua_func.cpp15
-rw-r--r--src/tsg_lua_interface.h3
5 files changed, 41 insertions, 1 deletions
diff --git a/gtest/CMakeLists.txt b/gtest/CMakeLists.txt
index fda6e7d..58b0efa 100644
--- a/gtest/CMakeLists.txt
+++ b/gtest/CMakeLists.txt
@@ -11,7 +11,7 @@ link_libraries(tsglua gtest gtest_main pthread)
add_definitions(-g -W -Wall)
add_executable(gtest_tsg_lua ${SRCS})
-#add_executable(gtest_tsg_lua_exec_with_context ./gtest_tsg_lua_exec_with_context.cpp)
+# add_executable(gtest_lua_remove_cmd ./gtest_lua_remove_cmd.cpp)
add_dependencies(gtest_tsg_lua ${lib_name}_shared gtest)
#target_link_libraries(gtest_tsg_lua tsglua gtest gtest_main pthread)
diff --git a/gtest/gtest_lua_remove_cmd.cpp b/gtest/gtest_lua_remove_cmd.cpp
new file mode 100644
index 0000000..df0c5f1
--- /dev/null
+++ b/gtest/gtest_lua_remove_cmd.cpp
@@ -0,0 +1,17 @@
+#include <gtest/gtest.h>
+#include "tsg_lua_interface.h"
+
+TEST(lua_remove_cmd, normal)
+{
+ tsg_lua_handle L = tsg_lua_vm_create_with_name("TEST");
+ ASSERT_TRUE(L);
+
+ lua_remove_cmd(L, "print");
+
+ char out[1204];
+ size_t len = 1024;
+ size_t type = STRING;
+ int ret = tsg_lua_exec_file(L, "./script/remove_print.lua", "remove print", strlen("remove print"), out, &len, &type);
+ EXPECT_EQ(ret, ERR_SCRIPT_EXEC_ERROR);
+
+} \ No newline at end of file
diff --git a/gtest/script/remove_print.lua b/gtest/script/remove_print.lua
new file mode 100644
index 0000000..1fc5dd8
--- /dev/null
+++ b/gtest/script/remove_print.lua
@@ -0,0 +1,5 @@
+local data = TSG.data
+
+print(data)
+
+return string.len(data), data \ No newline at end of file
diff --git a/src/tsg_lua_func.cpp b/src/tsg_lua_func.cpp
index 463942c..09d5ba0 100644
--- a/src/tsg_lua_func.cpp
+++ b/src/tsg_lua_func.cpp
@@ -1793,4 +1793,19 @@ int lua_get_error_code(tsg_lua_handle L)
struct lua_private_info_t *lua_info = (struct lua_private_info_t *)lua_getexdata(L);
return lua_info->errcode;
+}
+
+int lua_remove_cmd(tsg_lua_handle L, const char *cmd)
+{
+ if (L == NULL || cmd == NULL)
+ {
+ return ERR_PARAMETER;
+ }
+
+ lua_pushnil(L);
+ lua_setglobal(L, cmd);
+
+ lua_settop(L, 0);
+
+ return 0;
} \ No newline at end of file
diff --git a/src/tsg_lua_interface.h b/src/tsg_lua_interface.h
index 5e97328..7e2c250 100644
--- a/src/tsg_lua_interface.h
+++ b/src/tsg_lua_interface.h
@@ -5,6 +5,7 @@
************************************************************************/
#ifndef __TSG_LUA_INTERFACE__
#define __TSG_LUA_INTERFACE__
+#include <stddef.h>
enum type
{
@@ -232,4 +233,6 @@ int lua_exec_file(tsg_lua_handle L, const char *script, struct lua_data_t in, vo
tsg_lua_handle tsg_lua_vm_create_with_name(const char *name);
int lua_get_error_code(tsg_lua_handle L);
+
+int lua_remove_cmd(tsg_lua_handle L, const char *cmd);
#endif