Named Macro Variables

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Named Macro Variables

Post by helpy »

Hi Fred and other developers,

It would be helpful to have a sort of named macro variables, where some information could be stored, which could be used in other macros:
Syntax:

SetMacroVariable(VarName,Value) ... sets the macro variable "VarName"
GetMacroVariable(VarName) ... will be replaced by Value of "VarName"
Example:

Code: Select all

;====================================================
Structure __CLASS__OBJ_BASE
  *VTable
  *ObjectData
EndStructure

;====================================================
Macro IClass(ClassName)
  __#ClassName#__CLASS_INTERFACE
EndMacro

Macro OClass(ClassName)
  __#ClassName#__CLASS_OBJECT
EndMacro

Macro Class(ClassName)
  SetMacroVariable(ActualClass,ClassName)
  Interface IClass(ClassName) 
EndMacro

Macro EndClass
  EndInterface
  Structure OClass(GetMacroVariable(ActualClass)) Extends __CLASS__OBJ_BASE
    Functions.l[SizeOf(IClass(GetMacroVariable(ActualClass)))/4]
  EndStructure
EndMacro

Macro ExtendClass(ClassName)
  Extends IClass(ClassName)
  SetMacroVariable(ExtendClass,ClassName)
EndMacro

;====================================================
Class(CLASS_1)
  function1()
  function2(arg1,arg2)
EndClass

Class(CLASS_2) ExtendClass(CLASS_1)
  function4()
  function5(arg1,arg2)
  function6(arg1)
EndClass
At the moment I have to pass the actual class name with each macro:

Code: Select all

Class(CLASS_1)
  function1()
  function2(arg1,arg2)
EndClass(CLASS_1)

Class(CLASS_2) ExtendClass(CLASS_1)
  function4()
  function5(arg1,arg2)
  function6(arg1)
EndClass(CLASS_2)
This is only a LITTLE example of the usage of named macro variables.

What do you think about this idea?

cu, helpy