lua-users home
lua-l archive

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


It's great, I think it might be better if it can provide a compatible luajit.ffi interface module.

Dibyendu Majumdar <mobile@majumdar.org.uk> 于2021年9月26日周日 下午7:53写道:
Hi

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.

Example:

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

function demo(u: Userdata)

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

end

I have a wiki page with these ideas:
https://github.com/dibyendumajumdar/ravi-compiler/wiki/Embedding-C

Any thoughts or feedback welcome.

Regards
Dibyendu


--

Ruki Wang 
waruqi@gmail.com 
https://github.com/waruqi
https://twitter.com/waruqi