From 6c8fa83ecd3f40a8e2fec890caaaa955f9d4255c Mon Sep 17 00:00:00 2001 From: Matthew I Date: Sat, 8 Sep 2012 14:44:26 -0400 Subject: Add shutdown hook interface to Lua API Scripts can call minetest.register_on_shutdown() to register a shutdown hook. Document that minetest.register_on_shutdown() callbacks may not be run If the server crashes, it is unlikely that callbacks registered using minetest.register_on_shutdown() will be called. --- src/scriptapi.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/scriptapi.cpp') diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 91100d311..e5815c462 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -5576,6 +5576,19 @@ bool scriptapi_on_chat_message(lua_State *L, const std::string &name, return ate; } +void scriptapi_on_shutdown(lua_State *L) +{ + realitycheck(L); + assert(lua_checkstack(L, 20)); + StackUnroller stack_unroller(L); + + // Get registered shutdown hooks + lua_getglobal(L, "minetest"); + lua_getfield(L, -1, "registered_on_shutdown"); + // Call callbacks + scriptapi_run_callbacks(L, 0, RUN_CALLBACKS_MODE_FIRST); +} + void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player) { realitycheck(L); -- cgit v1.2.3