summaryrefslogtreecommitdiff
path: root/src/script/common
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2016-12-22 23:16:00 +0100
committerest31 <MTest31@outlook.com>2016-12-22 23:16:00 +0100
commit81d56b94919dceb7b2e51d70b21a7ca22f852bd5 (patch)
tree1e9ef1be1b3295a8673d6e4f0bdeb4c2d3a6015f /src/script/common
parent8077612dcb48221281e726a60eb97bf73fde462b (diff)
parent231ac33d34dfaaddf292c5f31b1eae43eeefba2d (diff)
downloadminetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.gz
minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.bz2
minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.zip
Merge 0.4.15 changes into stable-0.4
0.4.15 release!
Diffstat (limited to 'src/script/common')
-rw-r--r--src/script/common/c_content.cpp44
-rw-r--r--src/script/common/c_content.h6
-rw-r--r--src/script/common/c_converter.cpp20
-rw-r--r--src/script/common/c_converter.h4
4 files changed, 46 insertions, 28 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 06e20c2a0..541744895 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "porting.h"
#include "mg_schematic.h"
#include "noise.h"
-#include "json/json.h"
+#include <json/json.h>
struct EnumString es_TileAnimationType[] =
{
@@ -65,9 +65,8 @@ ItemDefinition read_item_definition(lua_State* L,int index,
}
lua_pop(L, 1);
- def.stack_max = getintfield_default(L, index, "stack_max", def.stack_max);
- if(def.stack_max == 0)
- def.stack_max = 1;
+ int stack_max = getintfield_default(L, index, "stack_max", def.stack_max);
+ def.stack_max = rangelim(stack_max, 1, U16_MAX);
lua_getfield(L, index, "on_use");
def.usable = lua_isfunction(L, -1);
@@ -527,6 +526,12 @@ ContentFeatures read_content_features(lua_State *L, int index)
// Amount of light the node emits
f.light_source = getintfield_default(L, index,
"light_source", f.light_source);
+ if (f.light_source > LIGHT_MAX) {
+ warningstream << "Node " << f.name.c_str()
+ << " had greater light_source than " << LIGHT_MAX
+ << ", it was reduced." << std::endl;
+ f.light_source = LIGHT_MAX;
+ }
f.damage_per_second = getintfield_default(L, index,
"damage_per_second", f.damage_per_second);
@@ -830,20 +835,18 @@ void push_tool_capabilities(lua_State *L,
// Create groupcaps table
lua_newtable(L);
// For each groupcap
- for(std::map<std::string, ToolGroupCap>::const_iterator
- i = toolcap.groupcaps.begin(); i != toolcap.groupcaps.end(); i++){
+ for (ToolGCMap::const_iterator i = toolcap.groupcaps.begin();
+ i != toolcap.groupcaps.end(); i++) {
// Create groupcap table
lua_newtable(L);
const std::string &name = i->first;
const ToolGroupCap &groupcap = i->second;
// Create subtable "times"
lua_newtable(L);
- for(std::map<int, float>::const_iterator
- i = groupcap.times.begin(); i != groupcap.times.end(); i++){
- int rating = i->first;
- float time = i->second;
- lua_pushinteger(L, rating);
- lua_pushnumber(L, time);
+ for (UNORDERED_MAP<int, float>::const_iterator
+ i = groupcap.times.begin(); i != groupcap.times.end(); i++) {
+ lua_pushinteger(L, i->first);
+ lua_pushnumber(L, i->second);
lua_settable(L, -3);
}
// Set subtable "times"
@@ -859,8 +862,8 @@ void push_tool_capabilities(lua_State *L,
//Create damage_groups table
lua_newtable(L);
// For each damage group
- for(std::map<std::string, s16>::const_iterator
- i = toolcap.damageGroups.begin(); i != toolcap.damageGroups.end(); i++){
+ for (DamageGroup::const_iterator i = toolcap.damageGroups.begin();
+ i != toolcap.damageGroups.end(); i++) {
// Create damage group table
lua_pushinteger(L, i->second);
lua_setfield(L, -2, i->first.c_str());
@@ -1066,8 +1069,7 @@ void push_flags_string(lua_State *L, FlagDesc *flagdesc, u32 flags, u32 flagmask
/******************************************************************************/
/******************************************************************************/
-void read_groups(lua_State *L, int index,
- std::map<std::string, int> &result)
+void read_groups(lua_State *L, int index, ItemGroupList &result)
{
if (!lua_istable(L,index))
return;
@@ -1086,11 +1088,10 @@ void read_groups(lua_State *L, int index,
}
/******************************************************************************/
-void push_groups(lua_State *L, const std::map<std::string, int> &groups)
+void push_groups(lua_State *L, const ItemGroupList &groups)
{
lua_newtable(L);
- std::map<std::string, int>::const_iterator it;
- for (it = groups.begin(); it != groups.end(); ++it) {
+ for (ItemGroupList::const_iterator it = groups.begin(); it != groups.end(); ++it) {
lua_pushnumber(L, it->second);
lua_setfield(L, -2, it->first.c_str());
}
@@ -1250,8 +1251,13 @@ static bool push_json_value_helper(lua_State *L, const Json::Value &value,
lua_newtable(L);
for (Json::Value::const_iterator it = value.begin();
it != value.end(); ++it) {
+#ifndef JSONCPP_STRING
const char *str = it.memberName();
lua_pushstring(L, str ? str : "");
+#else
+ std::string str = it.name();
+ lua_pushstring(L, str.c_str());
+#endif
push_json_value_helper(L, *it, nullindex);
lua_rawset(L, -3);
}
diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h
index 46416ad8e..2a2228b6d 100644
--- a/src/script/common/c_content.h
+++ b/src/script/common/c_content.h
@@ -33,11 +33,11 @@ extern "C" {
}
#include <iostream>
-#include <map>
#include <vector>
#include "irrlichttypes_bloated.h"
#include "util/string.h"
+#include "itemgroup.h"
namespace Json { class Value; }
@@ -106,10 +106,10 @@ void pushnode (lua_State *L, const MapNode &n,
NodeBox read_nodebox (lua_State *L, int index);
void read_groups (lua_State *L, int index,
- std::map<std::string, int> &result);
+ ItemGroupList &result);
void push_groups (lua_State *L,
- const std::map<std::string, int> &groups);
+ const ItemGroupList &groups);
//TODO rename to "read_enum_field"
int getenumfield (lua_State *L, int table,
diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp
index 55c4a5f5a..f36298915 100644
--- a/src/script/common/c_converter.cpp
+++ b/src/script/common/c_converter.cpp
@@ -23,6 +23,7 @@ extern "C" {
}
#include "util/numeric.h"
+#include "util/serialize.h"
#include "util/string.h"
#include "common/c_converter.h"
#include "constants.h"
@@ -37,6 +38,14 @@ extern "C" {
} \
} while(0)
#define CHECK_POS_COORD(name) CHECK_TYPE(-1, "position coordinate '" name "'", LUA_TNUMBER)
+#define CHECK_FLOAT_RANGE(value, name) \
+if (value < F1000_MIN || value > F1000_MAX) { \
+ std::ostringstream error_text; \
+ error_text << "Invalid float vector dimension range '" name "' " << \
+ "(expected " << F1000_MIN << " < " name " < " << F1000_MAX << \
+ " got " << value << ")." << std::endl; \
+ throw LuaError(error_text.str()); \
+}
#define CHECK_POS_TAB(index) CHECK_TYPE(index, "position", LUA_TTABLE)
@@ -170,14 +179,17 @@ v3f check_v3f(lua_State *L, int index)
lua_getfield(L, index, "x");
CHECK_POS_COORD("x");
pos.X = lua_tonumber(L, -1);
+ CHECK_FLOAT_RANGE(pos.X, "x")
lua_pop(L, 1);
lua_getfield(L, index, "y");
CHECK_POS_COORD("y");
pos.Y = lua_tonumber(L, -1);
+ CHECK_FLOAT_RANGE(pos.Y, "y")
lua_pop(L, 1);
lua_getfield(L, index, "z");
CHECK_POS_COORD("z");
pos.Z = lua_tonumber(L, -1);
+ CHECK_FLOAT_RANGE(pos.Z, "z")
lua_pop(L, 1);
return pos;
}
@@ -391,7 +403,7 @@ bool getintfield(lua_State *L, int table,
lua_getfield(L, table, fieldname);
bool got = false;
if(lua_isnumber(L, -1)){
- result = lua_tonumber(L, -1);
+ result = lua_tointeger(L, -1);
got = true;
}
lua_pop(L, 1);
@@ -404,7 +416,7 @@ bool getintfield(lua_State *L, int table,
lua_getfield(L, table, fieldname);
bool got = false;
if(lua_isnumber(L, -1)){
- result = lua_tonumber(L, -1);
+ result = lua_tointeger(L, -1);
got = true;
}
lua_pop(L, 1);
@@ -417,7 +429,7 @@ bool getintfield(lua_State *L, int table,
lua_getfield(L, table, fieldname);
bool got = false;
if(lua_isnumber(L, -1)){
- result = lua_tonumber(L, -1);
+ result = lua_tointeger(L, -1);
got = true;
}
lua_pop(L, 1);
@@ -430,7 +442,7 @@ bool getintfield(lua_State *L, int table,
lua_getfield(L, table, fieldname);
bool got = false;
if(lua_isnumber(L, -1)){
- result = lua_tonumber(L, -1);
+ result = lua_tointeger(L, -1);
got = true;
}
lua_pop(L, 1);
diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h
index eefac0ed7..a5fbee765 100644
--- a/src/script/common/c_converter.h
+++ b/src/script/common/c_converter.h
@@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define C_CONVERTER_H_
#include <vector>
-#include <map>
+#include "util/cpp11_container.h"
#include "irrlichttypes_bloated.h"
#include "common/c_types.h"
@@ -60,7 +60,7 @@ bool getintfield(lua_State *L, int table,
bool getintfield(lua_State *L, int table,
const char *fieldname, u32 &result);
void read_groups(lua_State *L, int index,
- std::map<std::string, int> &result);
+ UNORDERED_MAP<std::string, int> &result);
bool getboolfield(lua_State *L, int table,
const char *fieldname, bool &result);
bool getfloatfield(lua_State *L, int table,