module question
module question
Can you call a module from within a module? I tried to do that and got an error "Module not found (and the details)". I can call from the main without problem. Or am I doing something wrong?
Re: module question
RSrole wrote: Sat Jun 15, 2024 10:22 pm Can you call a module from within a module? I tried to do that and got an error "Module not found (and the details)". I can call from the main without problem. Or am I doing something wrong?
Code: Select all
DeclareModule mod1
Declare func1()
EndDeclareModule
Module mod1
Procedure func1()
Debug "mod1::Func1()"
EndProcedure
EndModule
DeclareModule mod2
Declare func1()
EndDeclareModule
Module mod2
Procedure func1()
mod1::func1()
EndProcedure
EndModule
mod2::func1()
Re: module question
Thanks, so I'm doing something wrong.
Re: module question
I see, it cares about the order in the source code Mod2 can only call Mod1 because it follows Mod2. Mod1 can't call mod2
Re: module question
Is the module you're trying to invoke a method from declared prior to the caller module? E.g., in @jassing's example, mod2 may access mod1, but not the other way around due to how they're declared.
If both modules happen to be interdependent (which IMO is less than ideal), you may declare both prior to their implementations, e.g.:
Code: Select all
DeclareModule mod1
Declare func1()
EndDeclareModule
DeclareModule mod2
Declare func1()
EndDeclareModule
Module mod1
Procedure func1()
Debug "mod1::Func1()"
EndProcedure
mod2::func1()
EndModule
Module mod2
Procedure func1()
mod1::func1()
EndProcedure
EndModule
-
- Addict
- Posts: 4770
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: module question
By the way, this problem is not specific to modules, but affects procedures outside of modules as well, because PureBasic is a single-pass compiler.
Re: module question
Yes this makes sense and thanks. It didn't occur to me to just put the DeclareModules in my Declares.pbi. That does solve it.
Thanks
Thanks