[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: perlTK
From: |
Joao Cardoso |
Subject: |
Re: perlTK |
Date: |
Fri, 18 Feb 2000 01:24:31 +0000 |
>On 4-Feb-2000, Joao Cardoso <address@hidden> wrote:
>
>| "John W. Eaton" wrote:
>|
>| > On 31-Jan-2000, Joao Cardoso <address@hidden> wrote:
>| >
>| > | Couldn't Octave have a function to do it? Something like
>| > |
>| > | on_idle("user function","user data")
>| >
>| > Sure, I've appended a solution.
>|
>| Thanks!
>|
>| But is seems that I have misunderstood its usage:
>|
>| octave:2> function po(data); printf("%s\n",data);fflush(stdout);endfunction
>| octave:3> po("Hello")
>| Hello
>| octave:4> input_event_hook ("po","meee")
>| error: segmentation violation -- stopping myself...
>|
>| I have tryed it with the last cvs. Hints?
>
>It worked when I first wrote it, but then I broke the event hook
>mechanism in liboctave when I was making changes to allow Octave to be
>compiled by compilers other than g++.
>
>Please try the following patch.
Thanks, it is now working OK.
However, I foresee a problem, if people/packages start using it, as
registering a new input function will overwrite the previous one.
I wrote two functions to avoid it and try to define a 'protocol'.
function register_input_event(func, data) register a new function
function deregister_input_event(func, data) de-register a function
I enclose them.
FYI, I am able to compile and run the latest Octave cvs (well, a few
days ago) with both egcs-1.1.2 and gcc-2.95.2 on sco-3.2v5.0.4.
Thanks,
Joao
function register_input_event(func, data)
global __user_func__ __user_data__
# humm, check that arguments are strings, and that 'func' exists as a
function
if (! exist("__user_func__"))
__user_func__ = __user_data__ = list;
endif
__user_func__ = append(__user_func__, func);
__user_data__ = append(__user_data__, data);
if (length(__user_func__) != 0)
input_event_hook("input_event","");
endif
endfunction
function deregister_input_event(func, data)
global __user_func__ __user_data__
# humm, check that arguments are strings!
if (! exist("__user_func__"))
__user_func__ = __user_data__ = list;
error("Nothing to de-register\n");
endif
for i=1:length(__user_func__)
if (strcmp(nth(__user_func__,i), func) & strcmp(nth(__user_data__,i),
data))
__user_func__ = splice(__user_func__, i, 1);
__user_data__ = splice(__user_data__, i, 1);
return
endif
endfor
error("No match to de-register\n");
endfunction
# this function should be hided from the user
function input_event
global __user_func__ __user_data__
if (length(__user_func__) == 0)
input_event_hook
else
for i=1:length(__user_func__)
feval(nth(__user_func__, i), nth(__user_data__, i));
endfor
endif
endfunction
1;
function register_input_event(func, data)
global __user_func__ __user_data__
if (! exist("__user_func__"))
__user_func__ = __user_data__ = list;
endif
__user_func__ = append(__user_func__, func);
__user_data__ = append(__user_data__, data);
if (length(__user_func__) != 0)
input_event_hook("input_event","");
endif
endfunction
function deregister_input_event(func, data)
global __user_func__ __user_data__
if (! exist("__user_func__"))
__user_func__ = __user_data__ = list;
error("Nothing to de-register\n");
endif
for i=1:length(__user_func__)
if (strcmp(nth(__user_func__,i), func) &
strcmp(nth(__user_data__,i), data))
__user_func__ = splice(__user_func__, i, 1);
__user_data__ = splice(__user_data__, i, 1);
return
endif
endfor
error("No match to de-register\n");
endfunction
function input_event
global __user_func__ __user_data__
if (length(__user_func__) == 0)
input_event_hook
else
for i=1:length(__user_func__)
feval(nth(__user_func__, i), nth(__user_data__, i));
endfor
endif
endfunction
- Re: perlTK, Joao Cardoso, 2000/02/04
- Re: perlTK,
Joao Cardoso <=