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 Rena once stated:
> Just had an interesting thought: could you write a compiler in Lua,
> that compiles C into Lua bytecode or source code?
> 
> I think you'd need a C module (compiled to native code) that provides
> Lua the ability to do some of the things C can do, such as call
> syscalls and allocate raw memory blocks (char*s), but once you have
> that framework in place, it could be possible to compile C programs
> into Lua code, that would then only rely on Lua and that "framework"
> module.

  I wrote Lua bindings to TCC [1][2] so now I can compile C code from within
Lua.  I then wrote another module [3] to provide a better interface over the
TCC module, as well as extend require() to allow the loading of Lua modules
from C source (it compiles them directly into memory).  It's not quite what
you are asking for, but ... 

  -spc (Sigh ... I really need to talk about these modules a bit more ... )

[1]	http://en.wikipedia.org/wiki/Tiny_C_Compiler
	It's a C compiler that's a library.

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

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