FFI newby question: importing C functions

  • From: QuentinC <webmaster@xxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 25 Jun 2012 22:21:53 +0200

Hello listers,

I'm new in lua and luajit. I have developped a simple text editor that uses luajit to extend its features with scripting.

I have already successfully loaded DLLs and import function from them using FFI. However, I have a problem to import standard and de-facto available functions (for those you don't need to load any supplementary DLL).

I'm running luajit 2.0.0.10 compiled with MinGW 3.4.5 on windows 7 32 bits.

This code works nicely  and I can see my beautiful message box appear :
ffi.cdef[[ int MessageBoxA (const void*, const char*, const char*, int) ; ]]
ffi.C.MessageBoxA(nil, "Hello world !", "Test", 48)


Infortunately, I need the standard round function missing from math table (I don't understand why they could have missed it in lua 5.1.4 but that's another topic). So I wrote that, but it doesn't work :

ffi.cdef[[ double round (double); ]]
function math.round (n)
return ffi.C.round(n)
end


When I call this math.round function above, I get an error telling that the function can't be resolved.

I have also tried to run this code directly in the interactive interpreter (luajit.exe), but the result is the same, so the problem don't appear to come from my host program.

IN luajit 2.0.0.9, the error message was different: it said something like "can't resolve, but operation has succeeded".

What's the problem ? What am I doing wrong ? What should I change to get it working ?
Thank you very much for your help.

Other related posts: