Skip to content

Commit

Permalink
ctypes supports v2.1 and adds ctypes.struct.__Enum
Browse files Browse the repository at this point in the history
  • Loading branch information
thqby committed Sep 25, 2023
1 parent 344f2fe commit b2c3d10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Native/Native.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class Native extends Func {
if !mems.HasOwnProp(name)
t := mems.%name% := {}
else t := mems.%name%
t.%sub% := me := this.Method(pbase, method, mit, minparams, maxparams, id)
t.DefineProp sub, me := this.Method(pbase, method, mit, minparams, maxparams, id)
NumPut('ptr', pname, ObjPtr(me), 3 * A_PtrSize + 8)
pmem += A_PtrSize - 3
} else {
Expand Down Expand Up @@ -297,7 +297,7 @@ class Native extends Func {
NumPut('char', 1, NumPut('ptr', IsObject(prototype) ? ObjPtr(prototype) : prototype, p) + A_PtrSize + 3), ac := pc := MinParams := 1
IsVariadic := false, MaxResultTokens := 0
if sig is Array {
if sig.Length > 1
if sig.Length
ret := sig.RemoveAt(1), smdf.Size += sig.Length, ret is String && ret := mdtypes.%ret%
else ret := 0
opt := false, retval := false, out := 0
Expand Down
15 changes: 10 additions & 5 deletions ctypes.ahk
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/************************************************************************
* @description create struct, union, array and pointer binding, and use it like ahk object
* @author thqby
* @date 2023/07/19
* @version 1.0.4
* @date 2023/09/25
* @version 1.0.5
***********************************************************************/
class ctypes {
Expand Down Expand Up @@ -74,14 +74,14 @@ class ctypes {
* @return {this}
*/
static from_ptr(ptr, size := 0, root := 0) {
static offset_ptr := 3 * A_PtrSize + 8
static offset_ptr := (VerCompare(A_AhkVersion, '2.1-alpha.3') >= 0 ? 5 : 3) * A_PtrSize + 8
if !ptr
return 0
NumPut('ptr', ptr, 'uptr', size || this.size, ObjPtr(obj := (Buffer.Call)(this)), offset_ptr)
NumPut('ptr', ptr, 'uptr', size || this.size, ObjPtr(obj := super()), offset_ptr)
obj.DefineProp('__Delete', { call: __del }), root && obj.DefineProp('__root', { value: root })
return obj
__del(this) {
try this.base.__Delete()
try (this.base.__Delete)(this)
NumPut('ptr', 0, ObjPtr(this), offset_ptr)
}
}
Expand Down Expand Up @@ -254,6 +254,11 @@ class ctypes {
return get_buf_size(this)
}

__Enum(n?) {
i := 0, n := (fields := this.__fields).Length
return (&k?, &v?, *) => (i < n ? (v := this.%k := fields[++i][2]%, true) : false)
}

static name => this.Prototype.__Class

static __max_align => 1
Expand Down

0 comments on commit b2c3d10

Please sign in to comment.