diff options
author | red-001 <red-001@outlook.ie> | 2017-01-21 21:44:37 +0000 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-03-13 23:56:05 +0100 |
commit | cb3a61f8db6b7020dd69f7786a1086f6fe014dfc (patch) | |
tree | ef2d2848a83d9937c74c95e800775f454bfed28e /src/script | |
parent | 2efae3ffd720095222c800e016286a45c9fe1e5c (diff) | |
download | minetest-cb3a61f8db6b7020dd69f7786a1086f6fe014dfc.tar.gz minetest-cb3a61f8db6b7020dd69f7786a1086f6fe014dfc.tar.bz2 minetest-cb3a61f8db6b7020dd69f7786a1086f6fe014dfc.zip |
[CSM] Add method that display chat to client-sided lua. (#5089) (#5091)
* squashed: [Client-sided scripting] Don't register functions that don't work. (#5091)
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/clientscripting.cpp | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_base.cpp | 6 | ||||
-rw-r--r-- | src/script/lua_api/l_base.h | 8 | ||||
-rw-r--r-- | src/script/lua_api/l_client.cpp | 12 | ||||
-rw-r--r-- | src/script/lua_api/l_client.h | 1 | ||||
-rw-r--r-- | src/script/lua_api/l_util.cpp | 26 | ||||
-rw-r--r-- | src/script/lua_api/l_util.h | 2 |
7 files changed, 56 insertions, 1 deletions
diff --git a/src/script/clientscripting.cpp b/src/script/clientscripting.cpp index 43bc6f94e..9bf93eb83 100644 --- a/src/script/clientscripting.cpp +++ b/src/script/clientscripting.cpp @@ -49,6 +49,6 @@ ClientScripting::ClientScripting(Client *client): void ClientScripting::InitializeModApi(lua_State *L, int top) { - ModApiUtil::Initialize(L, top); + ModApiUtil::InitializeClient(L, top); ModApiClient::Initialize(L, top); } diff --git a/src/script/lua_api/l_base.cpp b/src/script/lua_api/l_base.cpp index 515a7d933..f2703718a 100644 --- a/src/script/lua_api/l_base.cpp +++ b/src/script/lua_api/l_base.cpp @@ -37,6 +37,12 @@ Server *ModApiBase::getServer(lua_State *L) return getScriptApiBase(L)->getServer(); } +#ifndef SERVER +Client *ModApiBase::getClient(lua_State *L) +{ + return getScriptApiBase(L)->getClient(); +} +#endif Environment *ModApiBase::getEnv(lua_State *L) { return getScriptApiBase(L)->getEnv(); diff --git a/src/script/lua_api/l_base.h b/src/script/lua_api/l_base.h index 641013dfd..dc1b1b226 100644 --- a/src/script/lua_api/l_base.h +++ b/src/script/lua_api/l_base.h @@ -28,6 +28,10 @@ extern "C" { #include <lauxlib.h> } +#ifndef SERVER +#include "client.h" +#endif + class ScriptApiBase; class Server; class Environment; @@ -38,6 +42,10 @@ class ModApiBase { public: static ScriptApiBase* getScriptApiBase(lua_State *L); static Server* getServer(lua_State *L); + #ifndef SERVER + static Client* getClient(lua_State *L); + #endif // !SERVER + static Environment* getEnv(lua_State *L); static GUIEngine* getGuiEngine(lua_State *L); // When we are not loading the mod, this function returns "." diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index 9c478602a..f4c3812ac 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "l_client.h" #include "l_internal.h" +#include "util/string.h" int ModApiClient::l_get_current_modname(lua_State *L) { @@ -27,7 +28,18 @@ int ModApiClient::l_get_current_modname(lua_State *L) return 1; } +// display_chat_message(message) +int ModApiClient::l_display_chat_message(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + + std::string message = luaL_checkstring(L, 1); + getClient(L)->pushToChatQueue(utf8_to_wide(message)); + return 1; +} + void ModApiClient::Initialize(lua_State *L, int top) { API_FCT(get_current_modname); + API_FCT(display_chat_message); } diff --git a/src/script/lua_api/l_client.h b/src/script/lua_api/l_client.h index 332f00132..b4a57cb61 100644 --- a/src/script/lua_api/l_client.h +++ b/src/script/lua_api/l_client.h @@ -28,6 +28,7 @@ class ModApiClient : public ModApiBase private: // get_current_modname() static int l_get_current_modname(lua_State *L); + static int l_display_chat_message(lua_State *L); public: static void Initialize(lua_State *L, int top); diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp index c26791646..277a874bf 100644 --- a/src/script/lua_api/l_util.cpp +++ b/src/script/lua_api/l_util.cpp @@ -526,6 +526,32 @@ void ModApiUtil::Initialize(lua_State *L, int top) API_FCT(get_version); } +void ModApiUtil::InitializeClient(lua_State *L, int top) +{ + API_FCT(log); + + API_FCT(setting_set); + API_FCT(setting_get); + API_FCT(setting_setbool); + API_FCT(setting_getbool); + API_FCT(setting_save); + + API_FCT(parse_json); + API_FCT(write_json); + + API_FCT(is_yes); + + API_FCT(get_builtin_path); + + API_FCT(compress); + API_FCT(decompress); + + API_FCT(encode_base64); + API_FCT(decode_base64); + + API_FCT(get_version); +} + void ModApiUtil::InitializeAsync(AsyncEngine& engine) { ASYNC_API_FCT(log); diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h index 9910704b3..eef32c0a1 100644 --- a/src/script/lua_api/l_util.h +++ b/src/script/lua_api/l_util.h @@ -110,6 +110,8 @@ private: public: static void Initialize(lua_State *L, int top); + static void InitializeClient(lua_State *L, int top); + static void InitializeAsync(AsyncEngine& engine); }; |