Created
July 20, 2015 16:45
-
-
Save madprog/f2444f538d1f1fd3c108 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MyModule | |
{ | |
public void module_entry_point() | |
{ | |
stdout.printf("Called MyModule.module_entry_point()\n"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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