Skip to content

Commit

Permalink
move user define functions to template file
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Mar 2, 2019
1 parent 03b715e commit d89edfb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 36 deletions.
29 changes: 2 additions & 27 deletions bgfx.idl
Original file line number Diff line number Diff line change
Expand Up @@ -612,36 +612,11 @@ func.getRendererName
"const char*"
.type "RendererType::Enum"

local init_ctor = [[
BX_PLACEMENT_NEW(_init, bgfx::Init);
]]
func.initCtor { cfunc = init_ctor }
func.initCtor { cfunc }
"void"
.init "Init*"

local init = [[
bgfx_init_t init =*_init;
if (init.callback != NULL)
{
static bgfx::CallbackC99 s_callback;
s_callback.m_interface = init.callback;
init.callback = reinterpret_cast<bgfx_callback_interface_t*>(&s_callback);
}
if (init.allocator != NULL)
{
static bgfx::AllocatorC99 s_allocator;
s_allocator.m_interface = init.allocator;
init.allocator = reinterpret_cast<bgfx_allocator_interface_t*>(&s_allocator);
}
union { const bgfx_init_t* c; const bgfx::Init* cpp; } in;
in.c = &init;
return bgfx::init(*in.cpp);
]]
func.init { cfunc = init }
func.init { cfunc }
"bool"
.init "const Init &"

Expand Down
11 changes: 2 additions & 9 deletions codegen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ local function codetemp(func)
CPPFUNC = cppfunc,
CALLARGS = table.concat(callargs, ", "),
POSTRET = lines(func.ret_postfix),
CODE = func.cfunc,
}
end

Expand All @@ -331,16 +330,10 @@ BGFX_C_API $RET bgfx_$CFUNCNAME($CARGS)
}
]]

local c99usertemp = [[
BGFX_C_API $RET bgfx_$CFUNCNAME($CARGS)
{
$CODE
}
]]

function codegen.gen_c99(func)
if func.cfunc then
return apply_template(func, c99usertemp)
-- There is an user define c function, don't generate it.
return apply_template(func, "/* BGFX_C_API $RET bgfx_$CFUNCNAME($CARGS) */\n")
else
return remove_emptylines(apply_template(func, c99temp))
end
Expand Down
1 change: 1 addition & 0 deletions idl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ idl.vararg = "vararg"
idl.out = "out"
idl.const = "const"
idl.ctor = "ctor"
idl.cfunc = "cfunc"
idl.underscore = "underscore"
idl.NULL = "NULL"
idl.UINT16_MAX = "UINT16_MAX"
Expand Down
32 changes: 32 additions & 0 deletions temp.bgfx.idl.inl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,38 @@

$c99

/* user define functions */
BGFX_C_API void bgfx_init_ctor(bgfx_init_t* _init)
{
BX_PLACEMENT_NEW(_init, bgfx::Init);

}

BGFX_C_API bool bgfx_init(const bgfx_init_t * _init)
{
bgfx_init_t init =*_init;

if (init.callback != NULL)
{
static bgfx::CallbackC99 s_callback;
s_callback.m_interface = init.callback;
init.callback = reinterpret_cast<bgfx_callback_interface_t*>(&s_callback);
}

if (init.allocator != NULL)
{
static bgfx::AllocatorC99 s_allocator;
s_allocator.m_interface = init.allocator;
init.allocator = reinterpret_cast<bgfx_allocator_interface_t*>(&s_allocator);
}

union { const bgfx_init_t* c; const bgfx::Init* cpp; } in;
in.c = &init;

return bgfx::init(*in.cpp);

}

/**/
BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version)
{
Expand Down

0 comments on commit d89edfb

Please sign in to comment.