Mercurial > games > semicongine
annotate 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 |
rev | line source |
---|---|
890 | 1 type |
2 HorizontalAlignment* = enum | |
3 Left | |
4 Center | |
5 Right | |
6 VerticalAlignment* = enum | |
7 Top | |
8 Center | |
9 Bottom | |
10 | |
1137 | 11 func CleanString*(str: openArray[char]): string = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
12 for i in 0 ..< len(str): |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
13 if str[i] == char(0): |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
14 result = join(str[0 ..< i]) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
15 break |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
16 |
1137 | 17 func ToCPointer*[T](list: openArray[T]): ptr T = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
18 if list.len > 0: addr(list[0]) else: nil |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
19 |
1137 | 20 proc StaticExecChecked*(command: string, input = ""): string {.compileTime.} = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
21 let (output, exitcode) = gorgeEx( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
22 command = command, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
23 input = input) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
24 if exitcode != 0: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
25 raise newException(Exception, &"Running '{command}' produced exit code: {exitcode}" & output) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
26 return output |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
27 |
984
4e487f06378b
add: inital version of storage api (untested)
sam <sam@basx.dev>
parents:
943
diff
changeset
|
28 proc AppName*(): string = |
4e487f06378b
add: inital version of storage api (untested)
sam <sam@basx.dev>
parents:
943
diff
changeset
|
29 return string(Path(getAppFilename()).splitFile.name) |
4e487f06378b
add: inital version of storage api (untested)
sam <sam@basx.dev>
parents:
943
diff
changeset
|
30 |
1137 | 31 func Size*[T: seq](list: T): uint64 = |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
32 uint64(list.len * sizeof(get(genericParams(typeof(list)), 0))) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1190
diff
changeset
|
33 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1190
diff
changeset
|
34 template TimeAndLog*(body: untyped): untyped = |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1190
diff
changeset
|
35 let t0 = getMonoTime() |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1190
diff
changeset
|
36 body |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1190
diff
changeset
|
37 echo (getMonoTime() - t0).inNanoseconds.float / 1_000_000 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1190
diff
changeset
|
38 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1190
diff
changeset
|
39 template TimeAndLog*(name: string, body: untyped): untyped = |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1190
diff
changeset
|
40 let t0 = getMonoTime() |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1190
diff
changeset
|
41 body |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1190
diff
changeset
|
42 echo name, ": ", (getMonoTime() - t0).inNanoseconds.float / 1_000_000 |