3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "l_internal.h"
23 #include "util/string.h"
24 #include "cpp_api/s_base.h"
26 int ModApiClient::l_get_current_modname(lua_State *L)
28 lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
33 int ModApiClient::l_get_last_run_mod(lua_State *L)
35 lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
36 const char *current_mod = lua_tostring(L, -1);
37 if (current_mod == NULL || current_mod[0] == '\0') {
39 lua_pushstring(L, getScriptApiBase(L)->getOrigin().c_str());
44 // set_last_run_mod(modname)
45 int ModApiClient::l_set_last_run_mod(lua_State *L)
47 const char *mod = lua_tostring(L, 1);
48 getScriptApiBase(L)->setOriginDirect(mod);
52 // display_chat_message(message)
53 int ModApiClient::l_display_chat_message(lua_State *L)
57 std::string message = luaL_checkstring(L, 1);
58 getClient(L)->pushToChatQueue(utf8_to_wide(message));
62 void ModApiClient::Initialize(lua_State *L, int top)
64 API_FCT(get_current_modname);
65 API_FCT(display_chat_message);
66 API_FCT(set_last_run_mod);
67 API_FCT(get_last_run_mod);