3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "lua_api/l_base.h"
21 #include "lua_api/l_internal.h"
22 #include "cpp_api/s_base.h"
23 #include "content/mods.h"
27 ScriptApiBase *ModApiBase::getScriptApiBase(lua_State *L)
29 // Get server from registry
30 lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_SCRIPTAPI);
31 ScriptApiBase *sapi_ptr = (ScriptApiBase*) lua_touserdata(L, -1);
36 Server *ModApiBase::getServer(lua_State *L)
38 return getScriptApiBase(L)->getServer();
42 Client *ModApiBase::getClient(lua_State *L)
44 return getScriptApiBase(L)->getClient();
48 IGameDef *ModApiBase::getGameDef(lua_State *L)
50 return getScriptApiBase(L)->getGameDef();
53 Environment *ModApiBase::getEnv(lua_State *L)
55 return getScriptApiBase(L)->getEnv();
58 GUIEngine *ModApiBase::getGuiEngine(lua_State *L)
60 return getScriptApiBase(L)->getGuiEngine();
63 std::string ModApiBase::getCurrentModPath(lua_State *L)
65 lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
66 std::string current_mod_name = readParam<std::string>(L, -1, "");
67 if (current_mod_name.empty())
70 const ModSpec *mod = getServer(L)->getModSpec(current_mod_name);
78 bool ModApiBase::registerFunction(lua_State *L, const char *name,
79 lua_CFunction func, int top)
81 // TODO: Check presence first!
83 lua_pushcfunction(L, func);
84 lua_setfield(L, top, name);