Hello, having trouble using allocCstringArray to to allocate enough space for my extensions in Vulkan.
The problem is that the extension member is an array of 256 char so i cannot use it in allocCstringArray.
So here is the code to my problem.
VkExtensionProperties* = object
extensionName*: array[vkMaxExtensionNameSize, char]
specVersion*: uint32
i can get the "extensionName" member to a cstring but allocCstringArray wants a openarray of string.
so this is far as i got tonight.
for i in 0 .. extension_prop.len:
var s = (extension_prop[i].extensionName.cstring)
extension = allocCStringArray(??) #what to do here?
and i have to use cstringArray for the "extension" type. I'm sure there is someway to do this.
but allocCstringArray wants a openarray of string.
So you should give it one. You should know how you can create an array or a seq of strings. When you know that 256 chars are desired for each string, then you fill the array with strings with at least this size. And finally you pass that array or seg to allocCstringArray().
[EDIT]
Well I really think you know -- somethink like
var a: array[8, string] # assume we need only 8 strings
for i in mitems(a): i = newString(256)
var s: seq[string]
s = newSeq[string]()
s.add(newString(256)) # do in a loop and add as many as you like
Hi stefan it seems your suggestion jogged my memory banks a bit.
Here is what i came up with. It seems to work so far.
var s : seq[string] = newSeq[string](extension_count)
for i in 0 .. s.len:
var f = extension_prop[i].extensionName.cstring
s[i] = newString(256)
s[i] = cast[string](f)
extension = alloccstringArray(s)
edit: with the above code i get an "out of memory" err from nim. so i'm still not sure how to do this.
And while i'm at it, anyone know how to either use the __LINE__ macro from the compiler in nim? Or even the '#' stringify preprocessor symbol?
I have a template that checks the proc result calls in vulkan and puts out the error string. Nim makes it easy to do this, but i dunno what the corresponding line is where the error or proc call is.
Here:
template lineNim: int = instantiationInfo().line
proc main =
echo "Nim line: ", lineNim
var lineC: int
{.emit: "`lineC` = __LINE__;".}
echo "C line: ", lineC
{.emit: "#define foo(s) #s".}
var stuff: cstring
{.emit: "`stuff` = foo(thisIsTheArgument);".}
echo stuff
main()
hmm, still having some trouble, it seems nim won't let you politely cast cstring to string. I tried unsafe cast and it compiles but i get the "out of memory" err.
But i have to use cstringArray for the vulkan lib in the end.
I will come back later and do some digging in the docs. and maybe somebody will suggest something.
it seems nim won't let you politely cast cstring to string.
From the doc
A $ proc is defined for cstrings that returns a string. Thus to get a nim string from a cstring:
var str: string = "Hello!"
var cstr: cstring = str
var newstr: string = $cstr