From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.user Subject: ffi-help: gtk demo updated Date: Tue, 13 Mar 2018 17:13:19 -0700 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1520986306 30921 195.159.176.226 (14 Mar 2018 00:11:46 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 14 Mar 2018 00:11:46 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Mar 14 01:11:42 2018 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1evu18-0007u7-AN for guile-user@m.gmane.org; Wed, 14 Mar 2018 01:11:42 +0100 Original-Received: from localhost ([::1]:43778 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evu39-0001oU-KJ for guile-user@m.gmane.org; Tue, 13 Mar 2018 20:13:47 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evu2o-0001np-Do for guile-user@gnu.org; Tue, 13 Mar 2018 20:13:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evu2l-0003kK-5e for guile-user@gnu.org; Tue, 13 Mar 2018 20:13:26 -0400 Original-Received: from mail-pg0-x22e.google.com ([2607:f8b0:400e:c05::22e]:38118) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1evu2k-0003jz-SN for guile-user@gnu.org; Tue, 13 Mar 2018 20:13:23 -0400 Original-Received: by mail-pg0-x22e.google.com with SMTP id a15so617301pgn.5 for ; Tue, 13 Mar 2018 17:13:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:message-id:date:user-agent:mime-version :content-language; bh=0Xwd713/Vc5W3bNaIpQbNIqmPzQSTDPW+IAkrFcE3Os=; b=n4rqCxUx3o/heVoS9qZ0xHprXIEbIFm6ooB2yKzUVVOIgKMfNx6Qfxojhf6k3nRfJr JFLuvhT6wVGXxuWz8HDgA2yGPWngJB8CTNdyYKDli5PhcM3fIHXo6reqBtR+FAhH27MO +HmOgw4MPQ5tLZpzQHwDj1flcwAj1HDGzRvt2tz/xuq0MkahLLt57WkcjT+YQMPis/wl /OfI/WKyr1L8TlM3g8PCaRHPCVXlxO9c4/k8VheqQEb4uS0j0cvm9WoMnU6jhTX2ZBqg whRwpkAMXR0+T9X6zwdMbl3DGOcmWnVV4awfrZ+4TpawLBDIaNn56enJB1B5tRWwFc9G 3RBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-language; bh=0Xwd713/Vc5W3bNaIpQbNIqmPzQSTDPW+IAkrFcE3Os=; b=kqATX8fb2cprGUqPzWqjYGvjjHIC/+3jcxCxPR5dYIrPLFQ9iW9MGG2RWBRHDVfufW IFwlE60P3znduOD43jc5uQiiU1PCoD9cU74b7TZIl8sJdJZ8yWbid56JmihV2ReLcSTE C3SWfOV48z0QRctL1/YxwDjMVp4mJp3gdYLbf2N+O6OaK5uhSWHWM2VP3x1K7oyoZcXx n6quloHAZBLZe7mXn5LYra5qcjxKkMSnnUrCz+IiWIKH0NNkpA10CDr4bdyghCVXx07J 4S/PR8E0QrV/LHY4a6T6G9ifHNT2hy1i1DnWB88ObE96S9CABfd/llcXvL0mpsRwPav8 AOVQ== X-Gm-Message-State: AElRT7EvQ2Aca2yob3I34oOxq5xHbnt5EJL884FheJuaYwMwSM7eGDQq 5d537x07qyLLfZwCAE0HSJQpQ9UD X-Google-Smtp-Source: AG47ELuEgDq7oax9zgOJ6rPgZFH/4AjMqf/53cBSedL3syRLByWRAzIY5gE9dWwpMEtLt6PYTb6QmQ== X-Received: by 10.101.65.71 with SMTP id x7mr1994205pgp.203.1520986401183; Tue, 13 Mar 2018 17:13:21 -0700 (PDT) Original-Received: from [192.168.2.183] (216-165-229-229.championbroadband.com. [216.165.229.229]) by smtp.gmail.com with ESMTPSA id 205sm2181710pfy.117.2018.03.13.17.13.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Mar 2018 17:13:20 -0700 (PDT) Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::22e X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:14489 Archived-At: Hi All, I am working on a ffi-helper (FH): a program that will read in a C dot-h file and generate a Guile dot-scm file which defines a module to provide hooks into the associated C library. Lately I've been working to clean up user-level APIs. A recoded demo of the GTK+ Hello World example is shown below. This is based on 100% guile wrappers to the loaded C libraries for gtk+, gobject, pango and glib.. The comments with the (use-modules (ffi xxx)) lines below indicate the line-counts for the associated ffi file and its auto-generated scm file. If you `git clone -b c99dev git://git.savannah.nongnu.org/nyacc.git' you will find the demo in examples/nyacc/lang/c99/ffi-exam/. Read the ffi-helper section of the HACKING file for hints to run the demo. Caveat: Up until a few months ago I was developing on MacOS; I am now on Ubuntu. ;; gtkdemo.scm ;;https://developer.gnome.org/gtk-tutorial/stable/c39.html#SEC-HELLOWORLD (use-modules (system ffi-help-rt)) (use-modules (bytestructures guile)) (use-modules (ffi glib)) ; ffi:31 scm:31889 (use-modules (ffi gobject)) ; ffi:26 scm:12044 (use-modules (ffi gtk2+)) ; ffi:26 scm:92964 ;; This will generate a FFI code wrapper around the lambda. Then below ;; we use (fh-cast GCallback hello) to match the argument signature. (define hello (make-GtkCallback (lambda (widget data) (display "Hello world!\n")))) (define (delete-event widget event data) (display "delete event occurred\n") 1) (define (main) (define window #f) (define button #f) (define argc (bytestructure int 0)) (gtk_init (pointer-to argc) NULL) (set! window (gtk_window_new 'GTK_WINDOW_TOPLEVEL)) (g_signal_connect window "delete-event" delete-event NULL) (g_signal_connect window "destroy" ~gtk_main_quit NULL) (gtk_container_set_border_width window 10) (set! button (gtk_button_new_with_label "Hello World")) (g_signal_connect button "clicked" (fh-cast GCallback hello) NULL) (g_signal_connect_swapped button "clicked" ~gtk_widget_destroy window) (gtk_container_add window button) (gtk_widget_show button) (gtk_widget_show window) (gtk_main)) (main) ;; --- last line ---