What is PY?
There are two ways to avoid specifying the parameter type:
- Use only predefined functions, for which the parameter types are known.
- Make assumptions about the parameter type.
In neither case is the actual function call
smarter, but one might be more or less efficient, (un)safe, etc.
As far as I can tell,
Python's CFFI uses #1. It takes a full C definition of a function and produces a function object. In some cases it
invokes a C compiler.
Python's ctypes uses #1 or #2. If you don't tell it what arg types the function has, it makes assumptions based on what values you pass.
For #1, you can just write wrapper functions, or use AutoHotkey_H and #DllImport.
For #2, if we assume that the parameter should be "str" for any string, "double" for any floating-point number and "ptr" otherwise, you won't have to specify the
type, but:
- Functions that do not accept a UTF-16 string would require you to manually convert the string before passing it (or call a function that we add for that purpose; e.g. AStr(value)).
- There would be no way to specify that the parameter is for output. Instead, you will have to pass a buffer and read from it afterward.
- You would need to manually reinterpret the return value as the appropriate data type, or find a new way to specify the return type that isn't ambiguous with a parameter value.
- You would not be able to specify other types without the use of additional functions (i.e. converting the value to a "ptr").
It does not make using a dll
simpler. If the parameter types aren't predefined, you must be even more careful to pass the appropriate type of value, or do even more work to convert values to a type appropriate for the function.
It can be done in script, but not very efficiently.