minetest.registered_on_chat_messages, minetest.register_on_chat_message = make_registration()
minetest.registered_globalsteps, minetest.register_globalstep = make_registration()
+minetest.registered_on_shutdown, minetest.register_on_shutdown = make_registration()
minetest.registered_on_punchnodes, minetest.register_on_punchnode = make_registration()
minetest.registered_on_placenodes, minetest.register_on_placenode = make_registration()
minetest.registered_on_dignodes, minetest.register_on_dignode = make_registration()
Global callback registration functions: (Call these only at load time)
minetest.register_globalstep(func(dtime))
^ Called every server step, usually interval of 0.05s
+minetest.register_on_shutdown(func())
+^ Called before server shutdown
+^ WARNING: If the server terminates abnormally (i.e. crashes), the registered
+ callbacks WILL LIKELY NOT BE RUN. Data should be saved at
+ semi-frequent intervals as well as on server shutdown.
minetest.register_on_placenode(func(pos, newnode, placer, oldnode))
^ Called when a node has been placed
^ Deprecated: Use on_construct or after_place_node in node definition instead
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);
void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp,
u32 blockseed);
+/* server */
+void scriptapi_on_shutdown(lua_State *L);
+
/* misc */
void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player);
void scriptapi_on_dieplayer(lua_State *L, ServerActiveObject *player);
{}
}
}
+
+ /*
+ Execute script shutdown hooks
+ */
+ scriptapi_on_shutdown(m_lua);
{
JMutexAutoLock envlock(m_env_mutex);