Re: Question about where to put C files

  • From: demetri <demetri.spanos@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 28 Jun 2012 13:58:04 -0700

> Do I put the straight c files, or o files, or .so files somewhere in
> particular?  Where do they need to be in order for luajit and the ffi
> extention to recognize the function declarations I put in my ffi.cdef[[ …
> ]] block?
>

You have two (and a half) options; if you use a stock LuaJIT binary then
you need to create .so or .dll files, and then use the ffi's dynamic
loading facility to import the symbols that you reference in your cdef.
This is basically the example given with the zlib library at
http://luajit.org/ext_ffi_tutorial.html.

Option 2.a is to compile a custom luajit from source, linking in static
libraries that export symbols into the global C namespace (then you can
access those functions from ffi.C.*). You can then use this LuaJIT binary
as you would the stock LuaJIT, but extended with extra capabilities. This
is essentially what happens with the Windows MessageBoxA example at
http://luajit.org/ext_ffi.html (since MessageBoxA is available as part of
the windows C runtime).

Option 2.b is essentially 2.a except you embed LuaJIT into a parent C/C++
application (in which case it's more like giving LuaJIT access to global
symbols in your application, rather than creating an extended stand-alone).
But procedurally this is essentially the same as Option 2.a.

I was a newbie not long ago so if you want to email me off-list feel free.

Demetri

Other related posts: