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 | |
from winlean import useWinUnicode | |
when useWinUnicode: | |
type winString = WideCString | |
let apiPrefix = "W" | |
else: | |
type winString = CString | |
let apiPrefix = "A" | |
macro WinImport*(baseProc: stmt): stmt {.immediate.} = |
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 | |
iterator split*(s, sep: string): string = | |
var remainder = s # What string contents is left | |
var pos = find(remainder, sep) | |
while pos != -1: | |
let | |
start = pos-1 | |
middle = pos+sep.len | |
ending = remainder.len-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
Succeeded on x86-64 (64 bit), failed on x86 (32 bit) | |
t99bott.nim | |
tbind2.nim | |
teffects1.nim | |
tenummix.nim | |
tnot.nim | |
twrongconst.nim | |
twrongiter.nim | |
tbindtypedesc.nim | |
tthreadgeneric |
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
# This | |
proc findFirstFileW*(lpFileName: WinString, | |
lpFindFileData: var TWIN32_FIND_DATA): THandle {. | |
stdcall, dynlib: "kernel32", winApi.} | |
# Becomes this when using the Unicode Windows API | |
proc findFirstFile*(lpFileName: WinString, lpFindFileData: var TWIN32_FIND_DATA): THandle {. | |
stdcall, dynlib: "kernel32", importc: "FindFirstFileW".} |
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:\64\Nimrod>nimrod c test.nim | |
config\nimrod.cfg(37, 2) Hint: added path: 'C:\Users\Clay\.babel\pkgs\windows-1.0' [Path] | |
config\nimrod.cfg(37, 2) Hint: added path: 'C:\Users\Clay\.babel\pkgs\babel-0.1.0' [Path] | |
config\nimrod.cfg(37, 2) Hint: added path: 'C:\Users\Clay\.babel\pkgs\' [Path] | |
Hint: used config file 'C:\64\nimrod\config\nimrod.cfg' [Conf] | |
Hint: system [Processing] | |
Hint: test [Processing] | |
Hint: tables [Processing] | |
Hint: hashes [Processing] | |
Hint: strutils [Processing] |
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
# Implementation | |
iterator split*(s, sub: string): string = | |
## Replaces `sub` in `s` by the string `by`. | |
var a {.noinit.}: TSkipTable | |
preprocessSub(sub, a) | |
var i, j = 0 | |
let z = s.len() | |
while true: | |
j = findAux(s, sub, i, a) | |
if j < 0: break |
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 | |
type charContainer = generic c | |
c.contains(char) is bool | |
iterator split*(s: string, seps: charContainer = Whitespace): string = | |
## Splits the string `s` into substrings using a group of separators. | |
## | |
## Substrings are separated by a substring containing only `seps`. Note | |
## that whole sequences of characters found in ``seps`` will be counted as |
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 isMainModule: | |
doAssert split("Hello<world<!!", '<') == @["Hello", "world", "!!"] | |
doAssert split("Hello<world<", '<') == @["Hello", "world", ""] | |
doAssert split("<Hello<world<", '<') == @["", "Hello", "world", ""] | |
doAssert split("Hello<world<!!", {'<'}) == @["Hello", "world", "!!"] | |
doAssert split("Hello<world<", {'<'}) == @["Hello", "world"] | |
doAssert split("<Hello<world<", {'<'}) == @["Hello", "world"] |
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
proc setControlCHook(hook: proc () {.noconv.}) = | |
# ugly cast, but should work on all architectures: | |
type TSignalHandler = proc (sig: cint) {.noconv.} | |
c_signal(SIGINT, cast[TSignalHandler](hook)) |
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 | |
TTest = tuple[x: range[0..80], y: range[0..25]] | |
let x: TTest = (2, 23) | |
echo(x) |