summaryrefslogtreecommitdiff
path: root/src/01-coroutine
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-09-09 20:09:27 +0800
committerchai <chaifix@163.com>2020-09-09 20:09:27 +0800
commit229a3937a3b99a175b551e28d09b9a45d37c44f7 (patch)
tree3dce1ff5cbb81fe9d6a774c77878a48146ead8d0 /src/01-coroutine
parent77ac95b9985f5669d6659bfb54728786d28c2ef0 (diff)
*misc
Diffstat (limited to 'src/01-coroutine')
-rw-r--r--src/01-coroutine/main.cpp17
-rw-r--r--src/01-coroutine/test.lua3
2 files changed, 19 insertions, 1 deletions
diff --git a/src/01-coroutine/main.cpp b/src/01-coroutine/main.cpp
index 8187f6b..20bae2f 100644
--- a/src/01-coroutine/main.cpp
+++ b/src/01-coroutine/main.cpp
@@ -34,7 +34,24 @@ static int l_GetChar(lua_State* L)
return 1;
}
+static int __gc(lua_State* L)
+{
+ return 0;
+}
+
+static int l_createObj(lua_State* L)
+{
+ int* u = (int*)lua_newuserdata(L, sizeof(int));
+ lua_newtable(L);
+ lua_pushstring(L, "__gc");
+ lua_pushcfunction(L, __gc);
+ lua_rawset(L, -3);
+ lua_setmetatable(L, -2);
+ return 1;
+}
+
luaL_reg fns[] = {
+ { "createObj", l_createObj },
{"GetTime", l_GetTime } ,
{"Sleep", l_Sleep } ,
{"Kbhit", l_Kbhit },
diff --git a/src/01-coroutine/test.lua b/src/01-coroutine/test.lua
index 8735082..650433d 100644
--- a/src/01-coroutine/test.lua
+++ b/src/01-coroutine/test.lua
@@ -100,7 +100,8 @@ local function main()
local cur = GetTime()
dt = cur - pre
pre = cur
-
+ local a = createObj()
+ a = nil
GetInput()
watchdog:Update(dt)