Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/facebook/luaffifb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2015-07-21 21:41:51 +0300
committerSam Gross <colesbury@gmail.com>2015-07-21 21:41:51 +0300
commit0b7a623c557fffc6dca390c4072e950184ef8207 (patch)
tree0da95ceec3bdce2f775bb6ab731e3dd082fd2db3
parentfb4b9e359d250da31ba03fcfd6b96adcab4dece3 (diff)
Remove reference flag when ereferencing a pointer in a struct
This fixes the access of something like: struct Foo { int bar[3]; } struct Foo foo; foo.bar[0] = 1;
-rw-r--r--ffi.c1
-rw-r--r--test.lua24
2 files changed, 25 insertions, 0 deletions
diff --git a/ffi.c b/ffi.c
index 7fca4f9..a481b3c 100644
--- a/ffi.c
+++ b/ffi.c
@@ -1604,6 +1604,7 @@ static ptrdiff_t lookup_cdata_index(lua_State* L, int idx, int ct_usr, struct ct
ct->is_array = 0;
ct->pointers--;
ct->const_mask >>= 1;
+ ct->is_reference = 0;
lua_pushvalue(L, ct_usr);
diff --git a/test.lua b/test.lua
index ec37967..1393313 100644
--- a/test.lua
+++ b/test.lua
@@ -906,5 +906,29 @@ assert(ffi.istype('complex', sum))
sum = ffi.C.add_fc(ffi.new('complex float', 1, 2), ffi.new('complex float', 3, 5))
assert(ffi.istype('complex float', sum))
+ffi.cdef [[
+struct Arrays {
+ int ints[3];
+ unsigned int uints[3];
+};
+struct ArrayOfArrays {
+ struct Arrays arrays[3];
+};
+]]
+
+local struct = ffi.new('struct Arrays')
+local structOfStructs = ffi.new('struct ArrayOfArrays')
+for i=1,3 do
+ struct.ints[i] = i
+ struct.uints[i] = i
+ structOfStructs.arrays[0].ints[i] = i
+end
+for i=1,3 do
+ assert(struct.ints[i] == i)
+ assert(struct.uints[i] == i)
+ assert(structOfStructs.arrays[0].ints[i] == i)
+end
+
+
print('Test PASSED')