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 | |
| # --- | |
| type | |
| GameObj[T] = ref object | |
| props: T | |
| alive: bool | |
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 jsonstream | |
| let | |
| js = JsonStream() # Compile-time Error: empty params not allowed | |
| js = new JsonStream # Compile-time Error: empty params not allowed | |
| js = JsonStream("some/path.data") # Works: calls 'create' implicitly | |
| something(js) # won't get here unless you properly construct the JsonStream (or go out of your way) | |
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 | |
| PBCEnv = ref object | |
| PBCPattern = int | |
| proc pbc_pattern_new(e:PBCEnv, msg, format: cstring, offsets: varargs[int]): int = | |
| echo msg, ", ", format | |
| for n in offsets: | |
| result += n | |
| macro wrapped_pbc_pattern_new(e: PBCEnv, msg, format: cstring, offsets: varargs[int]): 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
| import macros | |
| {.emit:""" | |
| void foobar(int i, ...) { | |
| va_list args; | |
| int j; | |
| printf("Count: %i\n", i); | |
| va_start(args, i); | |
| for (j = 0; j < i; j++) { |
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
| macro doThis(s:static[string]): stmt = | |
| let n = parseStmt(s) | |
| quote do: | |
| template actuallyDoIt: stmt = | |
| `n` | |
| doThis("echo 1") | |
| static: | |
| actuallyDoIt() |
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, threadPool | |
| # --- | |
| type | |
| Person = object | |
| age: int | |
| friend: ref Person |
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 hasPragma(procedure:expr, name:string): bool {.compileTime.} = | |
| # checks if a procedure has a specific pragma | |
| let procPragma = procedure[4]#.pragma | |
| for p in procPragma.children: | |
| if p.repr == name: |
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 unsigned, macros | |
| type | |
| TokenType = enum | |
| comment, qstr, phrase, local_dot_atom_pre_comment, local_dot_atom, local_quoted_string, domain, obs_domain_list, angle_addr, address, group_name, msg_id, date, time, received_tokens, major_digits, minor_digits, param_val, param_attr, main_type, sub_type, encoding, disp_type, ctime_date, token_string | |
| EventType = enum | |
| enter, exit | |
| Event = object | |
| tokentype: TokenType | |
| position: int |
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 makeEmitPrag(lit:static[string]): stmt = | |
| result = newStmtList().add( | |
| newNimNode(nnkPragma).add( | |
| newNimNode(nnkExprColonExpr).add( | |
| newIdentNode("emit"), | |
| newStrLitNode(lit) | |
| ) | |
| ) |
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 RenderTexture = object | |
| type RenderWindow = object | |
| type Sprite = object | |
| type RenderTarget* = RenderTexture | RenderWindow | |
| type RenderTargetProc* = proc(s:Sprite, r:RenderTarget) | |
| type Drawable* = generic d, r | |
| r is RenderTarget | |
| d.draw(r) |