[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Embedding C in Ravi
- From: Dibyendu Majumdar <mobile@...>
- Date: Sun, 26 Sep 2021 12:53:29 +0100
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