From 229a3937a3b99a175b551e28d09b9a45d37c44f7 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 9 Sep 2020 20:09:27 +0800 Subject: *misc --- src/01-coroutine/main.cpp | 17 +++++++++++++++++ src/01-coroutine/test.lua | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src/01-coroutine') 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) -- cgit v1.1-26-g67d0