simple event system

2022-01-09 Thread enthus1ast
This can unfortunately just bind one event type. That's the reason i used pointers in the first place. But i like the macros.

What's the proper idiom?

2022-01-09 Thread ynfle
This is what I was suggesting

What's the proper idiom?

2022-01-09 Thread cantanima
Thank you! Would this be acceptably idiomatic? I believe it would be more convenient to my use case. func init*(_: typedesc[T], kind: E, value: int = 0, estimate: float = 0.0) : T = ( case kind of first: T( kind: first, a: value ) of second: T( kind: second, b:

simple event system

2022-01-09 Thread jyapayne
@enthus1ast, why not something using Nim's generics? Is there a reason you wanted to use pointers? For example, you could do something like this (made a little better with macros): import tables import macros type Callback[T] = proc (arg: T) Signal[T] = ref

What's the proper idiom?

2022-01-09 Thread ElegantBeef
Here is how one might make it more idiomatic type E* = enum first second T* = object case kind: E of first: a: int of second: b: float func a*(t: T): int = t.a func init*(_: typedesc[T], a: int): T = T(kind: first, a

What's the proper idiom?

2022-01-09 Thread cantanima
> Can you share your code? I did not get the same result Is this in reply to my erroneous reply, the one I edited out of existence? If so, please ignore it. > What is wrong with a constructor? Let me make sure I know what you mean. You don't mean this (my inference from experience w/OO program

What's the proper idiom?

2022-01-09 Thread cantanima
It seems that proc `a=`*(t: T, value: int) = discard Run prevents `a` from being assigned, but it doesn't raise a compile-time error, which is what I want. I guess it's time to dive into Nim's macro system, unless someone has a better idea.

What's the proper idiom?

2022-01-09 Thread ynfle
Can you share your code? I did not get the same result

What's the proper idiom?

2022-01-09 Thread ynfle
What is wrong with a constructor?

What's the proper idiom?

2022-01-09 Thread ynfle
I don't think so

What's the proper idiom?

2022-01-09 Thread cantanima
Thanks. I had a typo, and may have been editing my post while you were replying, so if anyone reads this and wants to know why ynfle wrote `first` instead of `a`, it's my fault. I still have the question about objection creation, though. Is there some way to decorate the type so that I can crea

What's the proper idiom?

2022-01-09 Thread ynfle
You can use a proc `first` that could be called as `instanceOfT.first` to access the field. Beware of templates though!

What's the proper idiom?

2022-01-09 Thread cantanima
I have an type whose fields I want to keep immutable outside the module. In addition, the type is discriminated by an enum. type E* = enum first, second type T* = object case kind: E of first: a: int of second: b: float Run Sometimes I need to

Changing a generic return type automatically

2022-01-09 Thread Ethernaut
Thanks, those options are better than what I had! But now that I think about it, I definitely need some way to decide what to return at runtime. I mean, I don't **_need_** it, but it would be nice to have, and less prone to mistakes since it would be automated. Is there a mechanism to achieve t

simple event system

2022-01-09 Thread coffeepot
@planetis > At least in my experience I used simple empty components as 'Tags' that > notify the next system of changes. They can be added and removed very > efficiently. In general, I agree with this. In many cases using components as "events" works better than explicit events because they ca

One Language to Rule the Mole

2022-01-09 Thread xigoi
Thinking about it, the Nim mole should have crooked teeth… because it didn't wear _braces_.

One Language to Rule the Mole

2022-01-09 Thread moigagoo
Oof, Krtek brings back dark childhood memories đŸ˜‚ I know it has a special place in a lot of people's hearts, but I'm happy we can't use it for Nim due to copyright issues :-)

One Language to Rule the Mole

2022-01-09 Thread pietroppeter
having finished my share of NYT articles for the month, I went to read about Krtek in wikipedia: ) very nice!

One Language to Rule the Mole

2022-01-09 Thread xigoi
As a Czech, I approve of this mole. I watched many animated movies with him as a child.

Is it correct to return var after casting an address

2022-01-09 Thread planetis
For the record my code was totally wrong, the correct one is `cast[ptr UncheckedArray[Vector3]](Mesh(x).normals)[i]`

Changing a generic return type automatically

2022-01-09 Thread Araq
If the decision only needs to be done at compile-time, you might as well simply use overloading.

Changing a generic return type automatically

2022-01-09 Thread Vindaar
Choosing a return type based on an int or enum value, make it seem like you want to decide at _runtime_ what type is being returned. That won't work without an additional argument (e.g. your `typedesc`), in which case the `case` doesn't really serve a purpose, as (at least in theory) each case w

One Language to Rule the Mole

2022-01-09 Thread oyster
yes, go's mole(?) is really ugly. I like this one you can read more about this mole at