lua-users home
lua-l archive

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


Over the years some projects have appeared that use Lua like syntax
but actually implement a C like language underneath. What if instead
we just allow C code to be embedded?

With the new compiler project for Ravi I have been experimenting with
allowing a subset of C code to be embedded in Ravi. This is made
possibly because the compiler generates C intermediate code anyway.

The idea is that there will be two new language keywords: C__decl and C__unsafe.

C__decl will only be allowed at top level and can be used to declare C types.

C__unsafe will allow embedding C code snippets.

C__unsafe takes variables as arguments - these will be made available
to the C code snippet. I am calling these bind variables as they bind
to the Ravi variables in scope.

The actual C code is provided as a string in both cases.


C__decl [[
typedef struct MyStruct {
    int a;
} MyStruct;

function demo(u: Userdata)

    C__unsafe(u) [[
        MyStruct *s = (MyStruct *) u.ptr;


I have a wiki page with these ideas:

Any thoughts or feedback welcome.