DLD Usage

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

DLD Usage

Jean-Marc Farinas
Hi,

There is a utility named gtk-server (http://www.gtk-server.org) wich
offers a stream-oriented interface to the GTK library. The stream
interface is easily implemented in GNU smalltalk, but there is also a
shared library version which provide a simple function
('char* gtk(char*)').

I've tried to implement this kind of interface with DLD and
CFunctionDescriptor classes.

When I'm calling the gtk function, it access the library but cannot
recover the returned char*.

Here is the script:



"
======================================================================
This is a template of gtk-server usage as a library
======================================================================
"

Object subclass: GtkServer [
    | type |
    <comment: 'I implement access to gtk server library'>
    <category: 'GUI'>
    <shape: #inherit>

    "Class Variables"
    gtkFuncP := nil.

    "Class Methods"
    GtkServer class >> new [
        <category: 'instance creation'>
        |r|
        r := super new.
        DLD addLibrary: 'libgtk-server.so'.
"
In this library there is a function '' char* gtk(char*) '' wich gives
access to whatever function as specified in the configuration file.
"
        DLD defineExternFunc: 'gtk'.
        gtkFuncP := CFunctionDescriptor for: 'gtk'
            returning: #string
            withArgs: #(#string).
        gtkFuncP printNl.
        ^r init
    ]

    init [
        type = 'lib'.
        ^self.
    ]

    type [
        ^ type
    ]

    type: aType [
        type := aType
    ]
   
    call: aString [
        | result |
">>>> This is where the returned value is always 'nil' and it "
         ^gtkFuncP callInto: result.
">>>> should be a string"
    ]
]

"Now try to make a new gtk-server instance (taken from perl example in
gtk server source tree)"
Eval [
    | win |
    WS := GtkServer new.
    WS call: 'gtk_init NULL NULL'.
    win := WS call: 'gtk_window_new 0'.
"win variable is not instanciated to window descriptor"
    win printNl.
    WS call: 'gtk_window_set_title ' , win , 'GST window'.
    WS call: 'gtk_window_set_default_size ', win, '400 200'.
    WS call: 'gtk_window_set_position ' ,win, '1'.
   
    WS call: 'gtk_widget_show_all ', win.

    WS call: 'gtk_server_callback wait'.
]

Do i miss something when the C function descriptor is build ?

Jean-Marc









_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: DLD Usage

Paolo Bonzini-2

> There is a utility named gtk-server (http://www.gtk-server.org) wich
> offers a stream-oriented interface to the GTK library. The stream
> interface is easily implemented in GNU smalltalk, but there is also a
> shared library version which provide a simple function
> ('char* gtk(char*)').

Interesting.

> Do i miss something when the C function descriptor is build ?

You don't need building a C function descriptor.  It is just an internal
detail.

Invoke "DLD addLibrary: 'libgtk-server.so'" just once, outside GtkServer
completely.  Then, implement #call: like this:

     call: aString [
         <cCall: 'gtk' returning: #string args: #(#string)>
     ]

The pragma <cCall:...> will be compiled to the invocation of #callInto:
for the CFunctionDescriptor.

Also, the first time you call it, it will automatically invoke
#defineExternFunc: and call the gtk function.

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: DLD Usage

Ildar Mulyukov
In reply to this post by Jean-Marc Farinas
On 01.02.2008 09:51:55, Jean-Marc Farinas wrote:
> There is a utility named gtk-server (http://www.gtk-server.org) wich  
> offers a stream-oriented interface to the GTK library. The stream  
> interface is easily implemented in GNU smalltalk, but there is also a  
> shared library version which provide a simple function ('char*  
> gtk(char*)').
>
> I've tried to implement this kind of interface with DLD and  
> CFunctionDescriptor classes.

        Hello, Jean-Marc,

Make it for Squeak - they will be grateful. One guy tries to make GTK+  
interface for Squeak - pitiful.

Regards,
--
Ildar  Mulyukov,  free SW designer/programmer
================================================
email: [hidden email]
home: http://tuganger.narod.ru/
ALT Linux Sisyphus
================================================


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk