2013-05-24 15:51:02 -07: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 13:19:39 -07:00
|
|
|
#pragma once
|
2013-05-24 15:51:02 -07:00
|
|
|
|
|
|
|
#include "common/c_types.h"
|
2013-11-05 09:06:15 -08:00
|
|
|
#include "common/c_internal.h"
|
2017-01-31 05:18:52 -08:00
|
|
|
#include "gamedef.h"
|
2013-05-24 15:51:02 -07:00
|
|
|
|
|
|
|
extern "C" {
|
2013-08-10 19:09:45 -07:00
|
|
|
#include <lua.h>
|
|
|
|
#include <lauxlib.h>
|
2013-05-24 15:51:02 -07:00
|
|
|
}
|
|
|
|
|
2017-01-21 13:44:37 -08:00
|
|
|
#ifndef SERVER
|
2017-08-16 13:11:45 -07:00
|
|
|
class Client;
|
2017-01-21 13:44:37 -08:00
|
|
|
#endif
|
|
|
|
|
2013-08-10 19:09:45 -07:00
|
|
|
class ScriptApiBase;
|
2013-05-24 15:51:02 -07:00
|
|
|
class Server;
|
|
|
|
class Environment;
|
2013-08-10 19:09:45 -07:00
|
|
|
class GUIEngine;
|
2013-05-24 15:51:02 -07:00
|
|
|
|
2013-08-10 19:09:45 -07:00
|
|
|
class ModApiBase {
|
2013-05-24 15:51:02 -07:00
|
|
|
|
2015-04-07 20:04:48 -07:00
|
|
|
public:
|
2013-08-10 19:09:45 -07:00
|
|
|
static ScriptApiBase* getScriptApiBase(lua_State *L);
|
|
|
|
static Server* getServer(lua_State *L);
|
2017-01-21 13:44:37 -08:00
|
|
|
#ifndef SERVER
|
|
|
|
static Client* getClient(lua_State *L);
|
|
|
|
#endif // !SERVER
|
|
|
|
|
2017-01-31 05:18:52 -08:00
|
|
|
static IGameDef* getGameDef(lua_State *L);
|
|
|
|
|
2013-08-10 19:09:45 -07:00
|
|
|
static Environment* getEnv(lua_State *L);
|
|
|
|
static GUIEngine* getGuiEngine(lua_State *L);
|
2015-04-08 13:44:37 -07:00
|
|
|
// When we are not loading the mod, this function returns "."
|
2015-04-07 20:04:48 -07:00
|
|
|
static std::string getCurrentModPath(lua_State *L);
|
2013-08-10 19:09:45 -07: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 13:28:59 -07:00
|
|
|
throw LuaError("Requested unavailable ScriptApi - core engine bug!");
|
2013-08-10 19:09:45 -07:00
|
|
|
}
|
|
|
|
return scriptIfaceDowncast;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool registerFunction(lua_State *L,
|
|
|
|
const char* name,
|
2014-12-12 11:49:19 -08:00
|
|
|
lua_CFunction func,
|
|
|
|
int top);
|
2018-05-31 13:52:08 -07:00
|
|
|
|
|
|
|
static bool isNaN(lua_State *L, int idx);
|
2018-06-04 13:38:07 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read a value using a template type T from Lua State L and index
|
|
|
|
*
|
|
|
|
* @tparam T type to read from Lua
|
|
|
|
* @param L Lua state
|
|
|
|
* @param index Lua Index to read
|
|
|
|
* @return read value from Lua
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
static T readParam(lua_State *L, int index);
|
2013-08-10 19:09:45 -07:00
|
|
|
};
|