diff options
| author | ruki <[email protected]> | 2023-02-21 23:12:54 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-02-21 23:12:54 +0800 |
| commit | eec6de9e8b6456aa13b588ecce47af07fcfba965 (patch) | |
| tree | 4f76bf9ac5c745708d5494c1b3b61b6bbc2f6baa /xmake/core/base/os.lua | |
| parent | 94c2973e49202add48796a75f9b5f64f4f8bb6f1 (diff) | |
add os.atexit
Diffstat (limited to 'xmake/core/base/os.lua')
| -rw-r--r-- | xmake/core/base/os.lua | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index dcd7cca8b..c05c718c9 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -270,6 +270,16 @@ function os._is_tracing_process() return is_tracing end +-- run all exit callback +function os._run_exit_cbs(ok, errors) + local exit_callbacks = os._EXIT_CALLBACKS + if exit_callbacks then + for _, cb in ipairs(exit_callbacks) do + cb(ok, errors) + end + end +end + -- match files or directories -- -- @param pattern the search pattern @@ -650,11 +660,25 @@ end -- exit program function os.exit(...) - - -- do exit return os._exit(...) end +-- register exit callback +-- +-- e.g. +-- os.atexit(function (ok, errors) +-- print(ok, errors) +-- end) +-- +function os.atexit(on_exit) + local exit_callbacks = os._EXIT_CALLBACKS + if exit_callbacks == nil then + exit_callbacks = {} + os._EXIT_CALLBACKS = exit_callbacks + end + table.insert(exit_callbacks, on_exit) +end + -- run command function os.run(cmd) |
