How can we convert C 0x00000001u (unsigned int in C) to Common Lisp ?

Luís Oliveira luismbo at gmail.com
Sun Jun 28 15:02:46 UTC 2020


The various C integer types map to Lisp integers, so if you want to
define the 0x00000010u constant you can use the Lisp value 16. (You
can use Lisp's hexadecimal syntax, of course: #x10.)

You may find the cl-sdl2 project
<https://github.com/lispgames/cl-sdl2> interesting. You can use it
and/or read its source to learn how to access SDL2 using CFFI.

Cheers,
Luís


On Sat, 27 Jun 2020 at 13:40, oleg harput <olegharput at gmail.com> wrote:
>
> i am trying to reach C SDL2 using CFFI, in C SDL2 there many functions like int "SDL_Init(Uint32 flags)"
> its return value is integer but its are arguments are defined like (in source code)
> #define SDL_INIT_TIMER          0x00000001u
> #define SDL_INIT_AUDIO          0x00000010u
> #define SDL_INIT_VIDEO          0x00000020u  /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
> #define SDL_INIT_JOYSTICK       0x00000200u  /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */
> #define SDL_INIT_HAPTIC         0x00001000u
> #define SDL_INIT_GAMECONTROLLER 0x00002000u  /**< SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK */
> #define SDL_INIT_EVENTS         0x00004000u
> #define SDL_INIT_SENSOR         0x00008000u
> when calling "SDL_Init" using CFFI in CL i did not know how to call arguments like SDL_INIT_TIMER,SDL_INIT_AUDIO,SDL_INIT_VIDEO,... so i tried instead of calling them, i tried to insert their corresping values (they are hexidecimal unsigned integers in C) like
> (cffi:foreign-funcall "SDL_Init"
>      :uint32 32;;for  #define SDL_INIT_VIDEO          0x00000020u
>      :int)
> but i am not sure that was a valid transformation or not(32 in CL corresponds to 0x00000020u in C or not)
> A better option is to call SDL_INIT_TIMER,SDL_INIT_AUDIO,... directly from cffi but i don not know how because they seemed undefined.
> Do you know how to call SDL_INIT_TIMER, SDL_INIT_AUDIO ... using CFFI?
> And can you tell me the transformation rules (if there are any) the numbers from C to CL using CFFI?
>
> пт, 26 июн. 2020 г. в 23:58, Luís Oliveira <luismbo at gmail.com>:
>>
>> On Fri, 26 Jun 2020 at 20:52, oleg harput <olegharput at gmail.com> wrote:
>> > How can we convert C 0x00000001u (unsigned int in C) to Common Lisp using CFFI?
>> >
>> > Can we type directly 1?(Is this a valid translation to CL?)
>>
>> In what context?
>>
>> --
>> Luís Oliveira
>> http://kerno.org/~luis/



--
Luís Oliveira
http://kerno.org/~luis/



More information about the cffi-devel mailing list