mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-21 16:55:01 -05:00
Array passing works, with copy overhead.
This commit is contained in:
parent
6825eeb179
commit
a103641897
@ -32,6 +32,9 @@ c = Color(DLL)
|
||||
ret = c.find((0, 0, 100, 100), 0)
|
||||
print ret
|
||||
|
||||
ret = c.findAll((0, 0, 100, 100), 0)
|
||||
print ret
|
||||
|
||||
|
||||
m = Mouse(DLL)
|
||||
|
||||
@ -53,5 +56,4 @@ print m.getPos()
|
||||
if hasattr(ret,'__iter__'):
|
||||
m.setPos(ret)
|
||||
|
||||
|
||||
del DLL
|
||||
|
@ -1,6 +1,7 @@
|
||||
from ctypes import *
|
||||
from mmltypes import isiterable
|
||||
from mmltypes import POINT, PPOINT, PINTEGER
|
||||
from mmltypes import PascalArray
|
||||
|
||||
|
||||
class ColorException(Exception):
|
||||
@ -24,7 +25,19 @@ class Color(object):
|
||||
self._mc.dll.findColor(byref(x), byref(y), color, *box)
|
||||
return (x, y)
|
||||
|
||||
def findAll(self, box, color):
|
||||
ptr = PPOINT()
|
||||
self._mc.dll.findColors(byref(ptr), color, *box)
|
||||
arr = PascalArray(POINT, ptr, self._mc)
|
||||
print 'Length:', len(arr)
|
||||
# for i in range(len(arr)):
|
||||
# print i, arr[i].x, arr[i].y
|
||||
return arr
|
||||
|
||||
def _initialiseDLLFuncs(self):
|
||||
self._mc.dll.findColor.restype = c_int
|
||||
self._mc.dll.findColor.argtypes = [PINTEGER, PINTEGER, c_int, c_int,
|
||||
c_int, c_int, c_int]
|
||||
self._mc.dll.findColors.restype = c_int
|
||||
self._mc.dll.findColors.argtypes = [POINTER(PPOINT), c_int, c_int,
|
||||
c_int, c_int, c_int]
|
||||
|
@ -8,6 +8,33 @@ class POINT(Structure):
|
||||
_fields_ = [('x', c_int),
|
||||
('y', c_int)]
|
||||
|
||||
class PascalArray(object):
|
||||
def __init__(self, pastype, ptr, MC):
|
||||
self._type = pastype
|
||||
self._p = ptr
|
||||
self._mc = MC
|
||||
|
||||
def __del__(self):
|
||||
self._mc.dll.fpc_freemem_(self._p)
|
||||
|
||||
def __len__(self):
|
||||
return cast(self._p, POINTER(c_ulong))[0]
|
||||
|
||||
def __getitem__(self, pos):
|
||||
if pos > len(self):
|
||||
print 'Out of range'
|
||||
return None
|
||||
return cast(self._p, POINTER(self._type))[pos+1]
|
||||
|
||||
def __setitem__(self, pos, item):
|
||||
if pos > len(self):
|
||||
print 'Out of range'
|
||||
return
|
||||
if sizeof(item) != sizeof(self._type):
|
||||
print 'Incorrect structure'
|
||||
return
|
||||
cast(self._p, POINTER(self._type))[pos] = item
|
||||
|
||||
PPOINT = POINTER(POINT)
|
||||
PINTEGER = POINTER(c_int)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user