Re: FFI newby question: importing C functions

  • From: Mike Pall <mike-1206@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 26 Jun 2012 01:25:25 +0200

QuentinC wrote:
> > The round() function is only in the C99 standard, but not in C89.
> > MinGW links against MSVCRT, which is not C99-compliant.
> 
> In that case, why can I use it without any problem in my C code ?

The missing functions are part of the static libmingwex.a library.
It's automatically linked in by MinGW (but only the functions
needed by the C code). AFAIK these functions are neither exported
nor available from any other DLL.

> A classic wrapper like this one would perfectly work :
> int round2 (lua_State* l) {
> lua_pushnumber(l, round(luaL_checknumber(l,1)));
> return 1;
> }
>
> But as I observed, FFI calls are much faster compared to wrapped
> functions in many cases (and you don't have to bother with trivial
> wrappers), so I though it was better to use FFI.

Sure, but instead of a classic Lua/C API wrapper, you could use a
direct wrapper. Then export the wrapper function and bind to it
via the FFI.

[Not that you'd want to do this for round() -- the implementation
in MinGW is rather suboptimal.]

--Mike

Other related posts: