[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **question about cdata type identification**
**From**: Francesco Abbate <francesco.bbt@...>
**Date**: Mon, 18 Apr 2011 10:00:12 +0200

Hi Mike,
I'm currently working on a matrix module based on LuaJIT2 plus FFI
without any use of any C wrapper functions. The module should permit
to work with both real and complex number and I'm planning to have
generic arithmetic operations that can operate with mixed operands of
real/complex number or real/complex matrices.
For the moment everything works really nicely with FFI, it is amazing
how you can have both the simplicity of Lua programming and, at the
same time, have access to low level C function and since the
introduction of metatypes all the needed functionalities are
available.
The datatype than I'm using for complex number is the native C
'complex' type from the C99 standard.
The problem here is that for the arithmetic operators I need to know
if the operands are real or complex number or real or complex
matrices. The problem is that if I use the 'type' function I get can
obtain just 'number' or 'cdata' and I have no means to discriminate
between, for example, a complex number and a matrix because both are
cdata.
I can imagine some workarounds but these solutions are all not
satisfying and I have the feeling that we lack a primitive FFI
function to have information about the C type of a cdata object.
I was thinking that may be a function ffi.ctype could make the affair.
The function should return a string that identify the C type of the
object. What do you think of this idea ?
Otherwise, am I missing something obvious to obtain the informations
that I need ?
Thanks in advance for any help.
Francesco