-
Notifications
You must be signed in to change notification settings - Fork 5
Question: Could this be used as IDL? #9
Description
I've been looking for some IDL (Interface Description Language) solution to generate C/C++ interface from common definition. This project got my attention since it's simple, and it supports Lua (matches build system I'm using).
I started this IDL in Go language, but I'm not happy with not being easily scriptable.
This is my current half-done solution:
{
"VertexBufferHandle", "createVertexBuffer", "create_vertex_buffer",
[]Arg{
{"const Memory *", "_mem"},
{"const VertexDecl &", "_decl"},
{"uint16_t", "_flags"},
},
},
{
"void", "destroy", "destroy_vertex_buffer",
[]Arg{
{"VertexBufferHandle", "_handle"},
},
},Idea is that this IDL would then generate following functions:
C++:
VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint16_t _flags)
{
BX_CHECK(NULL != _mem, "_mem can't be NULL");
BX_CHECK(isValid(_decl), "Invalid VertexDecl.");
return s_ctx->createVertexBuffer(_mem, _decl, _flags);
}
void destroy(VertexBufferHandle _handle)
{
s_ctx->destroyVertexBuffer(_handle);
}
C99:
BGFX_C_API bgfx_vertex_buffer_handle_t bgfx_create_vertex_buffer(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags)
{
const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl;
union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle;
handle.cpp = bgfx::createVertexBuffer( (const bgfx::Memory*)_mem, decl, _flags);
return handle.c;
}
BGFX_C_API void bgfx_destroy_vertex_buffer(bgfx_vertex_buffer_handle_t _handle)
{
union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle };
bgfx::destroy(handle.cpp);
}
And C99 dynamic lib which would call function via bgfx_interface_vtbl_t, and C++ dynamic lib which would call C99 dynamic lib function in the same way as above example calls C++ from C99 function wrapper.
Assumption here is that there would be one function body implemented somewhere (like one from C++ snippet above), but the rest function bodies would be generated automatically from IDL.