s_modchannels.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Minetest
  3. Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
  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. #include "s_modchannels.h"
  17. #include "s_internal.h"
  18. void ScriptApiModChannels::on_modchannel_message(const std::string &channel,
  19. const std::string &sender, const std::string &message)
  20. {
  21. SCRIPTAPI_PRECHECKHEADER
  22. // Get core.registered_on_generateds
  23. lua_getglobal(L, "core");
  24. lua_getfield(L, -1, "registered_on_modchannel_message");
  25. // Call callbacks
  26. lua_pushstring(L, channel.c_str());
  27. lua_pushstring(L, sender.c_str());
  28. lua_pushstring(L, message.c_str());
  29. runCallbacks(3, RUN_CALLBACKS_MODE_AND);
  30. }
  31. void ScriptApiModChannels::on_modchannel_signal(
  32. const std::string &channel, ModChannelSignal signal)
  33. {
  34. SCRIPTAPI_PRECHECKHEADER
  35. // Get core.registered_on_generateds
  36. lua_getglobal(L, "core");
  37. lua_getfield(L, -1, "registered_on_modchannel_signal");
  38. // Call callbacks
  39. lua_pushstring(L, channel.c_str());
  40. lua_pushinteger(L, (int)signal);
  41. runCallbacks(2, RUN_CALLBACKS_MODE_AND);
  42. }