Skip to content

Instantly share code, notes, and snippets.

@dandevelo dandevelo/staticread.nim Secret
Last active Jun 13, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.