hmm... It seems to me that this could be used to easily generate glue
functions on the fly. For example, consider a Lua function:
wrap (f, r, [p1, p2, ..])
which returned a glue function for C function f with parameter types p1,
p2, ... and return type r. For example, if I wanted to use OpenGL's
glTranslated:
glTranslated = wrap ("glTranslated", "void", "number", "number", "number");
This would generate and compile something like the following in tcc:
LUALIB_API int glue_glTranslated (lua_State *L)
{
glTranslated (lua_tonumber (L, 1), lua_tonumber (L, 2),
lua_tonumber (L, 3));
return 0;
}
Obviously I am leaving out a lot of details such as external libraries
but I think this general idea could prove very useful for exporting C
libraries to Lua /without ever writing C code/. It would not be hard to
optimize it to compile the tcc code upon the first call of the function
(kinda like LuaJIT).
By the way, it seems to me that this should be possible using just gcc
(though much slower of course). It should be possible to implement such
a system that falls back on gcc if tcc is not installed.