Open nddrylliog opened 10 years ago
Heh, good point! It works with:
objectGroup = ffi.cast(ffi.typeof("$*", tiled_ObjectGroup.ObjectGroup), tlayer)
because tiled_ObjectGroup.ObjectGroup
is a struct type.
I don't think we can do this in an easy way using only ffi, so a convenience function would be good. We could have a howling.cast(type, value)
which just runs the type parameter through to_ctype
, which already exists as a convenience function. What do you think?
But I tried exactly that! And I swear luaffi was complaining.
I just added a howling.cast
function. The above line can be rewritten as:
howling.cast(tiled_ObjectGroup.ObjectGroup, tlayer)
What do you think?
Practical case: using ooc-tiled, get an instance of 'Layer' from list.get, we want to access maps from 'ObjectGroup' (a subclass of 'MapLayer').
I tried all combinations of ffi.cast / typeof that I could find but I couldn't do it. You can look it up on lemon-stache I have a util method that just does pointer casting.