Hello,

> could anyone please tell me in a simple language what does .closure. means 
> and how it affected with .nimcall. ?

Sure thing !

Here is a [link](https://nim-lang.org/docs/manual.html#types-procedural-type) 
the part of the language manual that talks about this topic.

In case you could not understand, here is another explanation.

  * A `nimcall` procedure is a procedure that can only references entities 
declared at module scope or in its own scope.
  * A `closure` can additionnally reference dynamic entities declared in 
enclosing scopes, typically, parameters and local variables from the enclosing 
procedure.



This difference will result in 2 different procedure types in Nim, which 
translates to 2 different calling conventions.

By default:

  * A procedure declared at module scope will have the `nimcall` convention.
  * A procedure type involved in another type definition, like in your `Scene` 
object, will have the `closure` convention.



Now, I think the error you got is due to the compiler not converting the pair 
of `nimcall` procs to closures. So if you want to keep things by default, you 
can use anonymous procedures like so : 
    
    
    import actors
    {.experimental: "codeReordering".}
    
    app.settings.name = "Platypus"
    app.settings.screen_size = (1920,1080)
    app.scenes = newSeq[Scene](1)
    app.scenes[0].callback = (proc () {.closure.} = start(), proc () 
{.closure.} = update())
    
    run()
    
    proc start()=
      discard
    
    proc update()=
      discard
    
    
    Run

Unfortunately, this fails to compile when the `{.closure.}` pragmas are 
removed. It could be a bug in the compiler not knowing how to adapt a tuple of 
procedures to a target proc type.

Anyway, I hope this helps you.

Reply via email to