Giter VIP home page Giter VIP logo

haskell-gi's Introduction

haskell-gi

Generate Haskell bindings for GObject Introspection capable libraries.

Using the generated bindings

The most recent versions of the generated bindings are available from hackage. To install, start by making sure that you have a recent (1.24 or later) version of cabal-install:

$ cabal install cabal-install
$ cabal --version
cabal-install version 1.24.0.0
compiled using version 1.24.0.0 of the Cabal library 

Then install the bindings you need. For instance, for the gtk+ bindings you can do:

$ cabal install gi-gtk

(Note: you may need to run this command twice, due to a bug in cabal).

That's it! Here is an example "Hello World" program:

{-# LANGUAGE OverloadedStrings, OverloadedLabels #-}

import qualified GI.Gtk as Gtk
import Data.GI.Base

main :: IO ()
main = do
  Gtk.init Nothing

  win <- new Gtk.Window [ #title := "Hi there" ]

  on win #destroy Gtk.mainQuit

  button <- new Gtk.Button [ #label := "Click me" ]

  on button #clicked (set button [ #sensitive := False,
                                   #label := "Thanks for clicking me" ])

  #add win button

  #showAll win

  Gtk.main

This program uses the new OverloadedLabels extension in GHC 8.0, so make sure you have a recent enough version of GHC installed. To run this program, copy it to a file (hello.hs, say), and then

$ ghc -o hello hello.hs
$ ./hello

For a more involved example, see for instance this WebKit example. Further documentation can be found in the Wiki.

Binding to new libraries

It should be rather easy to generate bindings to any library with gobject-introspection support, see the examples in the bindings folder. Pull requests appreciated!

Build Status Join the chat at https://gitter.im/haskell-gi/haskell-gi

haskell-gi's People

Contributors

clumens avatar develop7 avatar ford-prefect avatar garetxe avatar hamishmack avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.