Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/hx/cppia/CppiaVars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,9 @@ void CppiaVar::linkVarTypes(CppiaModule &cppia, int &ioOffset)
AlignOffset(exprType, ioOffset);
offset = ioOffset;

switch(exprType)
{
case etInt: ioOffset += sizeof(int); storeType=fsInt; break;
case etFloat: ioOffset += sizeof(Float);storeType=fsFloat; break;
case etString: ioOffset += sizeof(String);storeType=fsString; break;
case etObject: ioOffset += sizeof(hx::Object *);storeType=fsObject; break;
case etVoid:
case etNull:
break;
}
storeType = typeId==0 ? fsObject : fieldStorageFromType(type);

ioOffset += sTypeSize[exprType];
}
}

Expand Down
22 changes: 22 additions & 0 deletions test/cppia/Client.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@ class ClientFoo implements IFoo {
}
}

class ClientBoolField {

public var flag:Bool = true;
public var offFlag:Bool = false;

public static var staticFlag:Bool = true;

public function new() {}

public function readFlag():Bool return flag;

public function readOffFlag():Bool return offFlag;

public function flagToString():String return "" + flag;

public function branchOnFlag():Int return flag ? 10 : 20;

public function branchOnOffFlag():Int return offFlag ? 10 : 20;

public function clearFlag():Bool { flag = false; return flag; }
}

class Client
{
public static var clientBool0 = true;
Expand Down
53 changes: 53 additions & 0 deletions test/cppia/cases/TestCommon.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,59 @@ class TestCommon extends Test {
Assert.equals(2, Common.callbackSet, 'Bad cppia closure');
}

@:depends(testStatus)
function testBoolMemberStorage() {
final cls = Type.resolveClass('ClientBoolField');

if (Assert.notNull(cls, 'Unable to resolve ClientBoolField')) {
final obj = Type.createInstance(cls, []);

Assert.equals('true', Std.string(Reflect.field(obj, 'flag')), 'Member Bool did not read back as a boolean');
Assert.equals('true', Std.string(Reflect.field(cls, 'staticFlag')), 'Static Bool did not read back as a boolean');
}
}

@:depends(testStatus)
function testBoolMemberFromScript() {
final cls = Type.resolveClass('ClientBoolField');

if (Assert.notNull(cls, 'Unable to resolve ClientBoolField')) {
final obj = Type.createInstance(cls, []);

Assert.equals(true, Reflect.callMethod(obj, Reflect.field(obj, 'readFlag'), []),
'Script read of a true Bool member failed');
Assert.equals(false, Reflect.callMethod(obj, Reflect.field(obj, 'readOffFlag'), []),
'Script read of a false Bool member failed');
Assert.equals('true', Reflect.callMethod(obj, Reflect.field(obj, 'flagToString'), []),
'Bool member did not stringify as a boolean');
Assert.equals(10, Reflect.callMethod(obj, Reflect.field(obj, 'branchOnFlag'), []),
'Branch on a true Bool member took the wrong arm');
Assert.equals(20, Reflect.callMethod(obj, Reflect.field(obj, 'branchOnOffFlag'), []),
'Branch on a false Bool member took the wrong arm');
}
}

@:depends(testStatus)
function testBoolMemberWrite() {
final cls = Type.resolveClass('ClientBoolField');

if (Assert.notNull(cls, 'Unable to resolve ClientBoolField')) {
final obj = Type.createInstance(cls, []);

Assert.equals(false, Reflect.callMethod(obj, Reflect.field(obj, 'clearFlag'), []),
'Script write of a Bool member did not stick');
Assert.equals('false', Std.string(Reflect.field(obj, 'flag')),
'Reflection did not see the script write');

Reflect.setField(obj, 'flag', true);

Assert.equals(true, Reflect.callMethod(obj, Reflect.field(obj, 'readFlag'), []),
'Script did not see the reflection write');
Assert.equals(10, Reflect.callMethod(obj, Reflect.field(obj, 'branchOnFlag'), []),
'Branch did not see the reflection write');
}
}

@:depends(testStatus)
function testInterfaceCalling() {
final obj : IFoo = Type.createInstance(Type.resolveClass('ClientFoo'), []);
Expand Down