comparison semiconginev2/core/utils.nim @ 1218:56781cc0fc7c compiletime-tests

did: renamge main package
author sam <sam@basx.dev>
date Wed, 17 Jul 2024 21:01:37 +0700
parents semicongine/core/utils.nim@04e446a7eb2b
children 841e12f33c47
comparison
equal deleted inserted replaced
1217:f819a874058f 1218:56781cc0fc7c
1 type
2 HorizontalAlignment* = enum
3 Left
4 Center
5 Right
6 VerticalAlignment* = enum
7 Top
8 Center
9 Bottom
10
11 func CleanString*(str: openArray[char]): string =
12 for i in 0 ..< len(str):
13 if str[i] == char(0):
14 result = join(str[0 ..< i])
15 break
16
17 func ToCPointer*[T](list: openArray[T]): ptr T =
18 if list.len > 0: addr(list[0]) else: nil
19
20 proc StaticExecChecked*(command: string, input = ""): string {.compileTime.} =
21 let (output, exitcode) = gorgeEx(
22 command = command,
23 input = input)
24 if exitcode != 0:
25 raise newException(Exception, &"Running '{command}' produced exit code: {exitcode}" & output)
26 return output
27
28 proc AppName*(): string =
29 return string(Path(getAppFilename()).splitFile.name)
30
31 func Size*[T: seq](list: T): uint64 =
32 uint64(list.len * sizeof(get(genericParams(typeof(list)), 0)))
33
34 template TimeAndLog*(body: untyped): untyped =
35 let t0 = getMonoTime()
36 body
37 echo (getMonoTime() - t0).inNanoseconds.float / 1_000_000
38
39 template TimeAndLog*(name: string, body: untyped): untyped =
40 let t0 = getMonoTime()
41 body
42 echo name, ": ", (getMonoTime() - t0).inNanoseconds.float / 1_000_000