majkinetor
Joined: 24 May 2006 Posts: 3652 Location: Belgrade
|
Posted: Mon Jul 07, 2008 1:47 pm Post subject: |
|
|
I already told you,
| Code: | | associative arrays + syntax suggar = objects = structs |
as structs are just simple objects, without member functions. They must be handled differently then eventual AHK objects as AHK doesn't have anything but string varables so you don't need to define them, and structs are ment for communication with C APIs. One possible solution would be to add special array member that defines structure and DllCalls to be updated to receive arrays as input.
C structure
| Code: | struct {
int field1
char field2
dword field3
} S |
can be seen as associative array with 1 special array member, the one used to define structure in DllCall manner:
| Code: | S["_DEF_"] = "Int field1, Char field2, Uint field"
S["field1"] = -1
S["field2"] = "a"
S["field3"] = 14 |
If we imagine AHK supports true arrays with above notation then we would use struct as this:
| Code: | s._DEF_ := "Int field1, Char field2, Uint field3"
s.field1 := -1
s.field2 := "a"
s.filed3 := 14
DllCall(.... , "struct", S) |
s.field is syntax suggar for s["field"], usual notation for associative arrays. You can ask here why not allowing this notation generaly, but struct member names are different then general associative array keys - C variable name can't have space or special character while associatve array keys can be any type of string, for example s["my nasty $$ _/ key"] so dot notation in this case is not possible, but it suits fine for structures (and objects, for the same reason)
"struct" keyword in dllcall would say AHK to check for _DEF_ array member, and make appropriate binary structure based on it and values of struct fields.
If you need binary structure for your own things, we could have function struct( array ) that returns binary structure mentioned above so that above DllCall
is equal to
| Code: | | DllCall(..., "uint*", struct(S)) |
Some additinal effort is needed for complex structures (those containing other structers or arrays of bits but everything can be thought out with associative arrays implemented. _________________
 |
|