first impression, strange `=destroy`

2024-07-24 Thread exelotl
I think OPs point of confusion is mostly surrounding the backticks? In JavaScript: `foo` is a string template literal. In Nim `foo` is an identifier. In fact it's the same as foo without backticks. The backticks are needed if the name contains special characters or is the same as a language key

Nimble incorrect package structure warning: What is going to be?

2024-07-07 Thread exelotl
Thanks for this! I've also been bugged by this seemingly pointless warning for years 😅

Escape characters for fmt

2023-12-20 Thread exelotl
> My guess is that & allows for escape characters even without whitespace is > because it is concatenating string literals, something inherent to the & > operator? No, I believe the reason is simply that `&` is not an identifier, therefore the parser doesn't see `&"foo"` as a raw string literal

Escape characters for fmt

2023-12-20 Thread exelotl
There's nothing special about `fmt`. This is just how Nim treats any occurrence of `xyz"string"` where there is no space between them. See [Raw string literals](https://nim-lang.org/docs/manual.html#lexical-analysis-raw-string-literals) and the section _" Generalised raw string literals"_ below

overload operator `+=` for private member

2023-11-19 Thread exelotl
I don't think it can be done in that case. Well, there's an unsafe way of doing it if you know that the two types are binary compatible and of the same size. type Obj = object m: cint static: doAssert(sizeof(cint) == sizeof(int32)) proc `m`*(o: v

NIR

2023-11-04 Thread exelotl
My project is large, every time I make a tiny change I have to wait for 1200 modules to compile to see if it worked, it's a real productivity killer. So incremental compilation gets my vote - unless tackling one of the other features would allow for a better quality IC implementation. I hope IC

tell me the library for windows to download files with a progress bar

2023-06-07 Thread exelotl
For the GUI side of things, you could use [wNim](https://github.com/khchen/wNim) or [IUP](https://github.com/nim-lang/iup).

High stack usage when calling `reset` on an object with a destructor

2023-05-08 Thread exelotl
Hey, I'm not sure if this counts as a bug or not so thought I'd ask about it here: I have the following code: type GoodboySave* = object data: array[5000, uint8] proc `=destroy`*(s: var GoodboySave) = discard var sav: GoodboySave reset(sav)

State of HTTP Servers in Nim

2023-04-07 Thread exelotl
It was super interesting to see all the Nim HTTP servers compared like this. I wonder how [GuildenStern](https://github.com/olliNiinivaara/GuildenStern) stacks up? (it's most similar to Mummy I believe)

.o files going missing before linking?

2023-03-17 Thread exelotl
@dwhall256 `R:` is a ramdisk created with IMDisk Toolkit, but the same problem happened when we had a local nimcache in the project directory too.

.o files going missing before linking?

2023-03-15 Thread exelotl
Hey! Some team members on my project are having an issue where linking sometimes (seemingly at random) fails because the .o files that were supposed to be produced by the Nim compiler aren't there. An example of what this looks like: The missing files in this case are ones whose .c sources have

Is there a way to automatically find the path to nimbase.h when installed with choosenim?

2023-02-16 Thread exelotl
Another solution could be `$(shell dirname $(shell dirname $(shell which nim)))/lib` which I was using some years ago, but I think that only works if you have added Nim to your PATH manually. Maybe you can use it as a fallback somehow. Alternatively, you can still install a local Nim git repo w

Is there a way to automatically find the path to nimbase.h when installed with choosenim?

2023-02-16 Thread exelotl
I've previously had success with `choosenim show path`/lib/nimbase.h Or in a Makefile that would be `$(shell choosenim show path)/lib/nimbase.h`

Pass instance to other script

2023-02-15 Thread exelotl
If I'm understanding correctly, you are thinking that modules in Nim can be instantiated more than once? That's not how it works, there's only one instance of each module. If you import it twice, you get access to the same copies of the same variables. e.g. # a.nim var n = 0

Nim vs the 6 languages I learned before it

2023-02-13 Thread exelotl
> I'd take a hack if there was one. Templates don't introduce a new scope by default. (but they're hygienic, so any variables introduced inside the body of the template itself won't conflict with ones outside, but that doesn't apply to a block that you passed _to_ the template). So you could d

Why vtable implementaion is not better than subtype checking implementation?

2023-02-08 Thread exelotl
This is awesome! Asides from the old dispatch trees being too slow, the main reason I can't use methods on embedded platforms is because the RTTI eats up too much RAM. If the RTTI and the vTable were generated as `const` in the C code then this wouldn't be a problem. Is that something that cou

Twisting Nim's arm to generate loop #pragmas .

2023-01-31 Thread exelotl
Using {.emit.} seems dodgy... Nim's `for` loops produce gotos instead of C `for` loops. So you can't just emit the pragma, you'd have to emit the whole `for` loop. You could emit a C for loop like so: template cfor*(x: untyped; a, b: int; body: untyped) = var `x` {.inject, no

Official Fediverse (e.g. Mastodon) account?

2023-01-08 Thread exelotl
> None of the fediverse frontends are nearly as good. I have to disagree here. If you want something lightweight, Pinafore is excellent. Tusky is great on Android. Even the regular Mastodon frontend is miles better than Twitter, it doesn't track you or pester you to sign in (as is the main bene

How to further speed up the build of your Nim's projects (using ccache)

2022-12-26 Thread exelotl
This sounds interesting, is it possible to tell the Nim compiler to use a copy of stdlib residing in `/tmp` for example? If so, how?

Nim version 2.0 RC1

2022-12-21 Thread exelotl
Everything seems to be working fine for me!

Fine control over the ordering of linker args?

2022-12-15 Thread exelotl
Thanks so much for your help! This has been really useful if only to know what my options are. > I doubt that they really need to be linked in order, since it is probably > just name resolution of symbols Yes you're right, it seems that the order shown in the example is simply best practise an

Fine control over the ordering of linker args?

2022-12-13 Thread exelotl
Hi, I'm trying to use Nim with a toolchain whose docs say I should use a command like below to link the final application: clang -nostartfiles -Wl,--gc-sections -Wl,-pie -Wl,--start-group /path/to/crt.o -Wl,--end-group -Wl,--sta

Forum subscription feature

2022-12-04 Thread exelotl
I've probably said some of this before but: * I like the Nim forums, they're simple and run well even on underpowered devices. * There is room for improvement, but I don't think that means they should be replaced... they handle the 90% case pretty well. * I dislike the fact that the forums

Are OpenArrays memory safe?

2022-11-20 Thread exelotl
They are just pointer,size but the semantics of the language are such that they're memory safe. * In Nim 1.x without the --experimental:views option, openArrays are only usable as parameters. You cannot hold onto an openArray, therefore it cannot outlive the array/sequence whose data it refer

Nim 1.6.10 release candidate

2022-11-03 Thread exelotl
Tried it with my codebase, no issues encountered so far!

How to import a C array of unknown size?

2022-10-31 Thread exelotl
With the corresponding `{.emit.}` pragma to declare the extern variables I think this would work. I'm just curious if there's something that doesn't rely on backend details.

How to import a C array of unknown size?

2022-10-31 Thread exelotl
> Generally its better to think of the array in C as a pointer with some extra > syntax. But that's how I got into this mess! Look: // main.c #include char my_data[] = "Hello world!"; extern char *foo(); extern char *bar(); int main() {

How to import a C array of unknown size?

2022-10-30 Thread exelotl
Yes `ptr UncheckedArray` is usually correct, but not in this case. it leads to the following codegen: extern NIM_CHAR* __HEAP_START__; extern NIM_CHAR* __HEAP_END__; Run which does not exhibit the same behaviour as the desired codegen: extern NIM_CHAR

How to import a C array of unknown size?

2022-10-30 Thread exelotl
In my codebase I'm trying to ensure that nobody tries to free something that's on the heap. There are two symbols defined by the linker script which can be imported and used like so in C: extern char __HEAP_START__[]; extern char __HEAP_END__[]; // ... uintptr

Tips on how to avoid Nim pointer instability bugs?

2022-10-28 Thread exelotl
Are there existing issues on github to keep track of these cases? You should definitely create them if not.

Tips on how to avoid Nim pointer instability bugs?

2022-10-25 Thread exelotl
Keep in mind that the "unsafe" features of the language are: `ptr`, `addr` and `cast` (plus certain pragmas such as {.noinit.}, {.cursor.}, {.union.}, {.checks:off.}, etc.). And of course, interfacing with C libraries, and other _" I know what I'm doing"_ things such as explicitly calling GC_ref

How do I turn binary file data into hex representation

2022-10-15 Thread exelotl
You'll have to show us an example (code, input, output, screenshots) as it's not entirely clear what you're asking.

Slow compilation time in a big project. What branch contains Incremental Compilation?

2022-09-09 Thread exelotl
Honestly I'm in the same boat. I'm using Nim at work every day and the 30+ second build times for my project are a real drag (especially when working on UI and cutscenes, it's always _" move sprite by 1 pixel, recompile... oh looks like I need to move it down by 1 pixel too, recompile... maybe t

how can I buy "Mastering Nim" without using amazon services?

2022-09-08 Thread exelotl
Hope you get to figure something out eventually, I have a strong distaste for Amazon but I'd also like to buy it as soon as it's available elsewhere.

Alternative to gravatar for the forums?

2022-08-16 Thread exelotl
+1 for removing Google Analytics and implementing open alternatives to gravatar, recaptcha and anything else that's within reach. I have to stick up for the Nim IRC bridge. I'm on a few Discords with IRC bridges, and Nim's is by far the best, having decent support for edits, replies and code pa

Nim v2: what would you change?

2022-08-10 Thread exelotl
`div` is fine, it goes with all the other keyword-ops for integer types. Personally I'd rather just shorten `tdiv` to `dv` in the relevant libraries, as then it becomes a mnemonic rather than just a stick-out prefixed symbol.

string of compressed source code

2022-08-06 Thread exelotl
well, I thought it was a neat concept but I actually don't think it's necessary. It seems like you can just straight up put invalid unicode in a string literal. const s = """ ��� """ echo s Run works for me. I filled out the string with F.

string of compressed source code

2022-08-06 Thread exelotl
If you need it to be in 1 file, maybe you could try something like this? #[ testing, put your dirty unprintable string here ]# const s = staticRead("main.nim")[3..49] echo s Run Output: testing, put your dirty unprintable string h

string of compressed source code

2022-08-01 Thread exelotl
if it's not valid unicode, your best bet is to store it in a separate file and use `staticRead` to load it into a string at compile-time. const s = staticRead("myfile.bin") load(s) Run

Nim Wiki disabled contributions

2022-08-01 Thread exelotl
I'm not sure how/when it'll be resolved, but I remember it was disabled due to a phishing attempt, see here for more info:

Implement api rate limiting with jester

2022-07-23 Thread exelotl
iirc what you're after is what many web frameworks call "middleware", which is not something that Jester has. However, there's [a fork](https://github.com/JohnAD/jesterwithplugins) from a couple of years ago which adds it. It was [covered in NimConf 2020](https://www.youtube.com/watch?v=BYv1QfJ

How to compute a set[enum] with all possible values?

2022-07-23 Thread exelotl
Yep, there's [fullSet](https://nim-lang.org/docs/setutils.html#fullSet%2Ctypedesc%5BT%5D) which beef added in `std/setutils`, which works with holey enums.

Cursed: Working braces in Nim

2022-06-09 Thread exelotl
Thanks, I hate it!

Small improvement discussion: Use `let` to lock variable previously declared as `var`

2022-05-31 Thread exelotl
This issue doesn't really bother me, I just use `let x = block:` if I want to compute-then-freeze a variable. But I do have a similar issue which I wish I could solve: proc update(self: ptr Entity) = self.doStuff() if self.health <= 0.0: destroyEntity(self

Nim v2: what would you change?

2022-05-07 Thread exelotl
@Zoom > Well, with an option/result you can always drop ("unwrap") it. This is cool > because now ignoring a possible error becomes explicit. Yep, of course there is a lot of merit to that, but it's less convenient as it infects the return type of everything that wants to pass on the error. Tha

Nim v2: what would you change?

2022-05-06 Thread exelotl
> All try/catch based systems always develop an "uncaught exception" at some > point in their lifetime, because an underlying library added a new exception > of some kind. Isn't this what the effects system is for? You can stick `{.raises: [].}` on your main proc and be confident that no pesky

Fidgets!

2022-05-04 Thread exelotl
The meta choice would be to call it fidgety :P

Nim v2: what would you change?

2022-05-02 Thread exelotl
This already exists (see `--include` and `--import` in the [compiler user guide](https://nim-lang.org/docs/nimc.html) \- you can add them to the `nim.cfg` or `config.nims` for your project.)

Nim v2: what would you change?

2022-05-01 Thread exelotl
I especially agree with Yardanico, Zoom and kobi. * Refactor the compiler, pull out docgen, remove legacy flags, etc. * Default `not nil` \- this eliminates `Option`'s speed vs correctness [conundrum](https://github.com/nim-lang/Nim/pull/18401). * Finish view types and other half-done featu

metatag - an audio metadata library

2022-04-18 Thread exelotl
This seems really useful! If you're looking to reduce the number of shared lib dependencies, I can recommend [zippy](https://github.com/guzba/zippy) as a pure-nim replacement for zlib :)

Seeking advices for a C programming book

2022-04-17 Thread exelotl
Regarding C being not particularly low level, I remember this being a good read: [C Is Not a Low-level Language](https://queue.acm.org/detail.cfm?id=3212479)

Nim 1.6.6 release candidate

2022-04-15 Thread exelotl
Seems to be working fine for me!

Do name the array element

2022-04-14 Thread exelotl
You can use an `enum` type as the index for the array: type Alignment = enum Left Middle Right var a: array[Alignment, int] a[Left] = 7 a[Middle] = 8 a[Right] = 9 # this is also supported: const b = [ Left: 7, M

System.sink & System.lent

2022-04-07 Thread exelotl
For me it comes down to the "use the least powerful tool for the job" mantra (especially when writing code that might be used by other people) - procs are simpler and more constrained in what they can do. When they contain errors or are used wrongly they will often fail earlier in the compilatio

runnableExample considered harmful / good feature to deprecate before 1.0?

2022-04-06 Thread exelotl
Personally I think runnableExamples make Nim harder to learn for newcomers. When viewing docs I would much rather read: > **Example:** > > > echo some(42).get # prints 42 > echo none(string).get # error! raises UnpackDefect > > Run instead of: > **Example:** >

System.sink & System.lent

2022-04-06 Thread exelotl
I can at least explain the `{.inline.}` pragma: Say I have two Nim files: # foo.nim import bar proc getNum*(): int = add(10, 20) Run # bar.nim proc add*(a, b: int): int = a + b Run Each `.nim` file is compil

Automatic dereferencing for procs

2022-03-29 Thread exelotl
I asked about implicitDeref [a while back](https://forum.nim-lang.org/t/6500). The verdict was: it seems like a nice feature but it doesn't jive well with others in its current form. For example a `var` parameter is supposed to never be `nil` but with implicitDeref it could be! And yeah, `ref s

how to make a enum with wrapped ordinals

2022-03-25 Thread exelotl
I think it _probably_ shouldn't be the default? Say there's a case where I don't want an enum to wrap, and I write some code that accidentally increments it beyond its maximum value. If it wraps by default, then I've just introduced silently buggy behaviour into my program, while a fatal error w

Using arc with C types?

2022-03-14 Thread exelotl
Ah that's perfect, all makes sense, thanks!

Using arc with C types?

2022-03-13 Thread exelotl
Say I have the following functions from a C library: type Foo = ptr object proc newFoo(): Foo {.importc.} proc freeFoo(f: Foo) {.importc.} Run I'd like to wrap these to create an idiomatic Nim API with `ref` types. type Bar = ref Ba

porting c++ [string]view demo to nim: a puzzle

2022-02-20 Thread exelotl
I'm not focusing on performance, but out of curiosity I've adapted your code to use Nim's own views. Sadly they're still not ready for prime-time yet, as we can see: * The stdlib is missing functions to work with them (we had to reimplement `find`) * The lifetime rules aren't up to scratch

Defer within async dispatch

2022-02-01 Thread exelotl
`newAsyncHttpClient` can't fail though, so I'm fairly certain you could do something like this: proc get_data*(): Future[string] {.async.} = let DOWNLOAD_API_URL = "some HTTP address" let client = newAsyncHttpClient() client.headers = newHttpHeaders({"Content-Type":

Defer within async dispatch

2022-02-01 Thread exelotl
Does it work if you put the `client.close()` in a `finally:` section at the end of the try..except? I've heard Araq say that `defer` is hard to maintain the past, so wouldn't be surprised if there are bugs with it - maybe it just doesn't work in closure iterators (the underlying mechanism used

NimForum 2.2.0 - Fixes a big CVE!

2022-01-30 Thread exelotl
Discourse is _really heavy_... I've never seen a Discourse forum that didn't make my phone chug while trying to navigate it. Meanwhile the Nim forums run perfectly fine. I don't care about shiny features, so as far as I'm concerned Discourse would be a downgrade. My only gripe with Nimforum is

nimscript - import configuration file

2022-01-19 Thread exelotl
constructs. # settings.nims fps = 30 fullscreen = false width = 800 height = 480 searchPath "." searchPath "C:/Users/exelotl/Pictures" searchPath "C:/Users/exelotl/Music" Run # config.nims

Evolving the moderation of the Nim communities

2021-11-19 Thread exelotl
@DIzer There are good reasons for the changes. For example, recently there have been instances of spam being posted to Discord via the Matrix bridge, and none of the mods online at the time had the tools necessary to deal with it since they weren't mods on Matrix. Given that context, I'm honest

Forbidden-by-default effects?

2021-11-15 Thread exelotl
Hey, I've recently been exploring the effect system as a way to stop people from calling coroutine-only functions outside of a coroutine. This _seems_ like a prime use-case for effects. # coro.nim type YieldEffect = ref object of RootEffect proc jield*() {.tags: [Y

include std/prelude vs import std/prelude (and other small prelude oddities)

2021-11-05 Thread exelotl
The disadvantage of `import`/`export` is that you lose the module names. For example you could do: include std/prelude echo times.fromUnix(0) Run But if it changed to `import common` you'd have to write this instead: import std/common ec

Trailing commas in "command" syntax?

2021-10-10 Thread exelotl
Hey! Currently in Nim the "command" syntax is one of the only cases in which trailing commas are not allowed. foo 10, 20, 30, # Error: invalid indentation Run I was wondering if this could be lifted in the future, or if there's a reason for it (di

Nim 1.6.0 RC2

2021-10-01 Thread exelotl
This approach works, I guess I'll use that for now: git clone https://github.com/nim-lang/Nim cd Nim git checkout 3c6001e ./build_all.sh choosenim . Run

Nim 1.6.0 RC2

2021-10-01 Thread exelotl
sources Building koch Exception: Execution failed with exit code 1 ... Command: ./bin/nim c koch ... Output: Hint: used config file '/home/exelotl/.choosenim/toolchains/nim-#3c6001e/config/nim.cfg' [Conf] ... Hint: used config file 'koch

Nim 1.6.0 RC2

2021-09-28 Thread exelotl
I tried updating via choosenim but it fails due to a invalid option when building koch: [exelotl@ringo ~]$ choosenim \#version-1-6 Downloading Nim version-1-6 from GitHub [##] 100.0% 0kb/s Extracting version-1-6.tar.gz

Nested concepts

2021-09-27 Thread exelotl
> I have not yet looked into this. Is there any documentation (or alike) > available yet? (Tried to find some ...) - Would really like to start using > these rather sooner than later. For now there's just the RFC on new-style concepts: And some tes

Goodboy Galaxy - Kickstarter and demo now live!

2021-09-25 Thread exelotl
Hey folks, I figured I'd bump this as it's the [final day](https://www.kickstarter.com/projects/penguinrik/goodboy-galaxy-exploration-platform-game-gba-pc-and-switch/posts/3311349) of the Kickstarter. We hit 1000% of our original funding goal, which feels unreal. I'm really hopeful we can reach

Goodboy Galaxy - Kickstarter and demo now live!

2021-08-30 Thread exelotl
Yes, it's a long way away but our current plan is to use Nim with SDL_gpu or similar. We'll make a basic 2D engine and then get to work on rewriting or editing each source file in the game (swapping out the draw calls, input handling, removing hardcoded constants such as the size of the screen,

Goodboy Galaxy - Kickstarter and demo now live!

2021-08-30 Thread exelotl
Thanks, that's really good to hear! ^^

Goodboy Galaxy - Kickstarter and demo now live!

2021-08-29 Thread exelotl
Sorry for the delay, I've had a lot on my plate! Our Nim GBA library is called [Natu](https://github.com/exelotl/natu), which includes bindings for various C/asm libraries such as: * [libtonc](https://github.com/devkitPro/libtonc) for interacting with the hardware and rendering

Goodboy Galaxy - Kickstarter and demo now live!

2021-08-27 Thread exelotl
Hi everyone! For the last 2 years I've been making a Game Boy Advance game in Nim with a friend on the weekends. Yesterday we launched a [Kickstarter](https://www.kickstarter.com/projects/penguinrik/goodboy-galaxy-exploration-platform-game-gba-pc-and-switch) campaign along with a [demo](https:

Can I jump to the definition of a proc or macros of a package when using IDE?

2021-08-06 Thread exelotl
Yep, though you're likely to find that nimsuggest chokes on large projects, so a lot of people end up turning it off in their editors eventually, once the pain outweighs the gain. :( Hopefully this will be fixed this year (if I understand correctly, nimsuggest improvements are on the roadmap, b

Serial string generation & generators

2021-08-05 Thread exelotl
Is the custom `->` syntax all you were looking for? I thought it was just for illustration 😅 A simple proc that generates the N th string in your sequence would look like this: import math proc foo(n: int): string = result = "" # Initial return

Idiomatic Nim code for 2D Poisson simulation

2021-07-09 Thread exelotl
I'm not familiar with the problem domain but you can use [var parameters](https://nim-lang.org/docs/manual.html#procedures-var-parameters) for that, if needed. proc poisson[N](a, b: var Matrix[N,N]): int = # ... # you can mutate a and b here # ... Run

Why does Nim compiler allways depends on another's language compiler?

2021-06-21 Thread exelotl
Compiling to C is a huge advantage to me (for reasons mentioned @treeform and @dom96 mentioned). It's one of the main reasons I chose this language over Go and others, when I was looking to learn a new compiled language for game development.

Nim on embedded systems

2021-06-21 Thread exelotl
Unfortunately it's impossible to do this without `emit` right now. I pushed for this kind of thing a couple of years ago, some progress was made on it (some basic types such as array of int may now be initialised statically) but it's still not really usable for many purposes - dispatch tables in

Nim on embedded systems

2021-06-16 Thread exelotl
It is possible to override the cflags/ldflags set by the global nim.cfg, using `arm.standalone.gcc.options.linker` and `arm.standalone.gcc.options.always` Here's an example of [how I do it for the GBA](https://github.com/exelotl/natu/blob/49cc2c04985339ed716c1d5d2832312db4f49eae/exa

How to solve type mismatch error ?

2021-05-17 Thread exelotl
It seems like you don't need to use cast for this, just regular [type conversion](https://nim-lang.github.io/Nim/manual.html#statements-and-expressions-type-conversions) would be fine. Nim will perform runtime checks on type conversions to make sure that you don't get overflow when converting b

Accessing {.emit.}'d variables across modules?

2021-04-19 Thread exelotl
I've settled on the following solution of using a helper module which emits the symbol to be importc'd (thanks to @clyybber for the idea!) # main.nim import mymodule echo foo # Works! import helper # Add helper to the build. Run

Accessing {.emit.}'d variables across modules?

2021-04-19 Thread exelotl
What would that look like? Is there a way to ensure different codegendecl output depending on whether the variable is being accessed in `mymodule.nim` or `main.nim`?

Accessing {.emit.}'d variables across modules?

2021-04-19 Thread exelotl
Here's a minimal example: # mymodule.nim {.emit:""" const char* foo = "Hello world!"; """.} var foo* {.importc.}: cstring Run # main.nim import mymodule echo foo

Release candidates for 1.4.6 and 1.2.12

2021-04-10 Thread exelotl
That... makes a lot more sense 😅 it's just the darn unescaped hash that tripped me up...

Release candidates for 1.4.6 and 1.2.12

2021-04-09 Thread exelotl
`choosenim #598d9f8` (exact commit hash) worked for me ^^

arm-none-eabi-gcc doesn't compile volatileStore

2021-04-04 Thread exelotl
Ah yep, I've run into this one before: <https://github.com/nim-lang/Nim/issues/14623> I ended up solving it like this (so yeah, changing them from templates to inline procs is probably the way to go): <https://github.com/exelotl/natu/blob/e65f107697420753fc8dc1d97383147e723398e3

auto declaration of function prototype

2021-03-23 Thread exelotl
The experimental [codeReordering](https://nim-lang.github.io/Nim/manual_experimental.html#code-reordering) feature is probably what you're looking for :)

how do I get a reference to a object

2021-03-19 Thread exelotl
I'm kind of envisaging that {.byaddr.} will go away once [views](https://nim-lang.org/docs/manual_experimental.html#view-types) become stable? e.g. you would be able to do: var a: var int = s[0] # mutable view let b: lent int = s[0] # immutable view a = 5 echo b

How to segment the code into different files?

2021-03-06 Thread exelotl
Hey! Yes, Nim has an `include` keyword which behaves much like in C or PHP. See: [include statement](https://nim-lang.org/docs/manual.html#modules-include-statement) So you could do this: import fastkiss import tables from strutils import `%` include "routes/func

How to allow out of bounds access on sized arrays?

2021-02-18 Thread exelotl
Hey! I ran into some trouble while cleaning up my wrapper of a C library for GBA development. One of the things that the library exposes is a 2D array which maps out several chunks of 512 tiles (a.k.a. charblocks) in video memory. type Tile* {.importc: "TILE4", header: "tonc.

Forwarding modules via `export`, and how to structure my library?

2021-02-15 Thread exelotl
Thinking about it more, I'm inclined to agree that the separate modules is something you can get used to. I will probably use that approach. However, the fact that the `tte` and `irq` modules are not "forwarding-friendly" is still an issue. For example, a developer might want to make a project-

Forwarding modules via `export`, and how to structure my library?

2021-02-14 Thread exelotl
Hi all! I'm trying to remove some prefixes from the names of procedures in my GBA library. Currently a "hello world" program looks like this: import natu irqInit() irqEnable(II_VBLANK) tteInitChr4cDefault(bgnr = 0, initBgCnt(cbb = 0, sbb = 31)) tteWrite("H

When to use IncompleteStruct pragma?

2020-12-01 Thread exelotl
Oh wow! {.completeStruct.} is quite useful for me, I had no idea we had that! I've wanted for a while to be able to make static assertions about the number of bytes taken up by arrays/objects containing types imported from C. I gave it a try and it works a treat, but I can't see it in the manual

is there a way to combine types?

2020-11-15 Thread exelotl
Note: a problem with solutions that copy the fields into the type, is that they don't let you use type `ABCombined` in a place where `A` or `B` is expected. This means you lose one of the main advantages of composition / inheritance. This is why I opted for a solution that keeps the sub types as

is there a way to combine types?

2020-11-15 Thread exelotl
Indeed, here's a macro I made to do this! <https://gist.github.com/exelotl/1f387c47468d02be4587044ed270c907> Example: type Vec2 = object x, y: float Player = object position: Vec2 compose Player, position var p: Player

  1   2   >