faqts : Computers : Programming : Languages : Tse : Macro

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

33 of 33 people (100%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

TSE: Function/Procedure: Public: How create public procedure or function? [passing parameter]

Aug 15th, 2005 10:52
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 18 January 2004 - 11:53 pm --------------------

TSE: Function/Procedure: Public: How create public procedure or 
function? [passing parameter]

---

To make a procedure or function public, you have
to put the keyword

 public

in front of it.

---

Given that the macro containing that procedure
or function is then loaded,
you can then use that procedure or function
in another macro.

---

Steps: Overview:

 1. -Create 2 TSE macro files

     1. Open a file

         myfilename1.s

     2. Open a file

         myfilename2.s

 2. -In the first file 'myfilename1.s',
     fill in the code:

--- cut here: begin --------------------------------------------------

 public proc dosomething1()
  Warn( "Hello" )
 end

 proc main()
 end

--- cut here: end ----------------------------------------------------

 3. -Compile this first file (e.g. type <CTRL><F9>)

 4. -In the second file 'myfilename2.s',
     fill in the code:

--- cut here: begin --------------------------------------------------

 proc main()
  ExecMacro( "dosomething1" )
 end

--- cut here: end ----------------------------------------------------

 5. -Compile this second file (e.g. type <CTRL><F9>)

 6. -You should then see "Hello", because the procedure in the
     first macro is executed in the second macro.

 7. -It was the keyword 'public' which was responsible for this.

---
---

Note:

You will have to make sure that the macro containing this
public function is loaded. e.g. via LoadMacro(), or
ExecMacro(), e.g. in the example you could use:

 proc main()
  // LoadMacro( "myfilename1" )
  // - or -
  // ExecMacro( "myfilename1" )
  ExecMacro( "dosomething1" )
 end

===

Another example:

Passing procedure names as a parameter.

This will come handy if you create your own little languages
in TSE

 E.g. your own calculator with commands like
      'ADD', 'MULTIPLY', ...

 ---

 E.g. your own database engine with commands like
      'UPDATE', 'INSERT', 'DELETE', 'CREATE', ...

 ---

 E.g. your own graphics engine with commands like
      'DRAW', 'MOVE', 'DOT'

You thus input your own commands.

Pass the corresponding procedures as a parameter to a central
routine.

And implement this corresponding procedures as public procedures.

===

--- cut here: begin --------------------------------------------------

FORWARD PROC Main()
FORWARD PROC PROCCallProcedureAsParameter( STRING s1 )
FORWARD PUBLIC PROC PROCMyProcedureName1()
FORWARD PUBLIC PROC PROCMyProcedureName2()
FORWARD PUBLIC PROC PROCMyProcedureName3()

PROC Main()
 PROCCallProcedureAsParameter( "MyProcedureName1" )
 PROCCallProcedureAsParameter( "MyProcedureName2" )
 PROCCallProcedureAsParameter( "MyProcedureName3" )
END

PROC PROCCallProcedureAsParameter( STRING ProcedurenameS )
 STRING s[255] = "PROC" + ProcedurenameS
 ExecMacro( s )
END

PUBLIC PROC PROCMyProcedureName1()
 Warn( "this comes from PROCMyProcedurename1()" )
END

PUBLIC PROC PROCMyProcedureName2()
 Warn( "this comes from PROCMyProcedurename2()" )
END

PUBLIC PROC PROCMyProcedureName3()
 Warn( "this comes from PROCMyProcedurename3()" )
END

--- cut here: end ----------------------------------------------------

If you run this you will see respectively:

 this comes from PROCMyProcedurename1()

 this comes from PROCMyProcedurename2()

 this comes from PROCMyProcedurename3()

===

e.g. getting return values back

--- cut here: begin --------------------------------------------------

FORWARD PROC Main()
FORWARD PROC PROCCallProcedureAsParameter( STRING s1 )
FORWARD PUBLIC PROC PROCMyProcedureName1()
FORWARD PUBLIC PROC PROCMyProcedureName2()
FORWARD PUBLIC PROC PROCMyProcedureName3()

PROC Main()
 PROCCallProcedureAsParameter( "MyProcedureName1" )
 Warn( Query( MacroCmdLine ) )
 PROCCallProcedureAsParameter( "MyProcedureName2" )
 Warn( Query( MacroCmdLine ) )
 PROCCallProcedureAsParameter( "MyProcedureName3" )
 Warn( Query( MacroCmdLine ) )
END

PROC PROCCallProcedureAsParameter( STRING ProcedurenameS )
 STRING s[255] = "PROC" + ProcedurenameS
 ExecMacro( s )
END

PUBLIC PROC PROCMyProcedureName1()
 Warn( "this comes from PROCMyProcedurename1()" )
 Set( MacroCmdLine, "return_value1" )
END

PUBLIC PROC PROCMyProcedureName2()
 Warn( "this comes from PROCMyProcedurename2()" )
 Set( MacroCmdLine, "return_value2" )
END

PUBLIC PROC PROCMyProcedureName3()
 Warn( "this comes from PROCMyProcedurename3()" )
 Set( MacroCmdLine, "return_value3" )
END

--- cut here: end ----------------------------------------------------

If you run this you will see respectively:

 this comes from PROCMyProcedurename1()
 return_value1

 this comes from PROCMyProcedurename2()
 return_value2

 this comes from PROCMyProcedurename3()
 return_value3

===

e.g. setting parameters and getting return values

--- cut here: begin --------------------------------------------------

FORWARD PROC Main()
FORWARD PROC PROCCallProcedureAsParameter( STRING s1 )
FORWARD PUBLIC PROC PROCMyProcedureName1()
FORWARD PUBLIC PROC PROCMyProcedureName2()
FORWARD PUBLIC PROC PROCMyProcedureName3()

PROC Main()
 //
 PROCCallProcedureAsParameter( "MyProcedureName1 
parameterinput_value1" )
 Warn( Query( MacroCmdLine ) )
 //
 PROCCallProcedureAsParameter( "MyProcedureName2 
parameterinput_value2" )
 Warn( Query( MacroCmdLine ) )
 //
 PROCCallProcedureAsParameter( "MyProcedureName3 
parameterinput_value3" )
 Warn( Query( MacroCmdLine ) )
END

PROC PROCCallProcedureAsParameter( STRING ProcedurenameS )
 STRING s[255] = "PROC" + ProcedurenameS
 ExecMacro( s )
END

PUBLIC PROC PROCMyProcedureName1()
 Warn( "this is an input parameter1" + " " + Query( MacroCmdLine ) )
 Warn( "this comes from PROCMyProcedurename1()" )
 Set( MacroCmdLine, "return_value1" )
END

PUBLIC PROC PROCMyProcedureName2()
 Warn( "this is an input parameter2" + " " + Query( MacroCmdLine ) )
 Warn( "this comes from PROCMyProcedurename2()" )
 Set( MacroCmdLine, "return_value2" )
END

PUBLIC PROC PROCMyProcedureName3()
 Warn( "this is an input parameter3" + " " + Query( MacroCmdLine ) )
 Warn( "this comes from PROCMyProcedurename3()" )
 Set( MacroCmdLine, "return_value3" )
END

--- cut here: end ----------------------------------------------------

If you run this you will see respectively:

 this is an input parameter1 parameterinput_value1
 this comes from PROCMyProcedurename1()
 return_value1

 this is an input parameter1 parameterinput_value2
 this comes from PROCMyProcedurename2()
 return_value2

 this is an input parameter1 parameterinput_value3
 this comes from PROCMyProcedurename3()
 return_value3

---
---

Internet: see also:

---


----------------------------------------------------------------------