std::string name = luaL_checkstring(L, 1);
text = luaL_checkstring(L, 2);
if (name == "deprecated") {
- log_deprecated(L, text);
+ log_deprecated(L, text, 2);
return 0;
}
level = Logger::stringToLevel(name);
bool styled = false;
if (!lua_isnone(L, 2)) {
- styled = lua_toboolean(L, 2);
+ styled = readParam<bool>(L, 2);
lua_pop(L, 1);
}
return 1;
}
-// get_dig_params(groups, tool_capabilities[, time_from_last_punch])
+// get_dig_params(groups, tool_capabilities)
int ModApiUtil::l_get_dig_params(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ItemGroupList groups;
read_groups(L, 1, groups);
ToolCapabilities tp = read_tool_capabilities(L, 2);
- if(lua_isnoneornil(L, 3))
- push_dig_params(L, getDigParams(groups, &tp));
- else
- push_dig_params(L, getDigParams(groups, &tp,
- luaL_checknumber(L, 3)));
+ push_dig_params(L, getDigParams(groups, &tp));
return 1;
}
if(lua_isnoneornil(L, 3))
push_hit_params(L, getHitParams(groups, &tp));
else
- push_hit_params(L, getHitParams(groups, &tp,
- luaL_checknumber(L, 3)));
+ push_hit_params(L, getHitParams(groups, &tp, readParam<float>(L, 3)));
return 1;
}
lua_getglobal(L, "tostring"); // function to be called
lua_pushvalue(L, 1); // 1st argument
lua_call(L, 1, 1); // execute function
- std::string str(lua_tostring(L, -1)); // get result
+ std::string str = readParam<std::string>(L, -1); // get result
lua_pop(L, 1);
bool yes = is_yes(str);
return 1;
}
+// is_nan(arg)
+int ModApiUtil::l_is_nan(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+
+ lua_pushboolean(L, isNaN(L, 1));
+ return 1;
+}
+
// get_builtin_path()
int ModApiUtil::l_get_builtin_path(lua_State *L)
{
int level = -1;
if (!lua_isnone(L, 3) && !lua_isnil(L, 3))
- level = luaL_checknumber(L, 3);
+ level = readParam<float>(L, 3);
std::ostringstream os;
compressZlib(std::string(data, size), os, level);
NO_MAP_LOCK_REQUIRED;
const char *path = luaL_checkstring(L, 1);
bool list_all = !lua_isboolean(L, 2); // if its not a boolean list all
- bool list_dirs = lua_toboolean(L, 2); // true: list dirs, false: list files
+ bool list_dirs = readParam<bool>(L, 2); // true: list dirs, false: list files
CHECK_SECURE_PATH(L, path, false);
return 1;
}
+// safe_file_write(path, content)
+int ModApiUtil::l_safe_file_write(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ const char *path = luaL_checkstring(L, 1);
+ size_t size;
+ const char *content = luaL_checklstring(L, 2, &size);
+
+ CHECK_SECURE_PATH(L, path, true);
+
+ bool ret = fs::safeWriteToFile(path, std::string(content, size));
+ lua_pushboolean(L, ret);
+
+ return 1;
+}
+
+// request_insecure_environment()
int ModApiUtil::l_request_insecure_environment(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
}
// Check secure.trusted_mods
- const char *mod_name = lua_tostring(L, -1);
+ std::string mod_name = readParam<std::string>(L, -1);
std::string trusted_mods = g_settings->get("secure.trusted_mods");
trusted_mods.erase(std::remove_if(trusted_mods.begin(),
trusted_mods.end(), static_cast<int(*)(int)>(&std::isspace)),
NO_MAP_LOCK_REQUIRED;
size_t size;
const char *data = luaL_checklstring(L, 1, &size);
- bool hex = !lua_isboolean(L, 2) || !lua_toboolean(L, 2);
+ bool hex = !lua_isboolean(L, 2) || !readParam<bool>(L, 2);
// Compute actual checksum of data
std::string data_sha1;
API_FCT(get_password_hash);
API_FCT(is_yes);
+ API_FCT(is_nan);
API_FCT(get_builtin_path);
API_FCT(mkdir);
API_FCT(get_dir_list);
+ API_FCT(safe_file_write);
API_FCT(request_insecure_environment);
API_FCT(write_json);
API_FCT(is_yes);
+ API_FCT(is_nan);
API_FCT(compress);
API_FCT(decompress);