lua-users home
lua-l archive

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


A small additional feature is the ability to allocate a C struct that
has a flexible array member.

Example usage:

https://github.com/dibyendumajumdar/ravi/blob/master/tests/comptests/inputs/57_embed_C.lua

On Sat, 16 Oct 2021 at 04:54, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
>
> An initial preview version is now available in Ravi. Simple tests like
> these work:
>
> https://github.com/dibyendumajumdar/ravi/blob/master/tests/comptests/inputs/54_embed_C.lua
> https://github.com/dibyendumajumdar/ravi/blob/master/tests/comptests/inputs/55_embed_C.lua
>
> ---------- Forwarded message ---------
> 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