This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zlib | |
proc compress(source: string): string = | |
var | |
sourcelen = source.len | |
destlen = sourcelen + (sourcelen.float * 0.1).int + 16 | |
result = "" | |
result.setLen destLen |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# STFL - The Structured Terminal Forms Language/Library | |
# Copyright (C) 2006, 2007 Clifford Wolf <[email protected]> | |
# | |
# This library is free software; you can redistribute it and/or | |
# modify it under the terms of the GNU Lesser General Public | |
# License as published by the Free Software Foundation; either | |
# version 3 of the License, or (at your option) any later version. | |
# | |
# This library is distributed in the hope that it will be useful, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import endians | |
proc swapEndian16*(outp, inp: pointer) = | |
## copies `inp` to `outp` swapping bytes. Both buffers are supposed to | |
## contain at least 2 bytes. | |
var i = cast[cstring](inp) | |
var o = cast[cstring](outp) | |
o[0] = i[1] | |
o[1] = i[0] | |
when cpuEndian == bigEndian: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from strutils import format | |
type TColor = enum | |
black = 0, red, green, yellow, blue, magenta, cyan, white, default | |
proc color(s: string; fg: TColor; bg = black): string = | |
result = "\x1B[$1;$2m$3\x1B[0m".format(fg.int + 30, bg.int + 40, s) | |
echo color("error!", red) | |
echo color("sup", green, yellow) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template foo(): stmt = | |
var x = "hello" | |
echo x | |
foo() | |
echo(definedInScope(x)) | |
template dirtyfoo(): stmt {.dirty.}= | |
var x = "hello" | |
echo x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math, os, strutils | |
randomize() | |
proc color(c: string; res: var string; fg = random(30), bg = random(30)) = | |
res.add '\3' | |
res.add($fg) | |
res.add ',' | |
res.add($bg) | |
res.add c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import strutils | |
when defined(parserPeg): | |
import pegs | |
elif defined(parserRegex): | |
import re | |
else: | |
{.error: "define either parserPeg or parserRegex".} | |
proc last*[A](some: seq[A]): A = return some[len(some)-1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lua, lualib, lauxlib, sfml, sfml_colors, strutils, sf_gui, json | |
const | |
ScreenW = 800 | |
ScreenH = 600 | |
var | |
window = new_render_window(video_mode(ScreenW, ScreenH, 32), "Lame Lua", sfDefaultStyle) | |
event: TEvent | |
text = newText("herro", guifont, 18) | |
gui = newContainer("luathinger_settings.json") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import opengl | |
when defined(Linux): | |
import x, xlib, xutil | |
type | |
PWindow = ref TWindow | |
TWindow = object | |
when defined(Linux): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
Bool32* {.size: sizeof(cint).} = enum | |
False32 = 0, True32 = 1 | |
converter toBool*(a: Bool32): bool = bool(a) | |
when isMainModule: | |
var x = False32 | |
if x: echo "hi" | |
else: echo "not x" |