Skip to content

Instantly share code, notes, and snippets.

@dandevelo
Last active June 13, 2018 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dandevelo/7a742d06c74c46ba67a141db1905d990 to your computer and use it in GitHub Desktop.
Save dandevelo/7a742d06c74c46ba67a141db1905d990 to your computer and use it in GitHub Desktop.
import macros
macro foo(x: static[string]): untyped =
var r: seq[uint8] = @[]
for i in 0 ..< x.len:
r.add x[i].uint8
result = quote do: `r`
const
resources {.exportc.} = foo(staticRead"resources.bin")
# BUG? resources is generated as array[0..len, int] instead of array[0..len, uint8]
# the following code is needed for the const to be generated in the .C file
proc calcSum() =
var sum = 0
for b in resources:
sum = sum + b
echo sum
calcSum()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment