You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

77 lines
2.2 KiB

  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. #ifndef L_BASE_H_
  17. #define L_BASE_H_
  18. #include "common/c_types.h"
  19. #include "common/c_internal.h"
  20. #include "common/helper.h"
  21. #include "gamedef.h"
  22. extern "C" {
  23. #include <lua.h>
  24. #include <lauxlib.h>
  25. }
  26. #ifndef SERVER
  27. class Client;
  28. #endif
  29. class ScriptApiBase;
  30. class Server;
  31. class Environment;
  32. class GUIEngine;
  33. class ModApiBase : protected LuaHelper {
  34. public:
  35. static ScriptApiBase* getScriptApiBase(lua_State *L);
  36. static Server* getServer(lua_State *L);
  37. #ifndef SERVER
  38. static Client* getClient(lua_State *L);
  39. #endif // !SERVER
  40. static IGameDef* getGameDef(lua_State *L);
  41. static Environment* getEnv(lua_State *L);
  42. static GUIEngine* getGuiEngine(lua_State *L);
  43. // When we are not loading the mod, this function returns "."
  44. static std::string getCurrentModPath(lua_State *L);
  45. // Get an arbitrary subclass of ScriptApiBase
  46. // by using dynamic_cast<> on getScriptApiBase()
  47. template<typename T>
  48. static T* getScriptApi(lua_State *L) {
  49. ScriptApiBase *scriptIface = getScriptApiBase(L);
  50. T *scriptIfaceDowncast = dynamic_cast<T*>(scriptIface);
  51. if (!scriptIfaceDowncast) {
  52. throw LuaError("Requested unavailable ScriptApi - core engine bug!");
  53. }
  54. return scriptIfaceDowncast;
  55. }
  56. static bool registerFunction(lua_State *L,
  57. const char* name,
  58. lua_CFunction func,
  59. int top);
  60. };
  61. #endif /* L_BASE_H_ */