Re: Including Files
- Posted by Chris Bensler <bensler at nt.net> Dec 01, 2006
- 761 views
cklester wrote: > > Can this please be considered? > > I'd like to be able to include files using a variable. For example: > > sequence s > s = dir("plugins") > for t=1 to length(s) do > if not find(s,{".",".."}) then > include s[t] > end if > end for > > Thanks! :) > > -=ck > "Programming in a state of Euphoria." > <a > href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a> That is not a very easy thing to do. Doing so would require changing how Eu processes code. You can do what you want using a dynamic include mechanism however. I'm not sure if it will work in >=2.5 but I beleive it will. The idea is to include an empty, dummy/placeholder file in your application just after the branch. Write an import() routine that accepts an include filename. In the routine, copy the contents of the specified file into the dummy file.
-- append the contents of include_name to the contents of dummy_name -- you will need make sure the dummy file is deleted at application start to clear the previous dynamic contents global procedure import(sequence dummy_name, sequence include_name) integer fn1,size fn1 = open("include_name","rb") fn2 = open(dummy_name,"ab") if seek(fn1,-1) then end if size = where(fn1) if seek(fn1,0) then end if puts(fn2,get_bytes(fn1,size)) close(fn2) close(fn1) end procedure -- make sure the contents of the dummy file are cleared close(open("dummy.e","w")) sequence s s = dir("plugins") for t=1 to length(s) do if not find(s,{".",".."}) then import("dummy.e",s[t]) end if end for include dummy.e
That dynamic include method will only work for interpretted code however :< Chris Bensler ~ The difference between ordinary and extraordinary is that little extra ~ http://empire.iwireweb.com - Empire for Euphoria