Re: Help with plugin concept

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Fri, 13 Feb 2004 18:58:50 -0500, Robert Craig
<rds at RapidEuphoria.com> wrote:

>Igor Kachan wrote:
> > Please, couldn't you explain more detailed what do you
> > mean when you say it does not work and it won't work.
> > What a reason ?
>
>The example code that you posted was...
>
>     P_S = open ("plugins.ew", "wb")
>     puts(P_S, PluginS)
>     close(P_S)
>
>     include plugins.ew
>
>The above code depends on the open() and puts() taking place
>before the include is processed. With the current
>interpreter that's what happens. With the current
>binder and translator that's not what happens.
>Rather, the binder and translator process the include file
>(and all other source code) first. Execution of statements
>happens later at run-time, when it's too late
>for the open/puts to have the desired effect.
>
>In the next release, with the clearer separation between
>front-end and back-end, the interpreter will also
>process the include (and all other source)
>before it executes any code.
OK. I have no argument with that.
>It will be simpler this way. I don't think a lot of
>people are actually using the above "dynamic" include
>technique, although it has been discussed on this list
>from time to time.
True.

I cannot however resist suggesting (in pseudo code rather than true or
tested Euphoria, you understand):

in say misc.e:
procedure dynamic_include(sequence filename, sequence contents)
integer changed, fn,
object d
	if interpreting or translating then	-- see PS
		changed=0
		d=dir(filename)	--##I forget the syntax/results##
		if d!=-1 and d[SIZE]=length(contents) then
			fn=open(filename,"r")
			for i=1 to length(contents) do
				if getc(fn)!=contents[i] then
					changed=1
					exit
				end if
			end for
			close(fn)
			if changed=0 then return end if
		end if
		open(filename,"w")
		puts(fn,contents)
		close(fn)
		puts(1,"dynamic include changed; restarting...")
		system(command_line())
		abort(0)
	end if
end procedure

then:
dynamic_include(filename,contents)
include filename

Does that make sense?
If so, I don't think it is much work and it will (might) put this
issue to bed once and for all.

Regards,
Pete
PS I am undecided whether it would be better for bind/translate to
simply not generate any code whatsoever for the dynamic_include()
call, or issue a fatal error (/warning) if it detects the program
ought to be re-bound/re-translated.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu