开发者

How to force F# interactive to reference Gtk# by default?

I am mostly playing with F# on Linux and would like to get all the necessary GUI libraries (Gtk, Gdk, Atk, Glib, Pango, Cairo) to be referenced by default so that I can simply use: open Gtk;; without any additional typing. My best guess would modifying the fsi launching script, which at the moment looks like that:


    #!/bin/sh  
    exec /usr/bin/mono /usr/local/src/fsharp/bin/fsi.exe $@

Update: working version of the script as in Stephen's suggestion:


    #!/bin/sh
    exec /usr/bin/mono /usr/local/src/fsharp/bin/fsi.exe -r "/usr/lib/cli/atk-sharp-2.0/atk-sharp.dll" -r "/usr/lib/cli/glib-sharp-2.0/glib-sharp.dll" -r "/usr/lib/cli/gdk-sharp-2.0/gdk-sharp.dll" -r "/usr/lib/cl开发者_JAVA百科i/gtk-sharp-2.0/gtk-sharp.dll" -r "/usr/lib/cli/pango-sharp-2.0/pango-sharp.dll" -r "/usr/lib/mono/2.0/Mono.Cairo.dll" $@


I wrote a little script that allows you to use Gtk# from F# Interactive (see below). It references the necessary Gtk# assemblies (you may need to modify the paths) and it also configures F# Interactive event loop, so that you can create and display widgets (such as Window) interactively.

If you want to get the support automatically, you'll need to run fsi.exe with a parameter to load the script on start mono /.../fsi.exe --load:load-gtk.fsx (assuming that you save the script as load-gtk.fsx)

[<AutoOpen>]
module GtkSharp

// Load some common Gtk# assemblies (from /usr/lib/mono/2.0/../gtk-sharp-2.0)
#r "../gtk-sharp-2.0/gtk-sharp.dll"
#r "../gtk-sharp-2.0/gdk-sharp.dll"
#r "../gtk-sharp-2.0/glib-sharp.dll"
#r "../gtk-sharp-2.0/atk-sharp.dll"

open Gtk

Application.Init()
fsi.EventLoop <- 
 { new Microsoft.FSharp.Compiler.Interactive.IEventLoop with
   member x.Run() = Application.Run() |> ignore; false
   member x.Invoke f = 
     let res = ref None
     let evt = new System.Threading.AutoResetEvent(false)
     Application.Invoke(new System.EventHandler(fun _ _ ->
       res := Some(f())
       evt.Set() |> ignore ))
     evt.WaitOne() |> ignore
     res.Value.Value 
   member x.ScheduleRestart() = () }


It may be a little different in Linux, but in Windows you can reference assemblies on fsi startup by using -r. e.g.

#!/bin/sh
exec /usr/bin/mono /usr/local/src/fsharp/bin/fsi.exe -r /usr/somedll.dll $@ 


I am guessing add

-r:/path/to/gtk

or

--load:someStartupScript.fs

which maybe includes some #rs or whatnot. fsi /? and you'll figure it out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜