lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Andy Stark wrote:
> - at the bottom of the list of selected Lua Programming Gems there is
> an item called "Interpreted C modules" which I am guessing is an
> inline C system like Perl's CPR (apologies to Jerome if I am wrong
> about this).   
> This might provide a good basis to show how C source could be mixed
> together with Lua source. 

You're not totally wrong, but it requires some precision.

The gem and the underlying code is much simpler than CPR. It's even
simpler than Inline.pm on which CPR is built. For readers that don't
know any of these two (like me a few minutes ago), Inline.pm is Perl
module that allows to inline C code in Perl source file, with macros
letting C code access the Perl API. CPR is built on top of that to make
a C interpreter with inline Perl.

My gem is based on two (yet to be released) modules. The first one,
luatcc, is a rewrite of Javier Guerra's libtcc binding. It allows to
compile inline C, but uses the existing Lua API. The second one,
luatcc.loader, is a loader modules that modify require behaviour, so
that Lua code like:

require 'somepackage.somemodule'

will load the file somepackage/somemodule.c, compile it, and find and
call the function luaopen_somepackage_somemodule inside the compiled
code. The code is almost final (its very small), but I'm waiting until
I've finished writing the first draft of the gem (which is 90% complete)
before releasing it publicly.