Commit e6240f40 authored by Wouter van Oortmerssen's avatar Wouter van Oortmerssen

Merge pull request #2790 from chobie/php-table-fix

(PHP) fixes getting indirect table, also fixes getInt method on 32bit machine
parents 18915372 4691558e
...@@ -399,8 +399,13 @@ class ByteBuffer ...@@ -399,8 +399,13 @@ class ByteBuffer
$sign = $index + (ByteBuffer::isLittleEndian() ? 3 : 0); $sign = $index + (ByteBuffer::isLittleEndian() ? 3 : 0);
$issigned = isset($this->_buffer[$sign]) && ord($this->_buffer[$sign]) & 0x80; $issigned = isset($this->_buffer[$sign]) && ord($this->_buffer[$sign]) & 0x80;
if (PHP_INT_SIZE > 4) {
// 4294967296 = 1 << 32 = Maximum unsigned 32-bit int // 4294967296 = 1 << 32 = Maximum unsigned 32-bit int
return $issigned ? $result - 4294967296 : $result; return $issigned ? $result - 4294967296 : $result;
} else {
// 32bit / Windows treated number as signed integer.
return $result;
}
} }
/** /**
......
...@@ -249,7 +249,13 @@ namespace php { ...@@ -249,7 +249,13 @@ namespace php {
NumToString(field.value.offset) + NumToString(field.value.offset) +
");\n"; ");\n";
code += Indent + Indent; code += Indent + Indent;
code += "return $o != 0 ? $obj->init($o + $this->bb_pos, $this->bb) : "; code += "return $o != 0 ? $obj->init(";
if (field.value.type.struct_def->fixed)
{
code += "$o + $this->bb_pos, $this->bb) : ";
} else {
code += "$this->__indirect($o + $this->bb_pos), $this->bb) : ";
}
code += GenDefaultValue(field.value) + ";\n"; code += GenDefaultValue(field.value) + ";\n";
code += Indent + "}\n\n"; code += Indent + "}\n\n";
} }
......
...@@ -188,7 +188,7 @@ class Monster extends Table ...@@ -188,7 +188,7 @@ class Monster extends Table
{ {
$obj = new Monster(); $obj = new Monster();
$o = $this->__offset(28); $o = $this->__offset(28);
return $o != 0 ? $obj->init($o + $this->bb_pos, $this->bb) : 0; return $o != 0 ? $obj->init($this->__indirect($o + $this->bb_pos), $this->bb) : 0;
} }
/** /**
...@@ -214,7 +214,7 @@ class Monster extends Table ...@@ -214,7 +214,7 @@ class Monster extends Table
{ {
$obj = new Stat(); $obj = new Stat();
$o = $this->__offset(32); $o = $this->__offset(32);
return $o != 0 ? $obj->init($o + $this->bb_pos, $this->bb) : 0; return $o != 0 ? $obj->init($this->__indirect($o + $this->bb_pos), $this->bb) : 0;
} }
/** /**
......
...@@ -37,6 +37,9 @@ ...@@ -37,6 +37,9 @@
"test1", "test1",
"test2" "test2"
], ],
enemy: {
name: "Fred"
},
testarrayofbools:[ testarrayofbools:[
true, false, true true, false, true
], ],
......
...@@ -30,6 +30,10 @@ function main() ...@@ -30,6 +30,10 @@ function main()
// We set up the same values as monsterdata.json: // We set up the same values as monsterdata.json:
$str = $fbb->createString("MyMonster"); $str = $fbb->createString("MyMonster");
$name = $fbb->createString('Fred');
\MyGame\Example\Monster::startMonster($fbb);
\MyGame\Example\Monster::addName($fbb, $name);
$enemy = \MyGame\Example\Monster::endMonster($fbb);
$inv = \MyGame\Example\Monster::CreateInventoryVector($fbb, array(0, 1, 2, 3, 4)); $inv = \MyGame\Example\Monster::CreateInventoryVector($fbb, array(0, 1, 2, 3, 4));
...@@ -62,6 +66,7 @@ function main() ...@@ -62,6 +66,7 @@ function main()
\MyGame\Example\Monster::AddTest($fbb, $mon2); \MyGame\Example\Monster::AddTest($fbb, $mon2);
\MyGame\Example\Monster::AddTest4($fbb, $test4); \MyGame\Example\Monster::AddTest4($fbb, $test4);
\MyGame\Example\Monster::AddTestarrayofstring($fbb, $testArrayOfString); \MyGame\Example\Monster::AddTestarrayofstring($fbb, $testArrayOfString);
\MyGame\Example\Monster::AddEnemy($fbb, $enemy);
\MyGame\Example\Monster::AddTestbool($fbb, false); \MyGame\Example\Monster::AddTestbool($fbb, false);
$mon = \MyGame\Example\Monster::EndMonster($fbb); $mon = \MyGame\Example\Monster::EndMonster($fbb);
...@@ -132,6 +137,10 @@ function test_buffer(Assert $assert, Google\FlatBuffers\ByteBuffer $bb) { ...@@ -132,6 +137,10 @@ function test_buffer(Assert $assert, Google\FlatBuffers\ByteBuffer $bb) {
$assert->strictEqual($monster->GetTestarrayofstringLength(), 2); $assert->strictEqual($monster->GetTestarrayofstringLength(), 2);
$assert->strictEqual($monster->GetTestarrayofstring(0), 'test1'); $assert->strictEqual($monster->GetTestarrayofstring(0), 'test1');
$assert->strictEqual($monster->GetTestarrayofstring(1), 'test2'); $assert->strictEqual($monster->GetTestarrayofstring(1), 'test2');
$fred = $monster->getEnemy();
$assert->Equal('Fred', $fred->getName());
$assert->strictEqual($monster->GetTestbool(), false); $assert->strictEqual($monster->GetTestbool(), false);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment