messages in TypeModuleSample

This commit is contained in:
Kolan Sh 2016-12-13 20:57:03 +03:00
parent c125be53dd
commit 4e41f28932
2 changed files with 33 additions and 3 deletions

View File

@ -11,19 +11,23 @@ class MyModule : TypeModule
this.name = name;
}
//private Type type;
void * plugin_init = null;
public override bool load () {
//if (plugin_init != null) return true;
string path = Module.build_path (Environment.get_variable ("PWD"), name);
module = Module.open (path, GLib.ModuleFlags.BIND_LAZY);
if (null == module) {
error ("Module not found");
}
void * plugin_init = null;
if (! module.symbol ("plugin_init", out plugin_init)) {
error ("No such symbol");
}
((PluginInitFunc) plugin_init) (this);
/*type = */((PluginInitFunc) plugin_init) (this);
return true;
}
@ -33,11 +37,17 @@ class MyModule : TypeModule
message ("Library unloaded");
module = null;
}
//public Object create_instance (/*IHost ihost*/) {
// var p = Object.new (type) as Object;
// //p.host = ihost;
// return p;
//}
}
// Never unref instance of GTypeModule
// http://www.lanedo.com/~mitch/module-system-talk-guadec-2006/Module-System-Talk-Guadec-2006.pdf
static TypeModule module = null;
static MyModule module = null;
int main ()
{
@ -46,9 +56,13 @@ int main ()
var o = GLib.Object.new (Type.from_name ("MyClass"));
var vasya = GLib.Object.new (Type.from_name ("MyNameIsVasya"));
// free last instance, plugin unload
o = null;
vasya = null;
module.unload ();
return 0;

View File

@ -1,6 +1,21 @@
public class MyNameIsVasya : Object {
construct {
stdout.puts ("(construct) My name is Vasya\n");
}
public MyNameIsVasya () {
stdout.puts ("My name is Vasya\n");
}
}
public class MyClass : Object {
//Type type;
construct {
message("MyClass init");
//var tmp = new MyNameIsVasya();
//type = typeof(MyNameIsVasya);
}
~MyClass() {
@ -10,5 +25,6 @@ public class MyClass : Object {
[ModuleInit]
Type plugin_init(GLib.TypeModule type_module) {
stdout.puts ("---plugin_init() called---\n");
return typeof(MyClass);
}