lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Fixed a bug.  The os.atexit() functions where being called after a full GC.

-- 
Robert G. Jakabosky
local exit_list={}
local exit=os.exit
local function cleanup()
	-- call atexit functions in reverse order
	for x=#exit_list,1,-1 do
		local func = exit_list[x]
		func()
		exit_list[x] = nil
	end
end
-- catch normal exit.
local gc=newproxy(true)
exit_list.gc = gc
gc=getmetatable(gc)
gc.__gc = cleanup

os.exit = function(...)
	cleanup()
	exit(...)
end
os.atexit = function(func)
	table.insert(exit_list, func)
end