Skip to content

Instantly share code, notes, and snippets.

@madprog
Created July 20, 2015 16:45
Show Gist options
  • Save madprog/f2444f538d1f1fd3c108 to your computer and use it in GitHub Desktop.
Save madprog/f2444f538d1f1fd3c108 to your computer and use it in GitHub Desktop.
using GI;
public void main(string[] args)
{
try {
string name = "mymodule";
Repository repository = Repository.get_default();
unowned Typelib module = repository.require_private(
Path.get_dirname(args[0]),
name, null, RepositoryLoadFlags.IREPOSITORY_LOAD_FLAG_LAZY);
BaseInfo _module_entry_point = repository.find_by_name(name, "module_entry_point");
if (_module_entry_point == null)
{
stderr.printf("No 'module_entry_point' function found in module '%s'\n", name);
return;
}
if (_module_entry_point.get_type() != InfoType.FUNCTION)
{
stderr.printf("Member 'module_entry_point' is a %s instead of a function\n", InfoType.to_string(_module_entry_point.get_type()));
return;
}
string symbol = FunctionInfo.get_symbol((FunctionInfo)_module_entry_point);
void *func = null;
if (!module.symbol(symbol, &func))
{
stderr.printf("Could not extract symbol '%s' from module %s\n", symbol, name);
return;
}
Argument input = (Argument)null;
Argument output = (Argument)null;
Argument ret = Argument();
stdout.printf("TRACE 1\n");
CallableInfo.invoke((CallableInfo)_module_entry_point, func, input, 0, output, 0, ret, false, true);
stdout.printf("TRACE 2\n");
}
catch (Error err)
{
stderr.printf("Caught error: %s\n", err.message);
}
}
namespace MyModule
{
public void module_entry_point()
{
stdout.printf("Called MyModule.module_entry_point()\n");
}
}
top = '.'
out = 'build'
def options(opt):
opt.load('compiler_c')
opt.load('vala')
def configure(conf):
conf.load('compiler_c')
conf.load('vala')
conf.find_program('g-ir-compiler', var='G_IR_COMPILER')
conf.check_cfg(package='gobject-introspection-1.0', uselib_store='GOBJECT_INTROSPECTION', args='--cflags --libs')
def build(bld):
_build_module(bld,
packages = '',
target = 'mymodule',
uselib = 'GLIB',
source = 'mymodule.vala',
gir = 'mymodule-1.0',
pkg_name = 'mymodule'
)
bld.program(
packages = 'gobject-introspection-1.0',
target = 'loader',
uselib = 'GOBJECT_INTROSPECTION',
source = 'loader.vala'
)
def _build_module(bld, **kw):
bld.shlib(**kw)
gir = kw.get('gir', None)
if gir:
bld(
rule = '${G_IR_COMPILER} -o ${TGT} ${SRC}',
source = '%s.gir' % gir,
target = '%s.typelib' % gir,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment