Re: FFI newby question: importing C functions

  • From: QuentinC <webmaster@xxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 26 Jun 2012 00:20:55 +0200

> 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 ? It is also correctly defined in stdlib.h.

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.

moreover, I don't know for luajit itself (I used allmost the default makefile without any change), but my program is actually compiled with the flag -std=gnu99, so I'm normally in C99 mode.

Thank you for the pure lua replacement. It's definitely better to use it, for something so simple.

Nonetheless, I'm anyway curious to know why I can access it in native C code without any problem but not in lua FFI. It's not impossible that I get this problem again with another function later, for which there wouldn't be a so simple pure lua replacement.

Thank you.

Other related posts: