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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef L_BASE_H_
|
|
|
|
#define L_BASE_H_
|
|
|
|
|
|
|
|
#include "common/c_types.h"
|
2013-11-05 18:06:15 +01:00
|
|
|
#include "common/c_internal.h"
|
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
|
|
|
}
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
class ScriptApiBase;
|
2013-05-25 00:51:02 +02:00
|
|
|
class Server;
|
|
|
|
class Environment;
|
2013-08-11 04:09:45 +02:00
|
|
|
class GUIEngine;
|
2013-05-25 00:51:02 +02:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
class ModApiBase {
|
2013-05-25 00:51:02 +02:00
|
|
|
|
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);
|
|
|
|
static Environment* getEnv(lua_State *L);
|
|
|
|
static GUIEngine* getGuiEngine(lua_State *L);
|
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,
|
|
|
|
lua_CFunction fct,
|
|
|
|
int top
|
|
|
|
);
|
|
|
|
};
|
2013-05-25 00:51:02 +02:00
|
|
|
|
|
|
|
#endif /* L_BASE_H_ */
|