Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/openpeeps/voodoo
Working with Nim's macros is just Voodoo 😱
https://github.com/openpeeps/voodoo
awesome-nim macros nim nim-lang nim-package openpeeps
Last synced: about 1 month ago
JSON representation
Working with Nim's macros is just Voodoo 😱
- Host: GitHub
- URL: https://github.com/openpeeps/voodoo
- Owner: openpeeps
- Created: 2024-04-02T11:44:02.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-08-10T12:07:47.000Z (5 months ago)
- Last Synced: 2024-08-10T13:26:01.125Z (5 months ago)
- Topics: awesome-nim, macros, nim, nim-lang, nim-package, openpeeps
- Language: Nim
- Homepage:
- Size: 247 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Working with Nim's macros 👑 is just Voodoo
nimble install voodoo
## 😍 Key Features
- [x] Compile-time utility tool
- [x] Helps reduce code size & repetitive tasks
- [x] Generate fast `getters`/`setters`
- [x] Callee Introspection## Examples
#### Getters
Generate fast getters from object fields. Excluding fields is also possible.
```nim
import pkg/voodootype
Price* {.getters.} = object
net, gross: stringProduct* {.getters: [id].} = object # exclude one or more fields
id: string
title, short_description: string
price: PriceexpandGetters() # is required to expand generated procs.
```Output:
```nim
proc getNet*(price: Price): string =
## Get `net` from `Price`
result = price.netproc getGross*(price: Price): string =
## Get `gross` from `Price`
result = price.grossproc getTitle*(product: Product): string =
## Get `title` from `Product`
result = product.titleproc getShortDescription*(product: Product): string =
## Get `short_description` from `Product`
result = product.short_descriptionproc getPrices*(product: Product): Price =
## Get `price` from `Product`
result = product.price
```#### Setters
todo#### Extensibles
It's easy to make extensible enums/objects. This may allow other modules/packages
to extend the functionality as if they were written in the original source.Also, `extensible` pragma works with both public or private definitions. Well, that looks like Voodoo to me!
```nim
import pkg/voodoo/extensible
type
Cardinal* {.extensible} = enum
north, west
```
Done! Now `Cardinal` is an extensible enum. Any other modules/packages importing it
can easily add fields to this enum. Yep, that's voodoo!```nim
import pkg/voodoo/extensible
extendEnum Cardinal:
south
eastimport ./cardinalModule
assert compiles(Cardinal.north)
assert compiles(Cardinal.south)
assert compiles(Cardinal.east)
```### ❤ Contributions & Support
- 🐛 Found a bug? [Create a new Issue](https://github.com/openpeeps/voodoo/issues)
- 👋 Wanna help? [Fork it!](https://github.com/openpeeps/voodoo/fork)
- 😎 [Get €20 in cloud credits from Hetzner](https://hetzner.cloud/?ref=Hm0mYGM9NxZ4)
- 🥰 [Donate via PayPal address](https://www.paypal.com/donate/?hosted_button_id=RJK3ZTDWPL55C)### 🎩 License
MIT license. [Made by Humans from OpenPeeps](https://github.com/openpeeps).
Copyright © 2024 OpenPeeps & Contributors — All rights reserved.