Modules

Mac OSX specific forum
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Modules

Post by fsw »

Fred,
was browsing through the help file to see if it's updated for 5.2 and saw that there is a:
PureBasic - Module
section, but it talks about music modules.
(never used it myself...)

IMHO either the "music module" or the "new module" needs to be renamed.

Don't you think?

Otherwise we will have:
DeclareModule
EndDeclareModule
Module
EndModule
UseModule
UnuseModule
CatchModule
FreeModule
GetModulePosition
GetModuleRow
IsModule
LoadModule
ModuleVolume
PlayModule
SetModulePosition
StopModule
Especially FreeModule or LoadModule might be used for the wrong thing.
Last edited by fsw on Sat Jun 29, 2013 12:49 am, edited 1 time in total.

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Modules

Post by luis »

Good catch :)
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Modules

Post by fsw »

Go[lang] uses "package".

In PureBasic terms it would be:

Code: Select all

DeclarePackage
EndDeclarePackage
Package
EndPackage
UsePackage
UnusePackage
Speaking of package, in go[lang] each package is in one or more files.
Each file starts with:

Code: Select all

package myStuff
but there is no endpackage needed.

Actually each go file starts with package; if it's a normal app the package name is [mandatory]:

Code: Select all

package main
The nice thing about it is that each file tells you to which package it belongs.

Only main packages are [automatically] compiled to executables.
Non main packages are [automatically] compiled to static libraries

Ah, [programming] life can be so easy :mrgreen:

I am to provide the public with beneficial shocks.
Alfred Hitshock
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Modules

Post by Little John »

fsw wrote:The only "trouble" I had so far is that macros need to stay outside of module declarations.
(otherwise my example app crashes after start...)
Could you post a short snippet that demonstrates the issue?
There was a problem with Modules and Macros in PB 5.20 beta 2, which has been fixed in beta 3.
Is this the same problem which you encountered?
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Modules

Post by fsw »

Sorry Little John, I totally missed your question.
It was my own stupidity :oops:

While changing the code to use the new Module function I moved the macro to the top of the code (even before other include files are called).
The procedure that I was calling inside the macro was calling itself internally (because of the active macro) and a stack overflow was happening.

There are two solutions for this:
1) Call UndefineMacro inside the procedure; do my thing; and then redefine it again
2) Move the macro to the bottom of the code

I went with the second solution.

Sorry for the confusion.

I am to provide the public with beneficial shocks.
Alfred Hitshock
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Modules

Post by Little John »

No worries!
I'm glad that the problem is solved. :-)
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Modules

Post by WilliamL »

I think I'm getting the idea.

I'd like to see the Help file updated with Module commands and explanations.

I see the Module commands in 'Folding' but Module commands are not added to 'Indentation' (they can be added to Indentation and work fine).
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Modules

Post by Michael Vogel »

freak wrote:[...] There is no risk of things like global variables or procedure names conflicting with other code parts.[...]
Not sure to understand the module concept fully and have no time for playing around for the next four weeks or so, but I read some postings and TI-994A brought an example which seems to show a conflict for me:

Code: Select all

#constant1 = "Hello"
Define a.f = 1.23

Procedure test()
  Debug #constant1 + " World!"
EndProcedure

DeclareModule myModule
  #constant1 = 100
  Define a.i = 1 
EndDeclareModule

Module myModule
  #constant2 = 200
  a = 2
 
  Procedure test(param)
    ProcedureReturn param + #constant1
  EndProcedure
EndModule

UseModule myModule           ;raises error
  Debug #constant1
  Debug a
  Debug test(22)
UnuseModule myModule
As I understood it, the compiler can't decide, if a is a global variable or from myModule and so on, are am right?

If UseModule works similar to With*, will Debug ::a work instead of Debug a ?

____
*) Structure aStru
a.i
b.i
EndStructure

a.astru
a\b=222
b=2

With a
Debug b
Debug \b
EndWith
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Modules

Post by TI-994A »

Michael Vogel wrote:
freak wrote:[...] There is no risk of things like global variables or procedure names conflicting with other code parts.[...]
As I understood it, the compiler can't decide, if a is a global variable or from myModule and so on, are am right?

If UseModule works similar to With*, will Debug ::a work instead of Debug a ?
Hello Michael Vogel. Your snippet had a number of name conflicts, and a missing module procedure. And once the UseModule directive is used, the double colons aren't required, although it can still be used with the full module name if desired, like this:

Code: Select all

DeclareModule myModule
  a = 123
EndDeclareModule

UseModule myModule
Debug a
Debug myModule::a
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply