Create a ref to a C allocated object to manage its memory

2022-12-27 Thread samdze
That is not enough for me. I want to wrap the C returned array into an immutable seq and return it to the user to provide a safe API. Seems like openArrays cannot be used this way. Also, I'd like Nim to call the `=destroy` proc I defined when there are no references to this (ref) seq left.

Create a ref to a C allocated object to manage its memory

2022-12-27 Thread samdze
Thanks for your replies! Related to this thread, I have another question: This time I'd like to wrap (and manage) a C returned array (pointer to heap + length) into a Nim seq (or ref seq) without performing extra copies. Is it possible?

Create a ref to a C allocated object to manage its memory

2022-12-21 Thread samdze
Mhh, I thought Nim could somehow create its housekeeping information on the fly, initializing a ref from a pointer to a data location. But i guess it just can't. If the housekeeping data is put before the referenced obj when a completely new ref is constructed, then it makes sense that Nim woul

Create a ref to a C allocated object to manage its memory

2022-12-21 Thread samdze
I already use that approach in other areas of my wrapper, but in this case I'd like not to define an additional object type just to hold a pointer to another object. Also because I'd like to directly access CObject's properties through CObjectRef, for example. But also because sometimes I get

Create a ref to a C allocated object to manage its memory

2022-12-21 Thread samdze
I'm in the process of wrapping a C API, and I found myself wanting to wrap a C returned pointer to a struct with Nim ref, to manage its memory. How can I do that? 1. Get a pointer to a struct from a C API. 2. Create a new ref for the struct referenced by the pointer. type COb

Polymorphism doesn't work building a dylib for Playdate (Cortex M7) with ARC

2022-11-30 Thread samdze
Thanks! The configuration I posted here is minimal, just to reproduce the issue. I do already use nimAllocPagesViaMalloc (and also build for arm when targeting the device) but didn't know the Playdate is using FreeRTOS! Nice!

Polymorphism doesn't work building a dylib for Playdate (Cortex M7) with ARC

2022-11-29 Thread samdze
Wow, that seems to be it. Thank you!

Polymorphism doesn't work building a dylib for Playdate (Cortex M7) with ARC

2022-11-29 Thread samdze
I'm writing Nim bindings for the C SDK release by Panic for the Playdate portable console. However, I stumbled upon an issue writing a more ergonomic API over the existing one. I'm testing this on the Playdate simulator. Polymorphism doesn't work as expected, here's my code: # ---

Type macro returning a transformed type def + other definitions

2022-11-29 Thread samdze
Thanks! For others, I've found this feature to be partially documented here:

Type macro returning a transformed type def + other definitions

2022-11-25 Thread samdze
I tried outputting the the exact AST this code generates: type Test = object obj: int proc generatedProc(this: Test, arg: int): int = return 1 Run AST gen: nnkStmtList.newTree( nnkTypeSection.newTree( nnkTypeDef

Type macro returning a transformed type def + other definitions

2022-11-24 Thread samdze
I'm writing a macro "testmacro" that should take this type definition: type Test {.testmacro.} = object normalProc: proc(add: int): int Run and generate this code: type Test = object normalProc: proc(add: int): int proc normalProcG