4

我有这个代码:

(define-foreign-library libc
  (:unix "libc.so.6"))
(use-foreign-library libc)
(defcfun "setlocale" :pointer (category :int) (locale :pointer)) 

我想做:

(with-foreign-string (locale "en_US.UTF-8")
    (setlocale XXXX locale))

如何找到各种 LC_xxx 常量的整数值,以便将它们传递给上面的调用?有没有更好的方法来实现这一目标?

4

2 回答 2

2

你应该在你的 Lisp 代码中重新声明常量。事实上,CFFI 可以为您做到这一点

于 2011-06-10T10:54:21.720 回答
1

我在我的 locale.h 中看到了这个:

/* These are the possibilities for the first argument to setlocale.
   The code assumes that the lowest LC_* symbol has the value zero.  */
#define LC_CTYPE          __LC_CTYPE
#define LC_NUMERIC        __LC_NUMERIC
#define LC_TIME           __LC_TIME
#define LC_COLLATE        __LC_COLLATE
#define LC_MONETARY       __LC_MONETARY
#define LC_MESSAGES       __LC_MESSAGES
#define LC_ALL            __LC_ALL
#define LC_PAPER          __LC_PAPER
#define LC_NAME           __LC_NAME
#define LC_ADDRESS        __LC_ADDRESS
#define LC_TELEPHONE      __LC_TELEPHONE
#define LC_MEASUREMENT    __LC_MEASUREMENT
#define LC_IDENTIFICATION __LC_IDENTIFICATION

和 bits/locale.h 包含:

enum
{
  __LC_CTYPE = 0,
  __LC_NUMERIC = 1,
  __LC_TIME = 2,
  __LC_COLLATE = 3,
  __LC_MONETARY = 4,
  __LC_MESSAGES = 5,
  __LC_ALL = 6,
  __LC_PAPER = 7,
  __LC_NAME = 8,
  __LC_ADDRESS = 9,
  __LC_TELEPHONE = 10,
  __LC_MEASUREMENT = 11,
  __LC_IDENTIFICATION = 12
};

您可以只编译一个打印它们的 C 程序。这就是 Groveller 所做的。

于 2011-07-03T08:54:49.173 回答