scripting_server.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include "cpp_api/s_base.h"
  18. #include "cpp_api/s_entity.h"
  19. #include "cpp_api/s_env.h"
  20. #include "cpp_api/s_inventory.h"
  21. #include "cpp_api/s_modchannels.h"
  22. #include "cpp_api/s_node.h"
  23. #include "cpp_api/s_player.h"
  24. #include "cpp_api/s_server.h"
  25. #include "cpp_api/s_security.h"
  26. #include "cpp_api/s_async.h"
  27. struct PackedValue;
  28. /*****************************************************************************/
  29. /* Scripting <-> Server Game Interface */
  30. /*****************************************************************************/
  31. class ServerScripting:
  32. virtual public ScriptApiBase,
  33. public ScriptApiDetached,
  34. public ScriptApiEntity,
  35. public ScriptApiEnv,
  36. public ScriptApiModChannels,
  37. public ScriptApiNode,
  38. public ScriptApiPlayer,
  39. public ScriptApiServer,
  40. public ScriptApiSecurity
  41. {
  42. public:
  43. ServerScripting(Server* server);
  44. void loadBuiltin();
  45. // use ScriptApiBase::loadMod() to load mods
  46. // Save globals that are copied into other Lua envs
  47. void saveGlobals();
  48. // Initialize async engine, call this AFTER loading all mods
  49. void initAsync();
  50. // Global step handler to collect async results
  51. void stepAsync();
  52. // Pass job to async threads
  53. u32 queueAsync(std::string &&serialized_func,
  54. PackedValue *param, const std::string &mod_origin);
  55. private:
  56. void InitializeModApi(lua_State *L, int top);
  57. static void InitializeAsync(lua_State *L, int top);
  58. AsyncEngine asyncEngine;
  59. };