Skip to content

Instantly share code, notes, and snippets.

@wmoxam
Last active October 29, 2020 14:12
Show Gist options
  • Save wmoxam/c62bf3714789fd4978f55a2603285323 to your computer and use it in GitHub Desktop.
Save wmoxam/c62bf3714789fd4978f55a2603285323 to your computer and use it in GitHub Desktop.
TK with Crystal aint bad either
@[Link("tcl")]
lib LibTcl
type Tcl_FreeProc = Void*
fun Tcl_SetVar(interp : Tcl_Interp*, varName : LibC::Char*, newValue : LibC::Char*, flags : Int32) : LibC::Char*
fun Tcl_Eval(interp : Tcl_Interp*, script : LibC::Char*) : Int32
fun Tcl_CreateInterp : Tcl_Interp*
fun Tcl_GetStringResult(interp : Tcl_Interp*) : LibC::Char*
fun Tcl_Init(interp : Tcl_Interp*) : Void
struct Tcl_Interp
result : LibC::Char*
freeProc : Tcl_FreeProc
errorLine : Int32
end
end
@[Link("tk")]
lib LibTk
fun Tk_Init(interp : LibTcl::Tcl_Interp*) : Void
fun Tk_MainLoop : Void
end
my_string = "MagicWord"
puts("The secret is '#{my_string}'")
interp = LibTcl.Tcl_CreateInterp
LibTcl.Tcl_Init(interp)
LibTk.Tk_Init(interp)
LibTcl.Tcl_SetVar(interp, "my_string", my_string, 0)
script = <<-END_SCRIPT
package require Tk
pack [button .b -text {Push Me} -command {
tk_messageBox -message $my_string
}]
END_SCRIPT
puts LibTcl.Tcl_Eval interp, script
puts String.new(LibTcl.Tcl_GetStringResult(interp))
LibTk.Tk_MainLoop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment