Allow foreign_method_fn() in the configuration object.

Wren expects this function to return a pointer to a function
that takes a WrenVM*. This is bad news because that type is
wrapped inside wren::VM and client code doesn't know about it.
It would be better for client code to return a pointer to a
function that takes a VM* instead. In order to do the VM* to
WrenVM* translation I make a "handmade" closure, that is I
generate a function at runtime that contains the VM* hardcoded
into it. The same function also contains the hardcoded
address of the callback function client code wanted to use.
By doing this I can pass a different function pointer to Wren
for each foreign method, and that function knows how to forward
the call to the real client callback.
Currently only implemented for amd64 gnu/linux.
This commit is contained in:
King_DuckZ 2020-04-26 17:19:02 +02:00
parent d0be115181
commit 16c4b8cbe5
9 changed files with 187 additions and 4 deletions

View file

@ -11,6 +11,7 @@ executable(meson.project_name(),
'src/wren/vm.cpp',
'src/wren/configuration.cpp',
'src/wren/def_configuration.cpp',
'src/wren/dynafunc_maker.cpp',
dependencies: [wren_dep],
install: true,
)