Skip to content

Class header

Richard Baltrusch edited this page Mar 9, 2021 · 2 revisions

Class header

Bare header

The bare class header is specified as below:

call class %*
%class%

Header logic

The class keyword writes a macro-style variable called class to the batch environment, which implements the class header logic. In detail, the class variable executed in the class header runs the following code:

@echo off
call getobjptr %~1 self 1
call :public-%~2 %*
exit /b

Of note are specifically lines 2 and 3, which are used for pointer extraction and public method calls, respectively.

Pointer extraction

On line 2, we use the getobjptr keyword to extract the pointer from the specified object handle and store it in self. For example, if we have an object handle myHandle containing the pointer $123, we would store that value in the variable self in the following way:

if not defined self (
    set self=%myHandle%
)

Public method calls

After extracting the pointer from the object handle, we call the specified public method and pass all input arguments to it on line 3. For example, if we ran the following code, which calls the public class myMethod for an instance obj of type myClass:

call MyClass obj myMethod

the class header would search for a label public-myMethod in the class definition. This functionality is important for encapsulation.

Finally, the class header exits the class definition file after the specified method call.

More information

More information can be found in the home page, the quick start page and the examples.

Clone this wiki locally