Mercurial > games > semicongine
diff semiconginev2/old/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/old/core/utils.nim@a3eb305bcac2 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/semiconginev2/old/core/utils.nim Wed Jul 17 21:01:37 2024 +0700 @@ -0,0 +1,38 @@ +import std/typetraits +import std/strutils +import std/paths +import std/os +import std/strformat + +type + HorizontalAlignment* = enum + Left + Center + Right + VerticalAlignment* = enum + Top + Center + Bottom + +func CleanString*(str: openArray[char]): string = + for i in 0 ..< len(str): + if str[i] == char(0): + result = join(str[0 ..< i]) + break + +func ToCPointer*[T](list: openArray[T]): ptr T = + if list.len > 0: addr(list[0]) else: nil + +proc StaticExecChecked*(command: string, input = ""): string {.compileTime.} = + let (output, exitcode) = gorgeEx( + command = command, + input = input) + if exitcode != 0: + raise newException(Exception, &"Running '{command}' produced exit code: {exitcode}" & output) + return output + +proc AppName*(): string = + return string(Path(getAppFilename()).splitFile.name) + +func Size*[T: seq](list: T): uint64 = + uint64(list.len * sizeof(get(genericParams(typeof(list)), 0)))