1. Igor Baidiuk
  2. love-threads-table-marshalling

Commits

Igor Baidiuk  committed 11a86a5

Fixed pure virtual call. Have issues with nested tables

  • Participants
  • Parent commits ea697c7
  • Branches default

Comments (0)

Files changed (2)

File src/common/Variant.cpp

View file
  • Ignore whitespace
 			{
 				for (T *i = begin(), *e = end(); i != e; ++i)
 					i->~T();
-				this->~RefArray();
+				RefArray::~RefArray();
 				delete[] ((char*)this);
 			}
 		}
 	{ }
 
 	Variant::Variant(bool boolean)
+		: type(BOOLEAN)
 	{
-		type = BOOLEAN;
 		data.boolean = boolean;
 	}
 
 	Variant::Variant(double number)
+		: type(NUMBER)
 	{
-		type = NUMBER;
 		data.number = number;
 	}
 
 	Variant::Variant(const char *string, size_t len)
+		: type(STRING)
 	{
-		type = STRING;
 		if (!string || !len)
 			data.string = NULL;
 		else
 	}
 
 	Variant::Variant(char c)
+		: type(CHARACTER)
 	{
-		type = CHARACTER;
 		data.character = c;
 	}
 
 	Variant::Variant(void *userdata)
+		: type(LUSERDATA)
 	{
-		type = LUSERDATA;
 		data.light = userdata;
 	}
 
 	Variant::Variant(love::Type udatatype, void *userdata)
 	{
-		type = FUSERDATA;
-		data.full.type = udatatype;
 		if (udatatype != INVALID_ID)
 		{
+			type = FUSERDATA;
+			data.full.type = udatatype;
 			Proxy *p = (Proxy *) userdata;
 			flags = p->flags;
 			data.full.data = p->data;
 			((love::Object *) data.full.data)->retain();
 		}
 		else
-			data.full.data = userdata;
+		{
+			type = LUSERDATA;
+			data.light = userdata;
+		}
 	}
 
 	Variant::Variant(const Variant& other)
 
 	Variant& Variant::operator = (const Variant& other)
 	{
-		Variant::~Variant();
+		cleanup();
 		type = other.type;
 		switch (type)
 		{
 		case FUSERDATA:
 			data.full = other.data.full;
 			flags = other.flags;
-			if (data.full.type != INVALID_ID)
-				((love::Object*)data.full.data)->retain();
+			((love::Object*)data.full.data)->retain();
 			break;
 		case TUPLE:
 			if (data.tuple = other.data.tuple)
 		return *this;
 	}
 
-	Variant::~Variant()
+	void Variant::cleanup()
 	{
 		switch(type)
 		{
 					((RefString*)data.string)->release();
 				break;
 			case FUSERDATA:
-				if (data.full.type != INVALID_ID)
-					((love::Object *) data.full.data)->release();
+				((love::Object *) data.full.data)->release();
 				break;
 			case TUPLE:
 				if (data.tuple)
 		}
 	}
 
+	Variant::~Variant()
+	{
+		cleanup();
+	}
+
 	Variant Variant::getVariant(lua_State *L, int n)
 	{
 		size_t len = 0;
 				lua_pushlightuserdata(L, data.light);
 				break;
 			case FUSERDATA:
-				if (data.full.type != INVALID_ID)
 				{
 					const char *name = NULL;
 					love::types.find(data.full.type, name);
 					((love::Object *) data.full.data)->retain();
 					luax_newtype(L, name, flags, data.full.data);
 				}
-				else
-					lua_pushlightuserdata(L, data.full.data);
 				// I know this is not the same
 				// sadly, however, it's the most
 				// I can do (at the moment).
 				if (data.table)
 				{
 					RefTable *t = (RefTable*)data.table;
-					lua_checkstack(L, 4);
 					for (Pair *i = t->begin(), *e = t->end(); i != e; ++i)
 					{
 						i->first.toLua(L);

File src/common/Variant.h

View file
  • Ignore whitespace
 		Variant(void *userdata);
 		Variant(love::Type udatatype, void *userdata);
 
+		void cleanup();
+
 		static Variant getVariant(lua_State* L, int n);
 
 	public: