diff options
-rw-r--r-- | lisplib.c | 6 | ||||
-rw-r--r-- | share/txr/stdlib/ffi.tl | 12 | ||||
-rw-r--r-- | txr.1 | 42 |
3 files changed, 57 insertions, 3 deletions
@@ -524,9 +524,9 @@ static val ffi_set_entries(val dlt, val fun) { val name[] = { lit("with-dyn-lib"), lit("deffi"), lit("deffi-type"), lit("deffi-cb"), - lit("deffi-var"), lit("typedef"), lit("sizeof"), lit("alignof"), - lit("offsetof"), lit("arraysize"), lit("elemsize"), lit("elemtype"), - lit("ffi"), lit("carray-ref"), lit("carray-sub"), + lit("deffi-sym"), lit("deffi-var"), lit("typedef"), lit("sizeof"), + lit("alignof"), lit("offsetof"), lit("arraysize"), lit("elemsize"), + lit("elemtype"), lit("ffi"), lit("carray-ref"), lit("carray-sub"), nil }; set_dlt_entries(dlt, name, fun); diff --git a/share/txr/stdlib/ffi.tl b/share/txr/stdlib/ffi.tl index a041692f..a430f777 100644 --- a/share/txr/stdlib/ffi.tl +++ b/share/txr/stdlib/ffi.tl @@ -96,6 +96,18 @@ (defmacro deffi-cb-unsafe (:form f name rettype argtypes) (sys:deffi-cb-expander f name rettype argtypes nil nil)) +(defmacro deffi-sym (:form f name var-expr : type-sym) + (let ((var-ref (cond + ((stringp var-expr) + ^(dlsym-checked sys:ffi-lib ,var-expr)) + ((consp var-expr) + (mac-param-bind f (sym ver) var-expr + ^(dlvsym-checked sys:ffi-lib ,sym ,ver))) + (t var-expr)))) + ^(defparml ,name ,(if type-sym + ^(cptr-cast ',type-sym ,var-ref) + var-ref)))) + (defmacro deffi-var (:form f name var-expr type) (let ((var-ref (cond ((stringp var-expr) @@ -56438,6 +56438,48 @@ form need not be surrounded by a call to the macro. .RE +.coNP Macro @ deffi-sym +.synb +.mets (deffi-sym < name < var-expr <> [ type-sym ]) +.syne +.desc +The +.code deffi-sym +macro defines a global lexical variable called +.code name +whose value is a +.code cptr +object that refers to a symbol in a foreign library. + +The +.meta name +argument gives the name for the variable to be defined. +This definition takes place place as if by the +.code defparml +macro. + +The +.meta var-expr +is syntax which specifies the foreign pointer, using exactly the same +conventions as described for the +.code deffi-var +macro, allowing for a short-hand notation if this form is +enclosed in a +.code with-dyn-lib +macro invocation. + +The optional +.meta type-sym +argument must be a symbol. If it is absent, it defaults to nil. +This argument specifies the type label for the +.code cptr +object which holds the pointer to the foreign symbol. + +The result value of +.meta deffi-sym +is the symbol +.metn name . + .coNP Macro @ typedef .synb .mets (typedef < name << type-syntax ) |