aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/common/c_content.cpp14
-rw-r--r--src/script/common/c_content.h3
-rw-r--r--src/script/cpp_api/s_entity.cpp5
-rw-r--r--src/script/lua_api/l_itemstackmeta.cpp5
-rw-r--r--src/script/lua_api/l_metadata.cpp14
-rw-r--r--src/script/lua_api/l_metadata.h3
-rw-r--r--src/script/lua_api/l_nodemeta.cpp5
-rw-r--r--src/script/lua_api/l_object.cpp2
-rw-r--r--src/script/lua_api/l_storage.cpp5
9 files changed, 51 insertions, 5 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 99e12cd82..bcae874b9 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -58,6 +58,12 @@ ItemDefinition read_item_definition(lua_State* L,int index,
getstringfield(L, index, "description", def.description);
getstringfield(L, index, "inventory_image", def.inventory_image);
getstringfield(L, index, "wield_image", def.wield_image);
+ getstringfield(L, index, "palette", def.palette_image);
+
+ // Read item color.
+ lua_getfield(L, index, "color");
+ read_color(L, -1, &def.color);
+ lua_pop(L, 1);
lua_getfield(L, index, "wield_scale");
if(lua_istable(L, -1)){
@@ -118,7 +124,7 @@ ItemDefinition read_item_definition(lua_State* L,int index,
/******************************************************************************/
void read_object_properties(lua_State *L, int index,
- ObjectProperties *prop)
+ ObjectProperties *prop, IItemDefManager *idef)
{
if(index < 0)
index = lua_gettop(L) + 1 + index;
@@ -216,6 +222,10 @@ void read_object_properties(lua_State *L, int index,
}
lua_pop(L, 1);
getstringfield(L, -1, "infotext", prop->infotext);
+ lua_getfield(L, -1, "wield_item");
+ if (!lua_isnil(L, -1))
+ prop->wield_item = read_item(L, -1, idef).getItemString();
+ lua_pop(L, 1);
}
/******************************************************************************/
@@ -284,6 +294,8 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
lua_setfield(L, -2, "automatic_face_movement_max_rotation_per_sec");
lua_pushlstring(L, prop->infotext.c_str(), prop->infotext.size());
lua_setfield(L, -2, "infotext");
+ lua_pushlstring(L, prop->wield_item.c_str(), prop->wield_item.size());
+ lua_setfield(L, -2, "wield_item");
}
/******************************************************************************/
diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h
index 10cccbb01..949b136eb 100644
--- a/src/script/common/c_content.h
+++ b/src/script/common/c_content.h
@@ -89,7 +89,8 @@ void push_tool_capabilities (lua_State *L,
ItemDefinition read_item_definition (lua_State *L, int index,
ItemDefinition default_def);
void read_object_properties (lua_State *L, int index,
- ObjectProperties *prop);
+ ObjectProperties *prop,
+ IItemDefManager *idef);
void push_object_properties (lua_State *L,
ObjectProperties *prop);
diff --git a/src/script/cpp_api/s_entity.cpp b/src/script/cpp_api/s_entity.cpp
index 9e2193970..2e1d277e4 100644
--- a/src/script/cpp_api/s_entity.cpp
+++ b/src/script/cpp_api/s_entity.cpp
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "object_properties.h"
#include "common/c_converter.h"
#include "common/c_content.h"
+#include "server.h"
bool ScriptApiEntity::luaentity_Add(u16 id, const char *name)
{
@@ -187,11 +188,11 @@ void ScriptApiEntity::luaentity_GetProperties(u16 id,
getstringfield(L, -1, "mesh", prop->mesh);
// Deprecated: read object properties directly
- read_object_properties(L, -1, prop);
+ read_object_properties(L, -1, prop, getServer()->idef());
// Read initial_properties
lua_getfield(L, -1, "initial_properties");
- read_object_properties(L, -1, prop);
+ read_object_properties(L, -1, prop, getServer()->idef());
lua_pop(L, 1);
}
diff --git a/src/script/lua_api/l_itemstackmeta.cpp b/src/script/lua_api/l_itemstackmeta.cpp
index efdd77b51..c37a82116 100644
--- a/src/script/lua_api/l_itemstackmeta.cpp
+++ b/src/script/lua_api/l_itemstackmeta.cpp
@@ -92,6 +92,10 @@ void ItemStackMetaRef::Register(lua_State *L)
lua_pushcfunction(L, gc_object);
lua_settable(L, metatable);
+ lua_pushliteral(L, "__eq");
+ lua_pushcfunction(L, l_equals);
+ lua_settable(L, metatable);
+
lua_pop(L, 1); // drop metatable
luaL_openlib(L, 0, methods, 0); // fill methodtable
@@ -111,5 +115,6 @@ const luaL_Reg ItemStackMetaRef::methods[] = {
luamethod(MetaDataRef, set_float),
luamethod(MetaDataRef, to_table),
luamethod(MetaDataRef, from_table),
+ luamethod(MetaDataRef, equals),
{0,0}
};
diff --git a/src/script/lua_api/l_metadata.cpp b/src/script/lua_api/l_metadata.cpp
index b54005bac..5f4e984cb 100644
--- a/src/script/lua_api/l_metadata.cpp
+++ b/src/script/lua_api/l_metadata.cpp
@@ -250,3 +250,17 @@ bool MetaDataRef::handleFromTable(lua_State *L, int table, Metadata *meta)
return true;
}
+
+// equals(self, other)
+int MetaDataRef::l_equals(lua_State *L)
+{
+ MetaDataRef *ref1 = checkobject(L, 1);
+ Metadata *data1 = ref1->getmeta(false);
+ MetaDataRef *ref2 = checkobject(L, 2);
+ Metadata *data2 = ref2->getmeta(false);
+ if (data1 == NULL || data2 == NULL)
+ lua_pushboolean(L, data1 == data2);
+ else
+ lua_pushboolean(L, *data1 == *data2);
+ return 1;
+}
diff --git a/src/script/lua_api/l_metadata.h b/src/script/lua_api/l_metadata.h
index be31d95ad..a4d8214d3 100644
--- a/src/script/lua_api/l_metadata.h
+++ b/src/script/lua_api/l_metadata.h
@@ -67,6 +67,9 @@ protected:
// from_table(self, table)
static int l_from_table(lua_State *L);
+
+ // equals(self, other)
+ static int l_equals(lua_State *L);
};
#endif /* L_NODEMETA_H_ */
diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp
index 55d11fc13..c65d56f14 100644
--- a/src/script/lua_api/l_nodemeta.cpp
+++ b/src/script/lua_api/l_nodemeta.cpp
@@ -204,6 +204,10 @@ void NodeMetaRef::RegisterCommon(lua_State *L)
lua_pushcfunction(L, gc_object);
lua_settable(L, metatable);
+ lua_pushliteral(L, "__eq");
+ lua_pushcfunction(L, l_equals);
+ lua_settable(L, metatable);
+
lua_pop(L, 1); // drop metatable
}
@@ -225,6 +229,7 @@ const luaL_Reg NodeMetaRef::methodsServer[] = {
luamethod(MetaDataRef, to_table),
luamethod(MetaDataRef, from_table),
luamethod(NodeMetaRef, get_inventory),
+ luamethod(MetaDataRef, equals),
{0,0}
};
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index f9d2754e7..0699705cb 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -737,7 +737,7 @@ int ObjectRef::l_set_properties(lua_State *L)
ObjectProperties *prop = co->accessObjectProperties();
if (!prop)
return 0;
- read_object_properties(L, 2, prop);
+ read_object_properties(L, 2, prop, getServer(L)->idef());
co->notifyObjectPropertiesModified();
return 0;
}
diff --git a/src/script/lua_api/l_storage.cpp b/src/script/lua_api/l_storage.cpp
index 59906dda5..4c6b2a182 100644
--- a/src/script/lua_api/l_storage.cpp
+++ b/src/script/lua_api/l_storage.cpp
@@ -98,6 +98,10 @@ void StorageRef::Register(lua_State *L)
lua_pushcfunction(L, gc_object);
lua_settable(L, metatable);
+ lua_pushliteral(L, "__eq");
+ lua_pushcfunction(L, l_equals);
+ lua_settable(L, metatable);
+
lua_pop(L, 1); // drop metatable
luaL_openlib(L, 0, methods, 0); // fill methodtable
@@ -138,5 +142,6 @@ const luaL_Reg StorageRef::methods[] = {
luamethod(MetaDataRef, set_float),
luamethod(MetaDataRef, to_table),
luamethod(MetaDataRef, from_table),
+ luamethod(MetaDataRef, equals),
{0,0}
};