How to pass a function in a usersub? 
Author Message
 How to pass a function in a usersub?

I need help (please ;-)!

I am in the process of writing uniperl, a perl interface for UNIFY
(5.0, not 2000 (yet ;-)) HLI C calls.  I have finished almost all
of the HLI routines, except for the ones that expect arguments
which are addresses of C functions.  I would like to be able to
pass perl routines in place of the C functions.  The address would
get saved and called at a later time, during another HLI routine
call.  My question is, how?

Example:

sub Select_Criterial { ... }

&sfncitm('Select_Criterial');
...

&unisel("sf$$", $my_table, $count);

In C, sfncitm is declared as:

sfncitm(sfunc)
int (*sfunc)();

And sfunc is called during the call to unisel().

Is this possible?  I've looked into callv and callback from usersub.c
a little bit, but am concerned about the stack pointer.

At first, I don't care about time spent to invoke this - I just want to do it.
Any help would be greatly appreciated.

Thanks in advance.
Rick
--

L
LMMM                           Law Manager, Inc.
LMMM         legal office automation specialists
------------------------------------------------
80 west georgianna drive  *  richboro, pa  18954

                                   Richard Wargo
                               Software Engineer
                             tel: (215) 895-1225
                             fax: (215) 895-1690



Sat, 19 Aug 1995 05:53:10 GMT  
 How to pass a function in a usersub?
: I need help (please ;-)!
:
: I am in the process of writing uniperl, a perl interface for UNIFY
: (5.0, not 2000 (yet ;-)) HLI C calls.  I have finished almost all
: of the HLI routines, except for the ones that expect arguments
: which are addresses of C functions.  I would like to be able to
: pass perl routines in place of the C functions.  The address would
: get saved and called at a later time, during another HLI routine
: call.  My question is, how?

Typically, you save the subroutine name in a table, and use some of
the information passed back in the callback to do the lookup in
the table and call the right routine.  Obviously, this depends on
an implementation of callbacks that lets you pass some information
through to the callback routine, and not just the name.  Otherwise
you'll have to know all the possible types of callback in advance
and have a separate routine for each.

: Example:
:
: sub Select_Criterial { ... }
:
: &sfncitm('Select_Criterial');
: ...
:
: &unisel("sf$$", $my_table, $count);
:
: In C, sfncitm is declared as:
:
: sfncitm(sfunc)
: int (*sfunc)();
:
: And sfunc is called during the call to unisel().
:
: Is this possible?  I've looked into callv and callback from usersub.c
: a little bit, but am concerned about the stack pointer.

Save it in a static location when you call into C or C++, and then you'll
have it when the callback needs it.

Larry



Mon, 21 Aug 1995 00:55:37 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. usersub functions in a different package.

2. how to pass a function name to a function, and have it call it

3. Passing arrays by reference to C functions and callback functions

4. Function to pass multiple strings to other function??

5. C function- passing arrays

6. Perl5: Passing References to local variables back from a function

7. passing functions as arguments to subroutines

8. passing functions as arguments

9. Passing parameters to a function in an EXE file thru registry

10. passing two arrays in a function..

11. Passing Associative Arrays to functions

12. function parameter passing, null arg distinction

 

 
Powered by phpBB® Forum Software