Re: FFI newby question: importing C functions

  • From: Mike Pall <mike-1206@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 25 Jun 2012 22:48:29 +0200

QuentinC wrote:
> I'm running luajit 2.0.0.10 compiled with MinGW 3.4.5 on windows 7 32 bits.
>
> [...]
>
> ffi.cdef[[ double round (double); ]]
> function math.round (n)
> return ffi.C.round(n)
> end

The round() function is only in the C99 standard, but not in C89.
MinGW links against MSVCRT, which is not C99-compliant.

function math.round(n) 
  if n >= 0 then return math.floor(n+0.5) 
  return math.ceil(n-0.5)
end

--Mike

Other related posts: