diff options
author | Andrew Ward <rw@rubenwardy.com> | 2018-03-28 16:04:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-28 16:04:41 +0100 |
commit | 2323842dd3dd336b087ca3cf9756e0680b3a1244 (patch) | |
tree | 6b76f139e42872c8457c991925a5a2e6d41b85c9 /src/script/lua_api | |
parent | 040b878cd5f77f6b44622b7c00255b4981500dc8 (diff) | |
download | minetest-2323842dd3dd336b087ca3cf9756e0680b3a1244.tar.gz minetest-2323842dd3dd336b087ca3cf9756e0680b3a1244.tar.bz2 minetest-2323842dd3dd336b087ca3cf9756e0680b3a1244.zip |
Add formspec theming using prepended strings
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_object.cpp | 33 | ||||
-rw-r--r-- | src/script/lua_api/l_object.h | 6 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index f72a81d32..5fc6f9d3c 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -1244,6 +1244,37 @@ int ObjectRef::l_get_inventory_formspec(lua_State *L) return 1; } +// set_formspec_prepend(self, formspec) +int ObjectRef::l_set_formspec_prepend(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + ObjectRef *ref = checkobject(L, 1); + RemotePlayer *player = getplayer(ref); + if (player == NULL) + return 0; + + std::string formspec = luaL_checkstring(L, 2); + + player->formspec_prepend = formspec; + getServer(L)->reportFormspecPrependModified(player->getName()); + lua_pushboolean(L, true); + return 1; +} + +// get_formspec_prepend(self) -> formspec +int ObjectRef::l_get_formspec_prepend(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + ObjectRef *ref = checkobject(L, 1); + RemotePlayer *player = getplayer(ref); + if (player == NULL) + return 0; + + std::string formspec = player->formspec_prepend; + lua_pushlstring(L, formspec.c_str(), formspec.size()); + return 1; +} + // get_player_control(self) int ObjectRef::l_get_player_control(lua_State *L) { @@ -1817,6 +1848,8 @@ const luaL_Reg ObjectRef::methods[] = { luamethod(ObjectRef, set_attribute), luamethod(ObjectRef, set_inventory_formspec), luamethod(ObjectRef, get_inventory_formspec), + luamethod(ObjectRef, set_formspec_prepend), + luamethod(ObjectRef, get_formspec_prepend), luamethod(ObjectRef, get_player_control), luamethod(ObjectRef, get_player_control_bits), luamethod(ObjectRef, set_physics_override), diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h index 2a76d8a70..58cfe7146 100644 --- a/src/script/lua_api/l_object.h +++ b/src/script/lua_api/l_object.h @@ -253,6 +253,12 @@ private: // get_inventory_formspec(self) -> formspec static int l_get_inventory_formspec(lua_State *L); + // set_formspec_prepend(self, formspec) + static int l_set_formspec_prepend(lua_State *L); + + // get_formspec_prepend(self) -> formspec + static int l_get_formspec_prepend(lua_State *L); + // get_player_control(self) static int l_get_player_control(lua_State *L); |