[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Sun, 15 Feb 2004 20:28:09 +0000 (UTC) 
Subject:Re: importing typedefs from C to Poplog 
From:ug57dsm 
Volume-ID: 

Aaron Sloman wrote:
> I don't know anything about typedef enums, but using grep found a
> use of 'enum' in the C code for the poplog widget set (Xpw):
> [snip]
> So you can perhaps look to see where that is used in the C code and
> pop11 code for Xpw
> [snip]
> It looks as if typedef enum enables you to define an ordered list of
> symbolic types. The compiled C code will probably have translated
> those names into some low level so I don't believe you will be able
> automatically to get them to be presented to pop11 as words or
> strings. You may find they come out as integers, and you'll then
> have to do your own translation, perhaps using a property, e.g.
> always writing something like pop11_of(BOOL),e.g.
 > [snip]

Found out how to do it, you have to use newc_dec:

uses newc_dec;

/* Declare everything that we are going to import from the C object */
external declare sock_lib in c;
     typedef enum {False, True} BOOL;
     typedef char *String;
...
endexternal;

but it still didn't give me true booleans, so I put a wrapper around all 
the imported functions that returns the correct pop11 datatype, eg:

define sock_connect(sock_index, port, address);
     so_sock_connect(sock_index, port, address) == True;
enddefine;

> If that is the case there is already an elaborate package described
> in REF SOCKETS. The code for it can be viewed using
>     SHOWLIB unix_sockets

I had a peek... It looked harder than just importing the existing c 
shared object. Now instead of doing all the socket stuff I have a simple 
object that allows me to connect to any stream socket in the internet 
with a very simple interface :). If you think this could be of use I can 
post the code (*.c, *.h, makefile and *.p) I have.

> [snip]
>>Also wondering if its possible to get pointers (char * to be exact) into
>>pop11 from C.
> 
> 
> Things of that sort are required for the pop11 X window interface,
> among other things. Relevant files include
>     REF EXTERNAL
>     REF EXTERNAL_DATA
>     REF DATA
> 

found how:

so_sock_get_data returns a "char *", and I have:

define sock_get_data(sock_index);
     lvars ptr = so_sock_get_data(sock_index);

     if is_null_external_ptr(ptr) then
         nil;	;;; value of nil is [], but makes checking easy...
		;;; could also return false...
     else
         exacc_ntstring(ptr);
     endif;
enddefine;


> But I've never used them myself.
> 

Thanks, I got everything I needed (for the time being...)

david.


-- 
=================================================
  The future of HTML mail is clearly > /dev/null.
=================================================