Show Changes Show Changes
Edit Edit
Print Print
Recent Changes Recent Changes
Subscriptions Subscriptions
Lost and Found Lost and Found
Find References Find References
Rename Rename
Administration Page Administration Page
Topic Locks Topic Locks

Search

History

10/5/2007 10:03:57 AM
-170.211.216.8
5/30/2007 12:36:03 PM
-125.72.28.38
5/28/2007 6:48:09 AM
-69.136.148.27
10/19/2006 11:45:32 AM
aeyr-71.202.158.38
List all versions List all versions

RSS feed for the SquirrelWiki namespace

Sq Plus CPP Inheritance Failure
.

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

Not logged in. Log in

squirrel's community wiki

This is FlexWiki, an open source wiki engine.

Change Style

Recent Topics