Skip to content

Instantly share code, notes, and snippets.

@chaddotson
Created November 22, 2016 06:36
Show Gist options
  • Save chaddotson/473ffa55b594ec2a4135aef65fbbc679 to your computer and use it in GitHub Desktop.
Save chaddotson/473ffa55b594ec2a4135aef65fbbc679 to your computer and use it in GitHub Desktop.
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