Macro
fli
define-foreign-variable the-name &key type accessor language
no-check => lisp-name
the-name ::= lisp-name | (lisp-name foreign-name [encoding]) |
(lisp-name foreign-string [encoding])
encoding ::= :source | :object | :lisp | :dbcs
accessor ::= :value | :address-of | read-only
Names the Lisp function which is used to access the foreign variable.
A symbol naming the Lisp accessor.
A symbol which is the name of the foreign variable.
A string containing the name of the foreign variable.
An option controlling how the Lisp variable name is translated to match the foreign variable name in the foreign DLL. The encoding option can be one of the following:
:source tells LispWorks that the string foreign-string or the symbol foreign-name is the name of the variable in the foreign source code. This is the default value of encoding.
:object tells LispWorks that the string foreign-string or the symbol foreign-name is the literal name of the variable in the foreign object code.
:lisp tells LispWorks that the symbol foreign-name is a Lisp symbol and must be translated and encoded.
:dbcs adds a suffix onto the variable name which will automatically change depending on whether Lisp image is started up in the Windows NT or Windows 95 operating system. The suffix is "A" for Windows 95 and "W" for Windows NT.
The FLI type corresponding to the type of the foreign variable to which Lisp is interfacing.
An option specifying what kind of accessor is generated for the variable. It can be one of the following:
:value gets the value of the foreign variable directly. This is the default value.
:address-of returns an FLI pointer to the foreign variable.
:read-only ensures that nosetf method is defined for the variable, which means that its value can be read, but it cannot be set.
The language in which the foreign source code for the variable is written. The default is:c.
Ifnil, the types of the arguments provided when the Lisp function is called are compared with the expected types and an error is raised if they do not match. Setting no-check tot overrides this check.
Specifies the module in which the foreign variable is defined. If it is the name of a module registered usingregister-module then that module is used to look up the variable. If the name of the module is a string then that module is automatically registered and used to look up the symbol.
A symbol naming the Lisp accessor.
define-foreign-variable defines a Lisp accessor which can be used to get and set the value of a variable defined in foreign code. fli:allocate-foreign-object, and the copy is then accessed. int num;
num1, to interface with the C variablenum. (fli:define-foreign-variable (num1 "num") :type :int)
num, and increase its value by 1: (num1) (incf (num1))
num2 interfaces withnum in a read-only manner. (fli:define-foreign-variable (num2 "num") :type :int :accessor :READ-ONLY)
num, but the second command raises an error, becausenum2 is read-only. (num2) (incf (num2))
num3, which accessesnum through pointers. (fli:define-foreign-variable (num3 "num") :type :int :accessor :address-of)
num, and to obtain the actual value stored bynum,num3 needs to be dereferenced. (num3) (fli:dereference (num3))