Re: Can I cast[pointer]( proc() {.closure.} ) ?

2019-11-21 Thread javinyang
Thank you very much. Yes, I need to call this function from C. For example, I need to add a callback function to the button of the UI system. The UI system is a c library. I will first store the pointers to rawProc and rawEnv and release them when they are not needed.

How to cast[proc() {.closure, gcsafe, locks: 0.}](pointer)()?

2019-11-21 Thread javinyang
` import system proc testCallback(arg: int): proc() {.closure, gcsafe, locks: 0.} = result = proc() {.closure, gcsafe, locks: 0.} = echo "res", arg var p1 = testCallback(5) var p1Pointer = system.rawProc(p1) # How to cast back cast[proc() {.closure, gcsafe, locks: 0.}](p1Pointer)() ` Run

Can proc/method name be used as parameter

2019-11-20 Thread javinyang
Obviously the following is wrong: proc testCallback[T](callback: proc(this: T) {.closure, gcsafe, locks: 0.}) = callback() type TestType = object discard proc helloNim(this: TestType) = echo "Hello, Nim!" proc testProc(this: TestType) = testCall

Re: Can I cast[pointer]( proc() {.closure.} ) ?

2019-11-20 Thread javinyang
import system proc testCallback(arg: int): proc() {.closure, gcsafe, locks: 0.} = result = proc() {.closure, gcsafe, locks: 0.} = echo "res", arg var p1 = testCallback(5) var p1Pointer = system.rawProc(po1) Run ?? How to cast back `cast[proc() {.

Re: Can I cast[pointer]( proc() {.closure.} ) ?

2019-11-20 Thread javinyang
import system proc testCallback(arg: int): proc() {.closure, gcsafe, locks: 0.} = result = proc() {.closure, gcsafe, locks: 0.} = echo "res", arg var p1 = testCallback(5) var p1Pointer = system.rawProc(po1) ?? How to cast back cast[proc() {.closure, gcsafe, locks: 0.}](p1Pointer)()

Can I cast[pointer]( proc() {.closure.} ) ?

2019-11-20 Thread javinyang
I don't understand why I can't cast proc(){.closure.} to pointer. but I can cast proc(){.nimcall.} to pointer ?

Re: It seems a bit confusing to express the current class object with the first argument.

2019-11-14 Thread javinyang
Yes, I use multiple operating systems, I am fed up with the free-standing procedure of the c language, but I have to do this (although I can also write oop-like code, but it is a chicken rib in c). but in nim can reflect oop-like, such as the existence of inheritance. But for a lot of reasons,

Re: It seems a bit confusing to express the current class object with the first argument.

2019-11-13 Thread javinyang
type T0 = object T1 = object T = object O = object converter (this: any) toT (): T = discard proc (this: T0) p (): O = discard proc (this: T0) p (that:T1): O = discard proc (this: T0) p (that:T1, rest:varargs[T, toT]): O = discard proc (that :T1) p (this:T0): O = discard Cann't nim be desig

It seems a bit confusing to express the current class object with the first argument.

2019-11-13 Thread javinyang
I am translating my go code into nim, which looks a bit messy compared to go. It's clearer to put the current class object before the name, **_proc (this: MyType) named (arg1: int)._** Why are class objects and parameters written in the same brackets in NIM? nim: ... #edi

Why does nim put the Export marker on the right side?

2019-11-07 Thread javinyang
type MyType* = ref object a*: int32 b*: int32 c*: int32 proc myProc*() = discard Run I don't understand why it is placed on the right side. Is there any reason for this design? Feel good on the left side. type *MyType

Can themutually recursive types be written separately?

2019-11-06 Thread javinyang
in nim manual Type sections A type section begins with the type keyword. It contains multiple type definitions. A type definition binds a type to a name. Type definitions can be recursive or even mutually recursive. Mutually recursive types are only possible within a single type section. Nominal

Re: How to privatize the proc of the inherited parent object?

2019-10-29 Thread javinyang
The premise of not using this way is that the type is perfect design from the beginning , but not all type can be designed perfectly from the very beginning.

Re: How to privatize the proc of the inherited parent object?

2019-10-28 Thread javinyang
Not even with method

How to privatize the proc of the inherited parent object?

2019-10-27 Thread javinyang
In c++ class Preant { public: void call() { } }; class Child : public Preant { private: void call(); }; Run In nim type Preant* = ref object of RootObj proc call*(this: Preant)