On Tue, Feb 09, 2010 at 15:36:56 +0100, jideel wrote: > I'm wondering what would be the "right" way to generates code/classes at > runtime, and reload it into the running program.
Well, is Vala the right tool than? It's a completely static language which needs to be compiled with C compiler and that linked and the C compiler and linker are a pretty big beast. Something more dynamic would handle the job easily. Either fully dynamic like python (or perl or ruby or lua or javascript (using libseed)), that have no compilation at all, or partially dynamic like CLR (Mono/.NET) or Java, which both carry their bytecode compiler in the runtime. You can still use vala for the static part and export necessary API to the dynamic part. > I thought to use the modules/plugin approach > (http://live.gnome.org/Vala/TypeModules) the following way : > - generate code than can be reloaded (plugin code, [ModuleInit]) using some > kind of StringBuilder > - flush it to a file I would not compose to StringBuilder (which is just string and will reallocate all the time as you extend it), but write to a file directly. It would be more efficient and you really get similar functionality. > - compile this file either by forking a valac compiler or perhaps using > directly libvala (possible ?) Both are possible. Forking is probably easier, since while most of vala compiler does live in libvala, the driver is not too trivial. Might depend on the conditions. I found the code reasonably easy to follow, so just take a look. > - reload the resulting plugin binary into the app It should work. You need to unload the old version, so you need to shut it down and than reload. Mostly applies to CLR and Java too; fully dynamic languages should be able to upgrade. > There's probably a better way to accomplish this kind of task. > > Any idea / suggestion ? It really depends on *why* you want to do it. -- Jan 'Bulb' Hudec <[email protected]> _______________________________________________ Vala-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/vala-list
