diff --git a/vala/TypeModuleSample/loader.vala b/vala/TypeModuleSample/loader.vala index aa89a5d..eb839b4 100644 --- a/vala/TypeModuleSample/loader.vala +++ b/vala/TypeModuleSample/loader.vala @@ -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; diff --git a/vala/TypeModuleSample/plugin.vala b/vala/TypeModuleSample/plugin.vala index 8f6e9a5..47af6f0 100644 --- a/vala/TypeModuleSample/plugin.vala +++ b/vala/TypeModuleSample/plugin.vala @@ -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); }