+1ts-soft wrote:I miss a feature to protect a function in module. Protected functions only available inside the module block.
And: I hope structures can be nested inside modules too, right?
+1ts-soft wrote:I miss a feature to protect a function in module. Protected functions only available inside the module block.
ts-soft wrote:I miss a feature to protect a function in module. Protected functions only available inside the module block.
Code: Select all
Module DirectX
Private state.l
Procedure New_OpenScreen(..)
SetState(1)
; ...
EndProcedure
Private Procedure SetState(_state)
state = _state
EndProcedure
EndModule
Module OpenGL
Private state.l
Procedure New_OpenScreen(..)
SetState(2)
; ...
EndProcedure
Private Procedure SetState(_state)
state = _state
EndProcedure
EndModule
OpenModule DirectX ; change to OpenGL to use another implementation
scr = New_OpenScreen(...)
SetState(...) ; error: Private function
state = 5 ; error: Private variable
CloseModule
I'm not sure.Danilo wrote: It's better than nothing!
Code: Select all
Module DirectX
Private Procedure SetState(_state)
...
...
ProcedureReturn result
EndProcedure
Procedure New_OpenScreen(..)
bla = SetState(1)
; ...
EndProcedure
EndModule
OpenModule DirectX ; change to OpenGL to use another implementation
scr = New_OpenScreen(...)
SetState(...) ; error: Private function
CloseModule
Good point! A module should definitely prefer its own functions over external ones.luis wrote: Then, if when you write your module you know it will need/depend from another module or library you call that beep with OTHERMOD::Beep() or ::Beep() if it's inside a userlib or if it's a PB command. But in this case you know you WANT to call something that's outside.
http://www.purebasic.fr/english/viewtop ... 15#p403131ts-soft wrote:I miss a feature to protect a function in module. Protected functions only available inside the module block.
I like your suggestion very much. Would be awesome if this private/public thingy would be implemented too!User_Russian wrote:http://www.purebasic.fr/english/viewtop ... 15#p403131ts-soft wrote:I miss a feature to protect a function in module. Protected functions only available inside the module block.
Code: Select all
; Here is my suggestion:
; - everything inside a module is "protected" by default. no extra "protected" keyword exists
; - "External" makes something visible on the outside
; - visible items can be accessed as <ModuleName>_<ItemName>
; - OpenModule makes them available without prefix
; - Things like EnableExplicit, EnableAsm, DisableDebugger or OpenModule
; should always be on their default state after a "Module", and be reset
; to what they were at OpenModule after a "EndModule"
;
; So a module is basically totaly separate from compilation outside in terms of naming
; and compiler behavior.
;
;
; As for overwriting names of PB functions: I think we should simply disallow it
; to avoid any possible confusion. The PB functions have very descriptive names (except math maybe),
; so i think it is no problem
;
; About the "all protected by default":
; If you want a list of globals like the IDE "Common.pb", just put that in a module too,
; then any module that wants to use it just has to do "OpenModule Common" and it is done.
; This way we have a good separation and still easy access.
;
; We could have an optional "AllExternal" kind of keyword to define a module where
; everything is externally visible for this purpose:
;
; Module Common AllExternal
; Global A ; no need for an extra "External" keyword
; EndModule
Module Crypto
Global Initialized
#InternalConstant = 128
External #ExternalConstant = 10
Procedure Cipher()
EndProcedure
External Procedure InitCrypto(info)
Initialized = 0
EndProcedure
External Procedure StartCrypto()
Cipher()
EndProcedure
EndModule
OpenModule Crypto
InitCrypto(#ExternalConstant)
StartCrypto()
CloseModule Crypto
Crypto_InitCrypto(#Crypto_ExternalConstant) ; this works also outside
; Example for separation of the explicit state etc:
EnableExplicit
Module Something
; here, EnableExplixit is off, until set otherwise
OpenModule SomethingElse
DisableDebugger
; ...
EndModule
; here, EnableExplicit is on again, the debugger is off and "SomethingElse" is not open
Code: Select all
Module Crypto
Module My
EndModule
EndModule
Code: Select all
package main
Code: Select all
package main
Code: Select all
package main
import "MyMod"
Code: Select all
package MyMod