Sq Plus CPP Inheritance Failure
Last changed: -170.211.216.8

.

acaccov

Summary

The following code fails in two different ways. (Tested on release 25)

#include "sqplus.h"
#include <vector>

class Container
{
public:
		typedef std::vector<SquirrelObject> ObjectList;

		ObjectList mItems;

		int addItem(HSQUIRRELVM v)
		{
				SquirrelObject item;
				item.AttachToStackObject(-1);
				mItems.push_back(item);
				return 0;
		}
};

class Derived : public Container
{
		
};

DECLARE_INSTANCE_TYPE(Container)
DECLARE_INSTANCE_TYPE(Derived)

int _tmain(int argc, _TCHAR* argv[])
{
		SquirrelVM::Init();

		SqPlus::SQClassDef<Container>(_T("Container"))
				.funcVarArgs(&Container::addItem, _T("addItem"));

		SqPlus::SQClassDef<Derived>(_T("Derived"),_T("Container"));

		Derived d;

		const SQChar *script = _T("tmp <- {};\n d.addItem(tmp);");

		// Method 1
		// Fails with "Invalid Instance Type"
		SqPlus::BindVariable(&d, "d");
		SquirrelVM::RunScript(SquirrelVM::CompileBuffer(script));

		// Method 2
		// Fails with "Invalid Instance Type", but also causes a memory exception when dobj is destroyed
		SquirrelObject dobj(&d);
		SquirrelObject root = SquirrelVM::GetRootTable();
		root.SetValue("d", dobj);
		SquirrelVM::RunScript(SquirrelVM::CompileBuffer(script));

		SquirrelVM::Cleanup();

		return 0;
}

quote on auto insurance