This file contains 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 macros, sets | |
macro lcSet(body): untyped = | |
# analyse the body, find the deepest expression 'it' and replace it via | |
# 'result.add it' | |
let res = genSym(nskVar, "lcResult") | |
proc t(n, res: NimNode): NimNode = | |
# Looks for the last statement of the last statement, etc... | |
case n.kind |
This file contains 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, algorithm | |
const wordlistFilename = "words.txt" | |
template with(f, fn, actions: untyped): untyped = | |
var f: File | |
if open(f, fn): | |
try: | |
actions | |
finally: | |
close(f) |
This file contains 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
# based on: https://dewitters.com/dewitters-gameloop/ | |
# http://lspiroengine.com/?p=378 | |
proc run(game: var Game) = | |
const | |
ticksPerSec = 25 | |
skippedTicks = 1_000_000_000 div ticksPerSec # to nanosecs per tick | |
maxFramesSkipped = 5 # 20% of ticksPerSec | |
var lastTime = getMonoTime().ticks |
This file contains 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 macros | |
{.experimental: "forLoopMacros".} | |
macro zip*(x: ForLoopStmt): untyped = | |
expectKind x, nnkForStmt | |
result = newStmtList() | |
echo x.repr | |
var args: seq[NimNode] | |
for i in 1 ..< x[^2].len: | |
args.add x[^2][i] |
This file contains 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 macros, parsejson, streams | |
template loadArray() {.dirty.} = | |
if p.kind != jsonArrayStart: raiseParseErr(p, "'[' expected for an array") | |
next(p) | |
var i = 0 | |
while p.kind != jsonArrayEnd and p.kind != jsonEof: | |
inc(i) | |
if p.kind == jsonArrayEnd: next(p) | |
else: raiseParseErr(p, "']' end of array expected") |
This file contains 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 macros, sets, tables | |
proc transLastStmt(n, res, bracketExpr: NimNode): (NimNode, NimNode, NimNode) = | |
# Looks for the last statement of the last statement, etc... | |
case n.kind | |
of nnkStmtList, nnkStmtListExpr, nnkBlockStmt, nnkBlockExpr, nnkWhileStmt, | |
nnkForStmt, nnkIfExpr, nnkIfStmt, nnkTryStmt, nnkCaseStmt, | |
nnkElifBranch, nnkElse, nnkElifExpr: | |
result[0] = copyNimTree(n) | |
result[1] = copyNimTree(n) |
This file contains 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 sugar, deques, sets, algorithm | |
include tables | |
proc at[A, B](t: Table[A, B]; i: int): (A, B) = | |
(t.data[i].key, t.data[i].val) | |
proc index[A, B](t: Table[A, B]; key: A): int = | |
var hc: Hash | |
result = rawGet(t, key, hc) |
This file contains 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
when declared(use_pkg_config) or declared(use_pkg_config_static): | |
{.pragma: libcairo, cdecl.} | |
when defined(use_pkg_config_static): | |
{.passl: gorge("pkg-config cairo --libs --static").} | |
else: | |
{.passl: gorge("pkg-config cairo --libs").} | |
else: | |
when defined(windows): | |
const LibCairo* = "libcairo-2.dll" | |
elif defined(macosx): |
This file contains 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
## This template provides syntactic sugar and | |
## that emulates/substitutes an optional type | |
type | |
SomePointer = ref | ptr | pointer | proc | |
template `?=`*(value, call: untyped): bool = | |
## Operator that unwraps the "optional" value that `call` returns, into `value`. | |
## This can be `(bool, T)` or any pointer type. | |
## Used only as an if condition |
This file contains 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 | |
Entity = uint16 | |
Version = uint8 | |
Registry = object | |
destroyed: Entity | |
entities: seq[Entity] | |
const |
OlderNewer