Created
November 22, 2016 06:36
-
-
Save chaddotson/473ffa55b594ec2a4135aef65fbbc679 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ctypes import * | |
class Point(Structure): | |
_fields_ = [ | |
("x", c_float), | |
("y", c_float) | |
] | |
def __str__(self): | |
return "x={0.x}, y={0.y}".format(self) | |
class Points(Structure): | |
_fields_ = [ | |
("num", c_int), | |
("points", POINTER(Point)) | |
] | |
def set(self, list_of_points): | |
l = len(list_of_points) | |
elems = (Point * l)(*list_of_points) | |
self.points = cast(elems, POINTER(Point)) | |
self.num = l | |
x = [Point(1,2), Point(3,4)] | |
y = Points() | |
y.set(x) | |
print y.points[0], y.points[1] | |
#t[:] = [Point(1, 2), Pointer(3, 4), Pointer(5, 6), Pointer(7, 8), Pointer(9, 10)] | |
print x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment