diff --git a/src/hx/cppia/CppiaVars.cpp b/src/hx/cppia/CppiaVars.cpp index ad98ca47e..e97e82344 100644 --- a/src/hx/cppia/CppiaVars.cpp +++ b/src/hx/cppia/CppiaVars.cpp @@ -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]; } } diff --git a/test/cppia/Client.hx b/test/cppia/Client.hx index 710373f4b..7cd44d361 100644 --- a/test/cppia/Client.hx +++ b/test/cppia/Client.hx @@ -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; diff --git a/test/cppia/cases/TestCommon.hx b/test/cppia/cases/TestCommon.hx index eaacb5a76..19f8b0a7c 100644 --- a/test/cppia/cases/TestCommon.hx +++ b/test/cppia/cases/TestCommon.hx @@ -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'), []);