aboutsummaryrefslogtreecommitdiff
path: root/src/scriptapi.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-07-19 14:09:16 +0300
committerPerttu Ahola <celeron55@gmail.com>2012-07-19 14:09:16 +0300
commit16ad10e62f4dcf620f9a962b07aa39f1c561f8dc (patch)
treef82e70e1d3d1c54b179ef4b3bc4b06bd702316dc /src/scriptapi.cpp
parent02fb912a955c9e5baa86ecd4206eefaa88f3e60a (diff)
downloadhax-minetest-server-16ad10e62f4dcf620f9a962b07aa39f1c561f8dc.tar.gz
hax-minetest-server-16ad10e62f4dcf620f9a962b07aa39f1c561f8dc.zip
Allow defining player's inventory form in Lua
Diffstat (limited to 'src/scriptapi.cpp')
-rw-r--r--src/scriptapi.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index f06485458..25af2d105 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -2864,6 +2864,32 @@ private:
return 1;
}
+ // set_inventory_formspec(self, formspec)
+ static int l_set_inventory_formspec(lua_State *L)
+ {
+ ObjectRef *ref = checkobject(L, 1);
+ Player *player = getplayer(ref);
+ if(player == NULL) return 0;
+ std::string formspec = luaL_checkstring(L, 2);
+
+ player->inventory_formspec = formspec;
+ get_server(L)->reportInventoryFormspecModified(player->getName());
+ lua_pushboolean(L, true);
+ return 1;
+ }
+
+ // get_inventory_formspec(self) -> formspec
+ static int l_get_inventory_formspec(lua_State *L)
+ {
+ ObjectRef *ref = checkobject(L, 1);
+ Player *player = getplayer(ref);
+ if(player == NULL) return 0;
+
+ std::string formspec = player->inventory_formspec;
+ lua_pushlstring(L, formspec.c_str(), formspec.size());
+ return 1;
+ }
+
public:
ObjectRef(ServerActiveObject *object):
m_object(object)
@@ -2960,6 +2986,8 @@ const luaL_reg ObjectRef::methods[] = {
method(ObjectRef, get_look_dir),
method(ObjectRef, get_look_pitch),
method(ObjectRef, get_look_yaw),
+ method(ObjectRef, set_inventory_formspec),
+ method(ObjectRef, get_inventory_formspec),
{0,0}
};