Re: call_back() etc
noah smith wrote:
>What I've played with so far:
>
>Run ProgA
> Code
> system_exec(ProgB)
> Code
>end ProgA
>
>What I really want to happen is ...
<snip>
>Run ProgA
> ProgA code
> Run ProgB
> Register ProgB functions/procedures with ProgA
> ProgA code using ProgB functions/procedures
> end ProgB
> Unregister ProgB functions/procedures from ProgA
> ProgA code
>end ProgA
<snip>
I see now. Well, I hate to say it, but to do this the way you're
wanting is pretty much impossible. Once code has been declared in
a context (such as for use with ProgA), you can't get rid of it.
Now you COULD, in theory, do this: write ProgA so that when it
needs to execute ProgB's functions, it runs a second instance of
Euphoria, interpreting ProgB, and gives (as command-line parameters)
the specific function to execute, plus any data needed to get the
right answer.
If you're willing to take the performance hit to run Euphoria for
EACH function call to ProgB, you can do something like the following:
-- BEGIN PROGB (WARNING: pseudo-code) --
sequence params, function_name
object return_object
params = get_command_line_params ()
function_name = params[1]
params = params[2..length(params)] -- remove the function name
return_object = call_func (routine_id (function_name), params)
write_to_file ("temp.txt", return_object)
-- END PROGB --
-----------------
-- BEGIN PROGA --
function CallProgBFunc (sequence FuncName, sequence ParamStrings)
sequence ProgBExecString
object ReturnObject
ProgBExecString = "ex progb.ex " & FuncName
for i = 1 to length (ParamStrings) do
ProgBExecString = ProgBExecString & " " & ParamStrings[i]
end for
system_exec (ProgBExecString) -- you may need system() instead
ReturnObject = get_data_from_file ("temp.txt") -- pseudo-code
delete_file ("temp.txt") -- more pseudo-code
return ReturnObject
end function
-- execute some ProgA code...
x = CallProgBFunc ("square", {sprintf (x)})
y = CallProgBFunc ("add", {sprintf (x), sprintf (y)})
-- execute some more ProgA code...
-- END PROGA --
Now, this method might run into difficulties (I'm not sure if you'll
be able to send sequences to the ProgB functions), but I think it's
pretty close to what you want. If you want to use several ProgB
functions at a time before returning to ProgA, let me know; I still
might be able to help you out.
But honestly, this seems like a lot of work to avoid keeping the
routines in memory, plus the performance hit when using ProgB's
routines is going to be significant. Is there some reason why you
don't want to include code as needed, or at the start? Are you
trying to keep the program size small or something? If there's some
other factor at work here, we might be able to help you get around
it some other way.
Rod
|
Not Categorized, Please Help
|
|