lua-users home
lua-l archive

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


It was thus said that the Great steve donovan once stated:
> On Thu, Mar 20, 2014 at 9:36 AM, Florian Weimer <fw@deneb.enyo.de> wrote:
> > The ROOT project at CERN has implemented this:
> > <http://root.cern.ch/drupal/content/cling>
> 
> Ah yes, comes from the clang project - very promising!  It means that
> I don't ever have to bother with UnderC again, which is good news.
> 
> But, to return at least nominally to Lua, this REPL is implemented by
> clang and so should be able to handle loading the Lua headers.  If it
> also does FFI linking against the shared library, that will give
> people a nice testing ground for playing with the Lua C API, one
> function at a time.

  You can get close to this with the org.conman.cc module [1] for Lua.  This
will allow you to compile C code from within Lua and have the results
immediately available for use:

[spc]saltmine:~>lua
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> cc = require "org.conman.cc"
> test = cc.compile('test',[[
>> #include <stdio.h>
>> #include <lua.h>
>> #include <lauxlib.h>
>> 
>> int test(lua_State *L)
>> {
>>   printf("Hello from C!\n");
>>   return 0;
>> }
>> ]]
>> )
> test()
Hello from C!
> 

  It's based upon my bindings to TCC [2][3], and it also extends the module
system so you can load C modules directly into Lua from source (only works
for Lua 5.1 currently).

  -spc

[1]	https://github.com/spc476/lua-conmanorg/blob/master/lua/cc.lua

[2]	A very fast C compiler that can be linked into any application.

[3]	https://github.com/spc476/lua-conmanorg/blob/master/src/tcc.c