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
## Bare-bones SDL2 example | |
import sdl2, sdl2/gfx | |
discard sdl2.init(INIT_EVERYTHING) | |
var | |
window: WindowPtr | |
render: RendererPtr | |
window = createWindow("SDL Skeleton", 100, 100, 640,480, SDL_WINDOW_SHOWN) |
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 mkcolor (a,b,c,d): uint32 = | |
uint32(SDL_FOURCC(a.int, b.int, c.int, d.int)) | |
converter toUint32 (some:color):uint32 = | |
mkColor(some.r, some.g, some.b, some.a) |
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 macros | |
macro super (x:typed): untyped = | |
## returns `x` with a type conv to its parent type, | |
## keeping ptr/ref info. `x` may be be an object, | |
## ptr or ref to an object, or a typedesc | |
var ty = getType(x) | |
var isTypedesc = ty.typekind == ntyTypedesc | |
if isTypedesc: ty = ty[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
C:\Users\phowl_000\src\crystal>crystal build test.cr | |
can't find file 'prelude' | |
C:\Users\phowl_000\src\crystal>set CRYSTAL_PATH | |
CRYSTAL_PATH="C:\users\phowl_000\src\crystal\src;libs" | |
C:\Users\phowl_000\src\crystal>set CRYSTAL_PATH= | |
C:\Users\phowl_000\src\crystal>crystal build test.cr | |
unexpected token: DELIMITER_START |
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 Unchecked* {.unchecked.}[T] = array[1,T] | |
var x = [1,2,3] | |
let y = cast[ptr Unchecked[int]](x[0].addr) | |
echo y[0] | |
echo y[1] | |
echo y[2] | |
echo y[3] # stack garbage | |
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 macros | |
proc concreteType* (n:NimNode): NimNode{.compileTime.}= | |
return case n.typeKind | |
of ntyTypeDesc: | |
n[1].concreteType |
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 macros | |
macro first (va_expr: expr): expr = | |
if va_expr.kind == nnkBracket: | |
return va_expr[0] | |
else: | |
return va_expr | |
macro rest (va_expr: expr): expr = | |
echo treerepr(va_expr) |
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 | |
jsobj {.importc.} = object | |
update*: proc(){.nimcall.} | |
d3_obj {.importc.} = object | |
linear* : proc(): jsobj{.nimcall.} | |
# this might work, to make it callable, i doubt it though | |
proc `()` (obj:jsobj; scale:float): float {.importc.} |
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
{.emit:""" | |
struct FooBase { | |
int x; | |
}; | |
template <typename T> | |
struct Foo: FooBase { | |
T val; | |
}; |
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 | |
App* = ref object of RootObj | |
vt*: AppVT | |
AppVT = object | |
draw*: proc(my:App) | |
update*: proc(my:App, dt:float) |