aboutsummaryrefslogtreecommitdiff
path: root/builtin/common
diff options
context:
space:
mode:
authorLars Müller <34514239+appgurueu@users.noreply.github.com>2022-07-14 20:50:21 +0200
committerGitHub <noreply@github.com>2022-07-14 20:50:21 +0200
commitac4eb746fe9da775a8bffe825a868581c0353169 (patch)
tree0f6ed4bfec89734b2168e8af24e545043b411de6 /builtin/common
parent6df69f9b5bea5b438498bbae7e9873bb99434439 (diff)
Deserialization: Restore backwards compat (#12519)
Diffstat (limited to 'builtin/common')
-rw-r--r--builtin/common/serialize.lua10
1 files changed, 10 insertions, 0 deletions
diff --git a/builtin/common/serialize.lua b/builtin/common/serialize.lua
index 6278e2739..caf989e69 100644
--- a/builtin/common/serialize.lua
+++ b/builtin/common/serialize.lua
@@ -188,6 +188,16 @@ local function dummy_func() end
local nan = (0/0)^1 -- +nan
function core.deserialize(str, safe)
+ -- Backwards compatibility
+ if str == nil then
+ core.log("deprecated", "minetest.deserialize called with nil (expected string).")
+ return nil, "Invalid type: Expected a string, got nil"
+ end
+ local t = type(str)
+ if t ~= "string" then
+ error(("minetest.deserialize called with %s (expected string)."):format(t))
+ end
+
local func, err = loadstring(str)
if not func then return nil, err end
155 156 157 158 159 160 161 162 163 164 165 166
/*
Minetest-c55
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef LUA_ITEM_H_
#define LUA_ITEM_H_

extern "C" {
#include <lua.h>
#include <lauxlib.h>
}

#include <vector>

#include "itemdef.h"
#include "content_sao.h"
#include "util/pointedthing.h"
#include "inventory.h"

#include "inventory.h"

ItemStack read_item(lua_State *L, int index);
std::vector<ItemStack> read_items(lua_State *L, int index);
void push_items(lua_State *L, const std::vector<ItemStack> &items);

class LuaItemStack
{
private:
	ItemStack m_stack;

	static const char className[];
	static const luaL_reg methods[];

	// Exported functions

	// garbage collector
	static int gc_object(lua_State *L);

	// is_empty(self) -> true/false
	static int l_is_empty(lua_State *L);

	// get_name(self) -> string
	static int l_get_name(lua_State *L);

	// get_count(self) -> number
	static int l_get_count(lua_State *L);

	// get_wear(self) -> number
	static int l_get_wear(lua_State *L);

	// get_metadata(self) -> string
	static int l_get_metadata(lua_State *L);

	// clear(self) -> true
	static int l_clear(lua_State *L);

	// replace(self, itemstack or itemstring or table or nil) -> true
	static int l_replace(lua_State *L);

	// to_string(self) -> string
	static int l_to_string(lua_State *L);

	// to_table(self) -> table or nil
	static int l_to_table(lua_State *L);

	// get_stack_max(self) -> number
	static int l_get_stack_max(lua_State *L);

	// get_free_space(self) -> number
	static int l_get_free_space(lua_State *L);

	// is_known(self) -> true/false
	// Checks if the item is defined.
	static int l_is_known(lua_State *L);