Below is an example of dynamic loading. Question: How do we find plugins?
We need the filename, but it is going to be different on different installations. For example if I make the plugins "fdoc" "flx" "c" etc for the webserver to format code in various formats .. how do I find them? there has to be at least one "fixed place" to start looking. Command line option? ============================================== Note there is a serious bug: Dynlink doesn't work correctly in a statically linked executable. This is not a programming bug, its a design bug. Felix was designed so you could either dynamically link or statically link. To make the same program work in both cases, the "dlopen" syle stuff is just ignored static linking, and dlsym maps to the actual linked in symbol. The problem is, statically linked executables can still do dynamic loading. In fact in most systems this is the usual case, and this includes the Felix driver flx_run which is the statically linked executable that loads the DLL version of your program (OR can be statically linked to it!). Either way, flx_run itself is an application (exe) not a library. So if it links to your main program statically, you still should be able to dynamically load libraries. In particular, it would be nice to do this for the webserver. In fact it would be nice to statically link SOME extensions but still allow others to be dynamically linked. The linkage is a bit tricky! Python somehow does this, but only with hackery and only building the main executable. The problem is for "plugins" you want to use a single name, the same name in ALL the extensions, so you can dlsym that name. But for static linking the name has to be different in all extensions :) Anyhow, Python can do things fairly nicely because it uses a single module table in extensions. Felix is harder to manage because it tries to "get at" the raw C level. i will probably have to separate the notion of "optionally static or dynamic linked" from "static linked" and "dynamic linked" so there's a Dynlink module that still works for actual dynamic linkage. //// the dll: xlat1.dylib (on OSX) /////////////// println "xlat1 initialising"; var s = "init string"; fun xlat(x:string)=> "XLATED <" + x + "> XLATEDEND " + s; fun xlat2(x:string)=> "XLATED2 <" + x + "> XLATEDEND2"; export fun xlat of (string) as "xlat"; export cfun xlat2 of (string) as "cxlat"; /// mainline //// println "Dynamic loader test"; var linst1 = Dynlink::init_lib("xlat1.dylib"); println$ "Library initialised"; var lib1 = Dynlink::get_library linst1; var tf = Dynlink::get_thread_frame linst1; var addr1 = Dynlink::dlsym$ lib1, "xlat"; println$ "Got function address " + str addr1; var fn1 = C_hack::cast[address * string --> string] addr1; println$ fn1 (tf, "Hello World"); var addr2 = Dynlink::dlsym$ lib1, "cxlat"; println$ "Got function address " + str addr2; var fn2 = C_hack::cast[string --> string] addr2; println$ fn2 ("Hello World"); ////// output ///////////////// ~/felix>flx dlx Dynamic loader test xlat1 initialising Library initialised Got function address 882864 XLATED <Hello World> XLATEDEND init string Got function address 881840 XLATED2 <Hello World> XLATEDEND2 -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ This SF email is sponsosred by: Try Windows Azure free for 90 days Click Here http://p.sf.net/sfu/sfd2d-msazure _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language