Skip to content

Commit 7b8d372

Browse files
ShadowNinjakwolekr
authored andcommittedOct 15, 2015
Use warningstream for deprecated field messages and refactor log_deprecated
1 parent 659922f commit 7b8d372

File tree

2 files changed

+30
-40
lines changed

2 files changed

+30
-40
lines changed
 

Diff for: ‎src/script/common/c_content.cpp

+19-20
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ ItemDefinition read_item_definition(lua_State* L,int index,
7676
getboolfield(L, index, "liquids_pointable", def.liquids_pointable);
7777

7878
warn_if_field_exists(L, index, "tool_digging_properties",
79-
"deprecated: use tool_capabilities");
79+
"Deprecated; use tool_capabilities");
8080

8181
lua_getfield(L, index, "tool_capabilities");
8282
if(lua_istable(L, -1)){
@@ -427,17 +427,17 @@ ContentFeatures read_content_features(lua_State *L, int index)
427427

428428
// Warn about some deprecated fields
429429
warn_if_field_exists(L, index, "wall_mounted",
430-
"deprecated: use paramtype2 = 'wallmounted'");
430+
"Deprecated; use paramtype2 = 'wallmounted'");
431431
warn_if_field_exists(L, index, "light_propagates",
432-
"deprecated: determined from paramtype");
432+
"Deprecated; determined from paramtype");
433433
warn_if_field_exists(L, index, "dug_item",
434-
"deprecated: use 'drop' field");
434+
"Deprecated; use 'drop' field");
435435
warn_if_field_exists(L, index, "extra_dug_item",
436-
"deprecated: use 'drop' field");
436+
"Deprecated; use 'drop' field");
437437
warn_if_field_exists(L, index, "extra_dug_item_rarity",
438-
"deprecated: use 'drop' field");
438+
"Deprecated; use 'drop' field");
439439
warn_if_field_exists(L, index, "metadata_name",
440-
"deprecated: use on_add and metadata callbacks");
440+
"Deprecated; use on_add and metadata callbacks");
441441

442442
// True for all ground-like things like stone and mud, false for eg. trees
443443
getboolfield(L, index, "is_ground_content", f.is_ground_content);
@@ -639,14 +639,13 @@ void pushnode(lua_State *L, const MapNode &n, INodeDefManager *ndef)
639639

640640
/******************************************************************************/
641641
void warn_if_field_exists(lua_State *L, int table,
642-
const char *fieldname, const std::string &message)
642+
const char *name, const std::string &message)
643643
{
644-
lua_getfield(L, table, fieldname);
645-
if(!lua_isnil(L, -1)){
646-
//TODO find way to access backtrace fct from here
647-
// infostream<<script_get_backtrace(L)<<std::endl;
648-
infostream<<"WARNING: field \""<<fieldname<<"\": "
649-
<<message<<std::endl;
644+
lua_getfield(L, table, name);
645+
if (!lua_isnil(L, -1)) {
646+
warningstream << "Field \"" << name << "\": "
647+
<< message << std::endl;
648+
infostream << script_get_backtrace(L) << std::endl;
650649
}
651650
lua_pop(L, 1);
652651
}
@@ -705,7 +704,7 @@ ItemStack read_item(lua_State* L, int index,Server* srv)
705704
}
706705
catch(SerializationError &e)
707706
{
708-
infostream<<"WARNING: unable to create item from itemstring"
707+
warningstream<<"unable to create item from itemstring"
709708
<<": "<<itemstring<<std::endl;
710709
return ItemStack();
711710
}
@@ -840,14 +839,14 @@ ToolCapabilities read_tool_capabilities(
840839
getintfield(L, table_groupcap, "uses", groupcap.uses);
841840
// DEPRECATED: maxwear
842841
float maxwear = 0;
843-
if(getfloatfield(L, table_groupcap, "maxwear", maxwear)){
844-
if(maxwear != 0)
842+
if (getfloatfield(L, table_groupcap, "maxwear", maxwear)){
843+
if (maxwear != 0)
845844
groupcap.uses = 1.0/maxwear;
846845
else
847846
groupcap.uses = 0;
848-
infostream<<script_get_backtrace(L)<<std::endl;
849-
infostream<<"WARNING: field \"maxwear\" is deprecated; "
850-
<<"should replace with uses=1/maxwear"<<std::endl;
847+
warningstream << "Field \"maxwear\" is deprecated; "
848+
<< "replace with uses=1/maxwear" << std::endl;
849+
infostream << script_get_backtrace(L) << std::endl;
851850
}
852851
// Read "times" table
853852
lua_getfield(L, table_groupcap, "times");

Diff for: ‎src/script/common/c_internal.cpp

+11-20
Original file line numberDiff line numberDiff line change
@@ -163,35 +163,26 @@ void script_run_callbacks_f(lua_State *L, int nargs,
163163
void log_deprecated(lua_State *L, const std::string &message)
164164
{
165165
static bool configured = false;
166-
static bool dolog = false;
167-
static bool doerror = false;
166+
static bool do_log = false;
167+
static bool do_error = false;
168168

169-
// performance optimization to not have to read and compare setting for every logline
169+
// Only read settings on first call
170170
if (!configured) {
171171
std::string value = g_settings->get("deprecated_lua_api_handling");
172172
if (value == "log") {
173-
dolog = true;
173+
do_log = true;
174174
} else if (value == "error") {
175-
dolog = true;
176-
doerror = true;
175+
do_log = true;
176+
do_error = true;
177177
}
178178
}
179179

180-
if (doerror) {
181-
if (L != NULL) {
180+
if (do_log) {
181+
warningstream << message << std::endl;
182+
if (do_error)
182183
script_error(L, LUA_ERRRUN, NULL, NULL);
183-
} else {
184-
FATAL_ERROR("Can't do a scripterror for this deprecated message, "
185-
"so exit completely!");
186-
}
187-
}
188-
189-
if (dolog) {
190-
/* abusing actionstream because of lack of file-only-logged loglevel */
191-
actionstream << message << std::endl;
192-
if (L != NULL) {
193-
actionstream << script_get_backtrace(L) << std::endl;
194-
}
184+
else
185+
infostream << script_get_backtrace(L) << std::endl;
195186
}
196187
}
197188

0 commit comments

Comments
 (0)
Please sign in to comment.