Added test for defer

This commit is contained in:
2023-11-26 22:13:18 -05:00
parent f07b1ebb57
commit 42b4e0fcf4
5 changed files with 39 additions and 3 deletions
+12 -2
View File
@@ -137,9 +137,19 @@ local function INIT(__GlobalLinda, __SleepingLinda, __StatusLinda, __Console)
end
end
function THREAD.defer(func)
local m = {onexit = function() func() end}
if _VERSION >= "Lua 5.2" then
setmetatable(m, {__gc = m.onexit})
else
m.sentinel = newproxy(true)
getmetatable(m.sentinel).__gc = m.onexit
end
end
return GLOBAL, THREAD
end
return {init = function(g,s,st,c)
return INIT(g,s,st,c)
return {init = function(g,s,st,c,onexit)
return INIT(g,s,st,c,onexit)
end}
+4
View File
@@ -152,6 +152,10 @@ function INIT()
end
end
function THREAD.defer(func)
multi.OnExit(func)
end
return GLOBAL, THREAD
end
+2
View File
@@ -88,6 +88,8 @@ local function INIT(thread)
THREAD.sleep = thread.sleep
THREAD.hold = thread.hold
THREAD.defer = thread.defer
function THREAD.setENV(env, name)
name = name or "__env"