From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Hans Aberg Newsgroups: gmane.lisp.guile.user Subject: C++ wrap Date: Mon, 22 Feb 2010 15:01:29 +0100 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1266847508 14643 80.91.229.12 (22 Feb 2010 14:05:08 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 22 Feb 2010 14:05:08 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Feb 22 15:05:04 2010 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1NjYuG-0005r7-6o for guile-user@m.gmane.org; Mon, 22 Feb 2010 15:05:04 +0100 Original-Received: from localhost ([127.0.0.1]:56886 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NjYuF-00005v-OI for guile-user@m.gmane.org; Mon, 22 Feb 2010 09:05:03 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NjYqs-0007Kb-1Q for guile-user@gnu.org; Mon, 22 Feb 2010 09:01:34 -0500 Original-Received: from [140.186.70.92] (port=36473 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NjYqr-0007K9-2l for guile-user@gnu.org; Mon, 22 Feb 2010 09:01:33 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NjYqp-0001EZ-PY for guile-user@gnu.org; Mon, 22 Feb 2010 09:01:32 -0500 Original-Received: from pne-smtpout1-sn1.fre.skanova.net ([81.228.11.98]:41069) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NjYqp-0001EP-KJ for guile-user@gnu.org; Mon, 22 Feb 2010 09:01:31 -0500 Original-Received: from h131n2-fre-d2.ias.bredband.telia.com (78.72.157.131) by pne-smtpout1-sn1.fre.skanova.net (7.3.140.3) (authenticated as u26619134) id 4B5C64F7003DE2F6 for guile-user@gnu.org; Mon, 22 Feb 2010 15:01:30 +0100 X-Mailer: Apple Mail (2.936) X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:7656 Archived-At: I have written a bit on a C++ wrap - has this been done? I use templates to get a static typed style similar to that of Haskell, which can be overridden at need. Some example code below. Hans ---- #include "src/guile.hh" #include #include #include int inner_main(std::pair* argp) { for (int i = 0; i < argp->first; ++i) std::cout << argp->second[i] << std::endl; using namespace scm; integer x = 2567575364397498ull; integer y = (uint64_t)2567575364397500ull; out << "-x = " << -x << "\ny = " << y << newline; // Checking object references and mutative operations: object w = x; ++x; out << "w = " << w << newline; out << "x = " << x << newline; function2 f("-"); // Using C++ output: std::cout << "f(x, y) = " << (char*)string(f(x, y), 10) << std::endl; // Loading a module, and using a function in it: object("(use-modules (ice-9 pretty-print))"); function<> pretty("pretty-print"); const char* text = "'(define (foo) (lambda (x) \ (cond ((zero? x) #t) ((negative? x) -x) (else \ (if (= x 1) 2 (* x x x))))))"; out << "Function:\n"; pretty(object(text)); list<> ks(std::list(5, 6)); out << "std::list(5, 6) = " << ks << newline << flush; function1 inc("(lambda (x) (+ x 1))"); out << "inc(integer(3)) = " << inc(integer(3)) << newline; return EXIT_SUCCESS; } int main(int argc, char **argv) { std::pair arg(argc, argv); return scm::with_guile*, int>(inner_main) (&arg); } ---- $ g++ test.cc -lguile -o test && ./test ./test -x = -2567575364397498 y = 2567575364397500 f(x, y) = -2 Function: (define (foo) (lambda (x) (cond ((zero? x) #t) ((negative? x) -x) (else (if (= x 1) 2 (* x x x)))))) std::list(5, 6) = (6 6 6 6 6) inc(integer(3)) = 4 ----