| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| extern "C" | ||
| { | ||
| ffi_*; | ||
| }; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| Minetest | ||
| Copyright (C) 2021 DS | ||
| 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. | ||
| */ | ||
|
|
||
| #include "cpp_api/s_core.h" | ||
|
|
||
| #include "server.h" | ||
| #ifndef SERVER | ||
| #include "client/client.h" | ||
| #endif | ||
|
|
||
| Server *ScriptApiCore::getServer() | ||
| { | ||
| return dynamic_cast<Server *>(m_gamedef); | ||
| } | ||
| #ifndef SERVER | ||
| Client *ScriptApiCore::getClient() | ||
| { | ||
| return dynamic_cast<Client *>(m_gamedef); | ||
| } | ||
| #endif | ||
|
|
||
| void ScriptApiCore::setOriginDirect(const char *origin) | ||
| { | ||
| m_last_run_mod = origin ? origin : "??"; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| Minetest | ||
| Copyright (C) 2021 DS | ||
| 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. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "irrlichttypes.h" | ||
| #include "debug.h" | ||
|
|
||
| #include "util/basic_macros.h" | ||
| #include "config.h" | ||
|
|
||
| enum class ScriptingType: u8 { | ||
| Async, | ||
| Client, | ||
| MainMenu, | ||
| Server | ||
| }; | ||
|
|
||
| class Server; | ||
| #ifndef SERVER | ||
| class Client; | ||
| #endif | ||
| class IGameDef; | ||
| class Environment; | ||
| class GUIEngine; | ||
|
|
||
| class ScriptApiCore { | ||
| public: | ||
| ScriptApiCore(ScriptingType type) : m_type(type) {}; | ||
| // fake constructor to allow script API classes (e.g ScriptApiEnv) to virtually inherit from this one. | ||
| ScriptApiCore() | ||
| { | ||
| FATAL_ERROR("ScriptApiCore created without ScriptingType!"); | ||
| } | ||
| DISABLE_CLASS_COPY(ScriptApiCore); | ||
|
|
||
| IGameDef *getGameDef() { return m_gamedef; } | ||
| Server *getServer(); | ||
| ScriptingType getType() { return m_type; } | ||
| #ifndef SERVER | ||
| Client *getClient(); | ||
| #endif | ||
|
|
||
| Environment *getEnv() { return m_environment; } | ||
|
|
||
| std::string getOrigin() { return m_last_run_mod; } | ||
| void setOriginDirect(const char *origin); | ||
|
|
||
| protected: | ||
| void setGameDef(IGameDef *gamedef) { m_gamedef = gamedef; } | ||
|
|
||
| void setEnv(Environment *env) { m_environment = env; } | ||
|
|
||
| #ifndef SERVER | ||
| GUIEngine *getGuiEngine() { return m_guiengine; } | ||
| void setGuiEngine(GUIEngine *guiengine) { m_guiengine = guiengine; } | ||
| #endif | ||
|
|
||
| std::string m_last_run_mod; | ||
|
|
||
| private: | ||
| IGameDef *m_gamedef = nullptr; | ||
| Environment *m_environment = nullptr; | ||
| #ifndef SERVER | ||
| GUIEngine *m_guiengine = nullptr; | ||
| #endif | ||
| ScriptingType m_type; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| set(common_SCRIPT_FFI_API_SRCS | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/ffi_bla.cpp | ||
| PARENT_SCOPE) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| Minetest | ||
| Copyright (C) 2021 DS | ||
| 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. | ||
| */ | ||
|
|
||
| #include "cpp_api/s_base.h" | ||
| #include "lua_api/l_insec_private.h" | ||
| #include "lua_api/l_internal.h" | ||
| #include "lua_api/l_object.h" | ||
| #include "log.h" | ||
|
|
||
| // get_script_api_core() | ||
| int ModApiInsecPrivate::l_get_script_api_core(lua_State *L) | ||
| { | ||
| MAP_LOCK_REQUIRED; | ||
| ScriptApiCore *sac = getScriptApiBase(L); | ||
| *(ScriptApiCore **)lua_newuserdata(L, sizeof(sac)) = sac; | ||
| return 1; | ||
| } | ||
|
|
||
| int ModApiInsecPrivate::l_get_objref_metatable(lua_State *L) | ||
| { | ||
| MAP_LOCK_REQUIRED; | ||
| luaL_getmetatable(L, ObjectRef::className); | ||
| return 1; | ||
| } | ||
|
|
||
| int ModApiInsecPrivate::l_objref_check(lua_State *L) | ||
| { | ||
| NO_MAP_LOCK_REQUIRED; | ||
| ObjectRef::checkobject(L, 1); | ||
| return 0; | ||
| } | ||
|
|
||
| void ModApiInsecPrivate::Initialize(lua_State *L, int insec_top) | ||
| { | ||
| API_FCT_INSEC(get_script_api_core); | ||
| API_FCT_INSEC(get_objref_metatable); | ||
| API_FCT_INSEC(objref_check); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| Minetest | ||
| Copyright (C) 2021 DS | ||
| 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. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "lua_api/l_base.h" | ||
|
|
||
| class ModApiInsecPrivate : public ModApiBase | ||
| { | ||
| private: | ||
| /* | ||
| NOTE: | ||
| The functions in this module are available in the insec_private table | ||
| in the insecure environment. | ||
| */ | ||
|
|
||
| // get_script_api_core() | ||
| static int l_get_script_api_core(lua_State *L); | ||
|
|
||
| // get_objref_metatable() | ||
| static int l_get_objref_metatable(lua_State *L); | ||
|
|
||
| // objref_check(obj) | ||
| static int l_objref_check(lua_State *L); | ||
|
|
||
| public: | ||
| static void Initialize(lua_State *L, int insec_top); | ||
| }; |