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 S_BASE_H_
|
|
|
|
#define S_BASE_H_
|
|
|
|
|
|
|
|
#include <iostream>
|
2013-08-11 04:09:45 +02:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <lua.h>
|
|
|
|
}
|
2013-05-25 00:51:02 +02:00
|
|
|
|
|
|
|
#include "irrlichttypes.h"
|
2013-09-16 05:00:01 +02:00
|
|
|
#include "jthread/jmutex.h"
|
|
|
|
#include "jthread/jmutexautolock.h"
|
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"
|
2013-05-25 00:51:02 +02:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
#define SCRIPTAPI_LOCK_DEBUG
|
2013-05-25 00:51:02 +02:00
|
|
|
|
2014-09-06 02:08:51 +02:00
|
|
|
#define SCRIPT_MOD_NAME_FIELD "current_mod_name"
|
|
|
|
// MUST be an invalid mod name so that mods can't
|
|
|
|
// use that name to bypass security!
|
|
|
|
#define BUILTIN_MOD_NAME "*builtin*"
|
|
|
|
|
|
|
|
|
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
|
|
|
class ServerActiveObject;
|
|
|
|
|
|
|
|
class ScriptApiBase {
|
|
|
|
public:
|
2013-08-11 04:09:45 +02:00
|
|
|
ScriptApiBase();
|
|
|
|
virtual ~ScriptApiBase();
|
|
|
|
|
2015-03-02 19:26:20 +01:00
|
|
|
bool loadMod(const std::string &script_path, const std::string &mod_name, std::string *error=NULL);
|
|
|
|
bool loadScript(const std::string &script_path, std::string *error=NULL);
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2013-05-25 00:51:02 +02:00
|
|
|
/* object */
|
|
|
|
void addObjectReference(ServerActiveObject *cobj);
|
|
|
|
void removeObjectReference(ServerActiveObject *cobj);
|
|
|
|
|
2014-09-06 02:08:51 +02:00
|
|
|
Server* getServer() { return m_server; }
|
|
|
|
|
2013-05-25 00:51:02 +02:00
|
|
|
protected:
|
|
|
|
friend class LuaABM;
|
|
|
|
friend class InvRef;
|
|
|
|
friend class ObjectRef;
|
|
|
|
friend class NodeMetaRef;
|
|
|
|
friend class ModApiBase;
|
|
|
|
friend class ModApiEnvMod;
|
2013-06-25 17:02:02 +02:00
|
|
|
friend class LuaVoxelManip;
|
2013-05-25 00:51:02 +02:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
lua_State* getStack()
|
2013-05-25 00:51:02 +02:00
|
|
|
{ return m_luastack; }
|
|
|
|
|
|
|
|
void realityCheck();
|
2013-11-05 18:06:15 +01:00
|
|
|
void scriptError();
|
2013-05-25 00:51:02 +02:00
|
|
|
void stackDump(std::ostream &o);
|
|
|
|
|
|
|
|
void setServer(Server* server) { m_server = server; }
|
|
|
|
|
|
|
|
Environment* getEnv() { return m_environment; }
|
|
|
|
void setEnv(Environment* env) { m_environment = env; }
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
GUIEngine* getGuiEngine() { return m_guiengine; }
|
|
|
|
void setGuiEngine(GUIEngine* guiengine) { m_guiengine = guiengine; }
|
|
|
|
|
2014-10-02 21:58:13 +02:00
|
|
|
void objectrefGetOrCreate(lua_State *L, ServerActiveObject *cobj);
|
|
|
|
void objectrefGet(lua_State *L, u16 id);
|
2013-05-25 00:51:02 +02:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
JMutex m_luastackmutex;
|
2014-04-15 19:30:46 +02:00
|
|
|
// Stack index of Lua error handler
|
|
|
|
int m_errorhandler;
|
2014-09-06 02:08:51 +02:00
|
|
|
bool m_secure;
|
2013-08-11 04:09:45 +02:00
|
|
|
#ifdef SCRIPTAPI_LOCK_DEBUG
|
2013-05-25 00:51:02 +02:00
|
|
|
bool m_locked;
|
|
|
|
#endif
|
2014-04-15 19:30:46 +02:00
|
|
|
|
2013-05-25 00:51:02 +02:00
|
|
|
private:
|
|
|
|
lua_State* m_luastack;
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
Server* m_server;
|
|
|
|
Environment* m_environment;
|
|
|
|
GUIEngine* m_guiengine;
|
2013-05-25 00:51:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* S_BASE_H_ */
|