Skip to content

Instantly share code, notes, and snippets.

@wmoxam
wmoxam / tcltk.cr
Last active Oct 29, 2020
TK with Crystal aint bad either
View tcltk.cr
@[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
@wmoxam
wmoxam / tcl.cr
Created Oct 26, 2020
TCL is easy to embed!
View tcl.cr
@[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*
struct Tcl_Interp
result : LibC::Char*
freeProc : Tcl_FreeProc
View crystal-0.35.1.diff
Index: lang/crystal/Makefile
===================================================================
RCS file: /cvs/ports/lang/crystal/Makefile,v
retrieving revision 1.8
diff -u -p -u -r1.8 Makefile
--- lang/crystal/Makefile 7 Sep 2019 08:46:41 -0000 1.8
+++ lang/crystal/Makefile 29 Jun 2020 15:30:24 -0000
@@ -3,8 +3,9 @@
# Hopefully ${CLANG_ARCHS} at some point.
ONLY_FOR_ARCHS= amd64
View Makefile
CC=/usr/bin/cc
CFLAGS= -I/opt/X11/include -L/opt/X11/lib -std=iso9899:1999 -m64 -O0 -g -fno-builtin \
-pedantic -pedantic-errors \
-march=k8 -mtune=k8 -mieee-fp -mhard-float \
-fno-fast-math -malign-double \
-mstackrealign -mno-mmx \
CPPFLAGS=-D_TS_ERRNO -D_POSIX_PTHREAD_SEMANTICS -D_LARGEFILE64_SOURCE \
View openbsd snapshot + Crystal 0.31.1
home$ CXX=/usr/local/bin/clang++ gmake
Using /usr/bin/llvm-config [version=8.0.1]
/usr/local/bin/clang++ -c -o src/llvm/ext/llvm_ext.o src/llvm/ext/llvm_ext.cc -I/usr/include -O2 -pipe -fno-ret-protector -mno-retpoline -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -DNDEBUG -fno-exceptions -fno-rtti -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
cc -fPIC -c -o src/ext/sigfault.o src/ext/sigfault.c
ar -rcs src/ext/libcrystal.a src/ext/sigfault.o
CRYSTAL_CONFIG_PATH="/home/wmoxam/projects/crystal/src" CRYSTAL_CONFIG_LIBRARY_PATH="" CRYSTAL_CONFIG_BUILD_COMMIT="5d135c22b" ./bin/crystal build -o .build/crystal src/compiler/crystal.cr -D without_openssl -D without_zlib
View gist:543209dd8d5fc2f7d9385baf5406642f
$ uname -a
OpenBSD home.wmoxam.com 6.7 GENERIC.MP#116 amd64
$ crystal -v
Crystal 0.34.0 (2020-04-11)
LLVM: 8.0.1
Default target: x86_64-unknown-openbsd6.7
@wmoxam
wmoxam / build-error.txt
Last active Nov 11, 2017
Crystal Build error on OpenBSD 6.2
View build-error.txt
$ gmake deps
Using /usr/local/bin/llvm-config [version=5.0.0]
ar -rcs src/ext/libcrystal.a src/ext/sigfault.o
$ CC=/usr/local/bin/clang-5.0 gmake
Using /usr/local/bin/llvm-config [version=5.0.0]
CRYSTAL_CONFIG_PATH=`pwd`/src ./bin/crystal build -o .build/crystal src/compiler/crystal.cr -D without_openssl -D without_zlib
/usr/local/lib/libevent_core.so.1.1: warning: warning: random() may return deterministic values, is that what you want?
_main.o: In function `__crystal_personality':
main_module:(.text+0x2868): undefined reference to `_Unwind_GetRegionStart'
main_module:(.text+0x2873): undefined reference to `_Unwind_GetIP'
View gist:a3d93a1bcde7cfbdbc64d9584fd1929b
grammar Parser {
rule TOP { I <love> <lang> }
token love { '♥' | love }
token lang { < Perl Rust Go Python Ruby > }
}
say Parser.parse: 'I ♥ Perl';
# OUTPUT: 「I ♥ Perl」 love => 「♥」 lang => 「Perl」
say Parser.parse: 'I love Rust';
View hello.cr
require "motif"
app = Motif.new(ARGV, {title: "Hello"})
button = Motif.create_element(
Motif::PushButton,
{
label: "Push here to say hello"
}.to_h
)
View test.cr
@[Link("ncurses")]
lib NcursesPrivate
fun acs_map : Char*
end
lib Ncurses
fun initscr
ACS_ULCORNER = NcursesPrivate.acs_map()['l'.to_i]
end