gpt4 book ai didi

bash - 如何强制 F# interactive 默认引用 Gtk#?

转载 作者:行者123 更新时间:2023-11-29 09:02:11 24 4
gpt4 key购买 nike

我主要在 Linux 上使用 F#,并希望默认引用所有必要的 GUI 库(Gtk、Gdk、Atk、Glib、Pango、Cairo),以便我可以简单地使用:
打开 Gtk;;
无需任何额外的输入。我最好的猜测是修改 fsi 启动脚本,目前看起来像这样:


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

更新:Stephen 建议的脚本工作版本:


#!/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/cli/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" $@

最佳答案

我写了一个小脚本,允许您使用 F# Interactive 中的 Gtk#(见下文)。它引用必要的 Gtk# 程序集(您可能需要修改路径),它还配置 F# Interactive 事件循环,以便您可以交互式地创建和显示小部件(例如 Window)。

如果你想自动获得支持,你需要运行 fsi.exe 并在启动时加载脚本 mono/.../fsi.exe - -load:load-gtk.fsx(假设您将脚本保存为 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() = () }

关于bash - 如何强制 F# interactive 默认引用 Gtk#?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4174852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com