2013-05-25 00:51:02 +02:00
|
|
|
/*
|
|
|
|
Minetest
|
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2013-05-25 00:51:02 +02:00
|
|
|
|
|
|
|
#include "common/c_types.h"
|
2013-11-05 18:06:15 +01:00
|
|
|
#include "common/c_internal.h"
|
2018-06-30 17:11:38 +02:00
|
|
|
#include "common/helper.h"
|
2017-01-31 14:18:52 +01:00
|
|
|
#include "gamedef.h"
|
2018-07-01 12:31:49 +02:00
|
|
|
#include <unordered_map>
|
2013-05-25 00:51:02 +02:00
|
|
|
|
|
|
|
extern "C" {
|
2013-08-11 04:09:45 +02:00
|
|
|
#include <lua.h>
|
|
|
|
#include <lauxlib.h>
|
2013-05-25 00:51:02 +02:00
|
|
|
}
|
|
|
|
|
2017-01-21 22:44:37 +01:00
|
|
|
#ifndef SERVER
|
2017-08-16 22:11:45 +02:00
|
|
|
class Client;
|
2020-04-26 20:57:27 +02:00
|
|
|
class GUIEngine;
|
2017-01-21 22:44:37 +01:00
|
|
|
#endif
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
class ScriptApiBase;
|
2013-05-25 00:51:02 +02:00
|
|
|
class Server;
|
|
|
|
class Environment;
|
2020-05-07 22:38:41 +02:00
|
|
|
class ServerInventoryManager;
|
2013-05-25 00:51:02 +02:00
|
|
|
|
2018-06-30 17:11:38 +02:00
|
|
|
class ModApiBase : protected LuaHelper {
|
2015-04-08 05:04:48 +02:00
|
|
|
public:
|
2013-08-11 04:09:45 +02:00
|
|
|
static ScriptApiBase* getScriptApiBase(lua_State *L);
|
|
|
|
static Server* getServer(lua_State *L);
|
2020-05-07 22:38:41 +02:00
|
|
|
static ServerInventoryManager *getServerInventoryMgr(lua_State *L);
|
2017-01-21 22:44:37 +01:00
|
|
|
#ifndef SERVER
|
|
|
|
static Client* getClient(lua_State *L);
|
2020-04-26 20:57:27 +02:00
|
|
|
static GUIEngine* getGuiEngine(lua_State *L);
|
2017-01-21 22:44:37 +01:00
|
|
|
#endif // !SERVER
|
|
|
|
|
2017-01-31 14:18:52 +01:00
|
|
|
static IGameDef* getGameDef(lua_State *L);
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
static Environment* getEnv(lua_State *L);
|
2020-04-26 20:57:27 +02:00
|
|
|
|
2015-04-08 22:44:37 +02:00
|
|
|
// When we are not loading the mod, this function returns "."
|
2015-04-08 05:04:48 +02:00
|
|
|
static std::string getCurrentModPath(lua_State *L);
|
2013-08-11 04:09:45 +02:00
|
|
|
|
|
|
|
// Get an arbitrary subclass of ScriptApiBase
|
|
|
|
// by using dynamic_cast<> on getScriptApiBase()
|
|
|
|
template<typename T>
|
|
|
|
static T* getScriptApi(lua_State *L) {
|
|
|
|
ScriptApiBase *scriptIface = getScriptApiBase(L);
|
|
|
|
T *scriptIfaceDowncast = dynamic_cast<T*>(scriptIface);
|
|
|
|
if (!scriptIfaceDowncast) {
|
2014-03-15 21:28:59 +01:00
|
|
|
throw LuaError("Requested unavailable ScriptApi - core engine bug!");
|
2013-08-11 04:09:45 +02:00
|
|
|
}
|
|
|
|
return scriptIfaceDowncast;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool registerFunction(lua_State *L,
|
|
|
|
const char* name,
|
2014-12-12 20:49:19 +01:00
|
|
|
lua_CFunction func,
|
|
|
|
int top);
|
2018-07-01 12:31:49 +02:00
|
|
|
|
2020-10-31 19:19:23 +01:00
|
|
|
/**
|
|
|
|
* A wrapper for deprecated functions.
|
|
|
|
*
|
|
|
|
* When called, handles the deprecation according to user settings and then calls `func`.
|
|
|
|
*
|
|
|
|
* @throws Lua Error if required by the user settings.
|
|
|
|
*
|
|
|
|
* @param L Lua state
|
|
|
|
* @param good Name of good function/method
|
|
|
|
* @param bad Name of deprecated function/method
|
|
|
|
* @param func Actual implementation of function
|
|
|
|
* @return value from `func`
|
|
|
|
*/
|
|
|
|
static int l_deprecated_function(lua_State *L, const char *good, const char *bad, lua_CFunction func);
|
2013-08-11 04:09:45 +02:00
|
|
|
};
|