1. Including Files
- Posted by cklester <cklester at yahoo.com> Dec 01, 2006
- 778 views
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." http://www.cklester.com/euphoria/
2. Re: Including Files
- Posted by Chris Bensler <bensler at nt.net> Dec 01, 2006
- 762 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
3. Re: Including Files
- Posted by cklester <cklester at yahoo.com> Dec 01, 2006
- 762 views
Chris Bensler wrote: > > cklester wrote: > > 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 > > That is not a very easy thing to do. Doing so would require changing how Eu > processes code. I don't see how include smith.e is that much more complicated than include "smith.e" or sequence smith smith = "smith.e" include smith > 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. Yeah, that might work. I'll think it over and get back to ya. :) -=ck "Programming in a state of Euphoria." http://www.cklester.com/euphoria/
4. Re: Including Files
- Posted by Ray Smith <ray at RaymondSmith.com> Dec 01, 2006
- 740 views
cklester wrote: > > Chris Bensler wrote: > > That is not a very easy thing to do. Doing so would require changing how Eu > > processes code. > > I don't see how > > include smith.e > > is that much more complicated than > > include "smith.e" > > or > > sequence smith > smith = "smith.e" > > include smith > Hi CK, I assume the complexity starts when binding and translating to C. Regards, Ray Smith http://RaymondSmith.com
5. Re: Including Files
- Posted by Chris Bensler <bensler at nt.net> Dec 01, 2006
- 802 views
cklester wrote: > > > That is not a very easy thing to do. Doing so would require changing how Eu > > processes code. > > I don't see how > > include smith.e > > is that much more complicated than > > include "smith.e" > > or > > sequence smith > smith = "smith.e" > > include smith > For one thing, it's abmiguous. Is smith a variable or a filename without an extension? If it were up to me, I would resolve this by forcing all literal filenames to be quoted. But that breaks compatability. The other major issue is that Eu assumes all the files are technically included before any code is executed. We can 'hack' around it using the interpetter because of how it parses source code, but the same is not posible for a bound application. A bound application has already parsed and included it's files before it even begins to execute anything. So the dummy file would always be empty, regardless of your attempts to rewrite it. A bound application would have to be capable of parsing and translating to op code during runtime, which would impose load time latencies during the run of your program whenever a new file is encountered. Any file that contains a dynamic include statement would also have to be processed everytime it's included, regardless if it was already parsed, since you couldn't guarantee that the dynamically included files within that include will be the same. If eu supported string execution it would be possible, but there is still the include statement abiguity and the overhead imposed by runtime parsing. Chris Bensler ~ The difference between ordinary and extraordinary is that little extra ~ http://empire.iwireweb.com - Empire for Euphoria
6. Re: Including Files
- Posted by Chris Bensler <bensler at nt.net> Dec 01, 2006
- 765 views
Chris Bensler wrote: > > 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. > > }}} <eucode> > -- 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 > </eucode> {{{ > > That dynamic include method will only work for interpretted code however :< > > Chris Bensler > ~ The difference between ordinary and extraordinary is that little extra ~ > <a href="http://empire.iwireweb.com">http://empire.iwireweb.com</a> - Empire > for Euphoria I made a mistake. you can't append include files together unless you can guarantee there will be no local name clashes, or else consolidate the files. What you will need to do for multiple files is either: A) have a dummy include statement for the maximum possible dynamic includes that you will allow. B) append a concurrent dummy include statement to each dummy include file. So, dummy01.e includes dummy02.e at the end of the file which includes dummy03.e at the end of it's file, etc.. Using A, you will have to have a limit on how many files will be dynamically included. Using B, you will be restricted by Eu's include nesting limit. Chris Bensler ~ The difference between ordinary and extraordinary is that little extra ~ http://empire.iwireweb.com - Empire for Euphoria
7. Re: Including Files
- Posted by cklester <cklester at yahoo.com> Dec 01, 2006
- 716 views
Chris Bensler wrote: > Chris Bensler wrote: > > cklester wrote: > > > I'd like to be able to include files using a variable. For example: > > 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. > I made a mistake. you can't append include files together unless you can > guarantee > there will be no local name clashes, or else consolidate the files. What about just simply creating an include file that includes files? files = dir("plugins") fn = open("built_at_runtime.e","w") for t=1 to length(files) do puts(fn,"include " & files[D_NAME]) end for include built_at_runtime.e -=ck "Programming in a state of Euphoria." http://www.cklester.com/euphoria/
8. Re: Including Files
- Posted by Chris Bensler <bensler at nt.net> Dec 01, 2006
- 731 views
cklester wrote: > > Chris Bensler wrote: > > Chris Bensler wrote: > > > cklester wrote: > > > > I'd like to be able to include files using a variable. For example: > > > 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. > > I made a mistake. you can't append include files together unless you can > > guarantee > > there will be no local name clashes, or else consolidate the files. > > What about just simply creating an include file that includes files? > > files = dir("plugins") > fn = open("built_at_runtime.e","w") > for t=1 to length(files) do > puts(fn,"include " & files[D_NAME]) > end for > include built_at_runtime.e > > -=ck > "Programming in a state of Euphoria." > <a > href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a> Hehe, yea that ought to work too :P Chris Bensler ~ The difference between ordinary and extraordinary is that little extra ~ http://empire.iwireweb.com - Empire for Euphoria
9. Re: Including Files
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Dec 01, 2006
- 791 views
- Last edited Dec 02, 2006
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! :) I think the only 'reasonable' way to do this is to use something like ooeu's eval() (which it can do). I haven't migrated that into the c backend yet, so you'd be stuck with the euphoria backend. I have some ideas on how to do it, however, though it's going to be a lot of work. The difficulty is in adding to the symbol table at runtime. The c backend converts all the symtab indices into pointers. In order to add stuff at the end of the symbol table, you need to be able to allocate new space. My solution will use linked symbol table blocks, so that each time you call eval, a new one gets allocated. As Ray mentioned, translation is where this gets difficult. I've got some ooeu features translating, but to add an eval, you have to embed the interpreter into the runtime library, rather than just the support routines. And then you have to be able to allow stuff to go back and forth between the translated and interpreted code. Similar issues arise from the var_id family of features. A better way to do this might be to translate your plugins to c, so that you could dynamically load them. Since the translator is all free, there's less reason not to do this sort of thing. You might take a look at the ooeu debugger, or even the win32lib dll wrapper (http://www.rapideuphoria.com/windll.zip) that allows a dll to use the win32lib in the main program. They should give some ideas about how to integrate eu code in this manner. Matt
10. Re: Including Files
- Posted by cklester <cklester at yahoo.com> Dec 02, 2006
- 723 views
Matt Lewis wrote: > 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! :) > > I think the only 'reasonable' way to do this is to use something like > ooeu's eval() (which it can do). I haven't migrated that into the c > backend yet, so you'd be stuck with the euphoria backend. I have some > ideas on how to do it, however, though it's going to be a lot of work. If Euphoria currently knows what to do with this: include myinc.e which is basically include the file 'myinc.e' why can't it simply do something like this: (pseudo-code) sequence s s = "myinc.e" include s which would be the exact same thing as include the file 'myinc.e' as defined in the variable s Instead of 1. parse filename from line of code 2. include filename contents we would have 1. is include parameter a variable? Yes: parse filename from variable No: parse filename from line of code 2. include filename contents It's the EXACT SAME THING, except for that little translation part. But that happens before the include is invoked! Ultimately, the interpreter should be using the exact same unaltered include code it uses now, it's just that there might be a step or two extra before that in determing from whence the filename should be gotten. Do you see what I'm saying? The code used to include files now should not have to change. It can just obtain the filename to include in a new way. I hope that makes sense. It sure does in my head. 8) Is this a single-pass/double-pass issue? -=ck "Programming in a state of Euphoria." http://www.cklester.com/euphoria/
11. Re: Including Files
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Dec 02, 2006
- 729 views
cklester wrote: > > If Euphoria currently knows what to do with this: > > include myinc.e > > which is basically > > include the file 'myinc.e' > > why can't it simply do something like this: > > (pseudo-code) > > sequence s > s = "myinc.e" > include s Well, for one thing, when things are being parsed, s hasn't been assigned any value. > which would be the exact same thing as > > include the file 'myinc.e' as defined in the variable s > > Instead of > > 1. parse filename from line of code > 2. include filename contents > > we would have > > 1. is include parameter a variable? > Yes: parse filename from variable > No: parse filename from line of code > 2. include filename contents > > It's the EXACT SAME THING, except for that little translation part. > But that happens before the include is invoked! Ultimately, the > interpreter should be using the exact same unaltered include code it uses > now, it's just that there might be a step or two extra before that in > determing from whence the filename should be gotten. > > Do you see what I'm saying? The code used to include files now should not > have to change. It can just obtain the filename to include in a new way. > > I hope that makes sense. It sure does in my head. 8) > > Is this a single-pass/double-pass issue? The issue is that you're asking to be able to execute code during parsing, which is not how euphoria works (2.5 and later, anyway). I agree, however, that your simple example is exactly the same. So I'd ask you why you would want to do it that way? OK, I know the answer is that you'd want to do some other calculations to either create the sequence dynamically, or include it conditionally. You might do better with a preprocessor for the conditional include situation. You mentioned plugins. I really think the dll idea is a better way to go, because you could really load them dynamically (and unload them, if you really wanted to). Otherwise, some sort of preprocessor is probably better, so that you could keep some sort of ini file that identified the plugins you wanted, and before the code was actually executed, you could create the includes that you really wanted. That's basically what some others have done in their dynamic inclusion schemes for 2.5. Matt
12. Re: Including Files
- Posted by cklester <cklester at yahoo.com> Dec 02, 2006
- 709 views
Matt Lewis wrote: > The issue is that you're asking to be able to execute code during parsing, > which is not how euphoria works (2.5 and later, anyway). I agree, however, > that your simple example is exactly the same. So I'd ask you why you would > want to do it that way? Because I want users who don't know the internals to use an API to write plug-ins for my app. These plug-ins will be written in Euphoria and most likely will not be compiled into a dll, ever. At least, not by me! :) > You might do better with a preprocessor for the conditional include situation. Maybe, but I'm leery of leaving a pure Euphoria environment. That is, I tend to like to avoid kludges, to stay within the boundaries of the standards, and a preprocessor seems kludgey. -=ck "Programming in a state of Euphoria." http://www.cklester.com/euphoria/
13. Re: Including Files
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Dec 02, 2006
- 713 views
cklester wrote: > > Matt Lewis wrote: > > > The issue is that you're asking to be able to execute code during parsing, > > which is not how euphoria works (2.5 and later, anyway). I agree, however, > > that your simple example is exactly the same. So I'd ask you why you would > > want to do it that way? > > Because I want users who don't know the internals to use an API to write > plug-ins for my app. These plug-ins will be written in Euphoria and most > likely will not be compiled into a dll, ever. At least, not by me! :) > > > You might do better with a preprocessor for the conditional include > > situation. > > Maybe, but I'm leery of leaving a pure Euphoria environment. That is, I tend > to like to avoid kludges, to stay within the boundaries of the standards, > and a preprocessor seems kludgey. So how were you proposing that your users include their plugins into your app? Are they going to manually modify your code to add their file? You could have a setup app that configured the plugins to act as the preprocessor. A user could run it, and it would modify a section of your code where you include the plugins. Then the user runs the app. The setup could even be from within your app (assuming that makes sense for the UI of whatever you're doing) and the user has to restart for the plugin to work (lot's of things do this--see Firefox). If this doesn't sound good, maybe some more detail on what you're doing would help. Matt
14. Re: Including Files
- Posted by Chris Bensler <bensler at nt.net> Dec 02, 2006
- 729 views
Matt Lewis wrote: > > cklester wrote: > > > > Matt Lewis wrote: > > > > > The issue is that you're asking to be able to execute code during parsing, > > > which is not how euphoria works (2.5 and later, anyway). I agree, > > > however, > > > that your simple example is exactly the same. So I'd ask you why you > > > would > > > want to do it that way? > > > > Because I want users who don't know the internals to use an API to write > > plug-ins for my app. These plug-ins will be written in Euphoria and most > > likely will not be compiled into a dll, ever. At least, not by me! :) > > > > > You might do better with a preprocessor for the conditional include > > > situation. > > > > Maybe, but I'm leery of leaving a pure Euphoria environment. That is, I tend > > to like to avoid kludges, to stay within the boundaries of the standards, > > and a preprocessor seems kludgey. > > So how were you proposing that your users include their plugins into your > app? Are they going to manually modify your code to add their file? You > could have a setup app that configured the plugins to act as the preprocessor. > A user could run it, and it would modify a section of your code where you > include the plugins. Then the user runs the app. The setup could even be > from within your app (assuming that makes sense for the UI of whatever you're > doing) and the user has to restart for the plugin to work (lot's of things > do this--see Firefox). > > If this doesn't sound good, maybe some more detail on what you're doing would > help. > > Matt Hasn't anyone made Eu-in-Eu into an embeddable script engine yet? Seems to me, this is one of the few ways in which it can really be useful. Chris Bensler ~ The difference between ordinary and extraordinary is that little extra ~ http://empire.iwireweb.com - Empire for Euphoria
15. Re: Including Files
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Dec 02, 2006
- 721 views
Chris Bensler wrote: > > > Hasn't anyone made Eu-in-Eu into an embeddable script engine yet? > Seems to me, this is one of the few ways in which it can really be useful. > Yes, ooeu can do this, but currently only with the eu-based backend. As I mentioned earlier in this thread, I'm working on getting that implemented in the C backend, but it's going to take a while (I'm currently focusing on wxEuphoria development). Matt
16. Re: Including Files
- Posted by cklester <cklester at yahoo.com> Dec 02, 2006
- 707 views
Matt Lewis wrote: > > So how were you proposing that your users include their plugins into your > app? Are they going to manually modify your code to add their file? What I proposed is that the user simply puts their plugin into the plugins directory and the program will pick it up. Then, when the program is run, it simply includes all the files in the plugins directory. I'll probably have to go with the solution proposed earlier, where I create an include file that includes all the files in the plugins folder, then include that include file in the main program. > could have a setup app that configured the plugins to act as the preprocessor. > A user could run it, and it would modify a section of your code where you > include the plugins. The way it's proposed above makes it a one-step process. Drop in the file, run the program. That'll work for now... I hope. Haven't tested it, yet, but will this weekend. :) -=ck "Programming in a state of Euphoria." http://www.cklester.com/euphoria/
17. Re: Including Files
- Posted by Ryan W. Johnson <ryanj at fluidae.com> Dec 02, 2006
- 722 views
- Last edited Dec 03, 2006
cklester wrote: > > Matt Lewis wrote: > > > > So how were you proposing that your users include their plugins into your > > app? Are they going to manually modify your code to add their file? > > What I proposed is that the user simply puts their plugin into the plugins > directory and the program will pick it up. Then, when the program is run, it > simply includes all the files in the plugins directory. > > I'll probably have to go with the solution proposed earlier, where I create > an include file that includes all the files in the plugins folder, then > include that include file in the main program. > > > could have a setup app that configured the plugins to act as the > > preprocessor. > > A user could run it, and it would modify a section of your code where you > > include the plugins. > > The way it's proposed above makes it a one-step process. Drop in the file, > run the program. That'll work for now... I hope. Haven't tested it, yet, but > will this weekend. :) > > -=ck > "Programming in a state of Euphoria." > <a > href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a> I'm actually dealing with the exact same issue in my Fluid Application Environment project. It has optional modules which provide services for applications, and they are included in the kernel. As it is now, I have to manually add include statements and some other things to "modules.e" for new modules to work. I think what' i'm going to do is have a file called "modules.cfg" which will be included in "modules.e". When FluidAE is started, a special startup program will scan the /modules folder and add the appropriate entries into "modules.cfg" before executing "fluidae.exw". It will also allow modules to be included, but in a disabled state. Maybe we could work together on this. ~Ryan W. Johnson Fluid Application Environment http://www.fluidae.com/ [cool quote here, if i ever think of one...]