#===================================================================================================
# Example Script: Return and Exit Statements
# Demonstrates the use of 'return' statement for a number of different data types and with
# normal and compiler methods. Also uses 'exit 0' to terminate the script with success.
#===================================================================================================
# Method reference data type used for a method that takes an integer arg and returns a string.
type<string method<int>> MethodRefTakesIntAndReturnsString
# Global variable used for primitive reference in compile-time logic.
data<float> compiler MyGlobalCompilerFloat = 87.65
# Call the compiler method to dump out return values from compiler methods.
DumpMethodReturns()
#----------------------------------------------------------------------------
# Some example compiler methods returning various data types. Note that the
# data type in the 'method<>' keyword must match data type in 'return'.
#----------------------------------------------------------------------------
method<int> compiler CompilerGetInt()
{
return(CompilerRandomInt(1,50))
}
method<string> compiler CompilerGetString()
{
data<string> MyString
MyString = CompilerStrPad(' Aztec Compiler String ',60,'-',string.PadCenter)
return(MyString)
}
method<float ref> compiler CompilerGetFloatRef()
{
data<float ref> MyFloatRef = @MyGlobalCompilerFloat
return(@MyFloatRef)
}
# Method to access the above methods and dump out the return values.
method compiler DumpMethodReturns()
{
data<int> MyInt
data<float ref> MyFloatRef
data<string> MyString
MyInt = CompilerGetInt()
CompilerWriteLog("Return integer value from compiler method is " + CompilerIntStr(MyInt))
@MyFloatRef = CompilerGetFloatRef()
CompilerWriteLog("Return float (using ref) value from compiler method is " + CompilerFloatStr(MyFloatRef))
MyString = CompilerGetString()
CompilerWriteLog("Return string value from compiler method is " + MyString)
}
#-----------------------------------------------------------------------
# Some example "run-time" methods returning various data types. The
# data type in the 'method<>' keyword must match data type in 'return'.
#-----------------------------------------------------------------------
method<int> GetInt()
{
return(int.Random(101,150))
}
method<string> GetString()
{
data<string> MyString
MyString = StrPad(' Aztec Run-Time String ',60,'-',string.PadCenter)
return(MyString)
}
method<float ref> GetFloatRef()
{
data<float ref> MyFloatRef = new<float(RandomInt(151,200))>
return(@MyFloatRef)
}
method<Test1> GetTest1()
{
return(new<Test1>)
}
method<MethodRefTakesIntAndReturnsString> GetMethodRef1()
{
return(TestMethod1)
}
# Method that will be returned from an above method (takes int and returns string)
method<string> unique TestMethod1(int Value)
{
return(Value.Str())
}
#-----------------------------------------------------------------------------------
# Run-time entry point for the script. Calls the above methods to demo various
# different data types being returned from a method, including a method reference.
#-----------------------------------------------------------------------------------
method Main()
{
data<int> MyInt
data<Test1> MyTest1
data<string> MyString
data<float ref> MyFloatRef
data<MethodRefTakesIntAndReturnsString> MyMethodRef
StdIO.Write("Return integer value from run-time method is " + GetInt().Str())
@MyFloatRef = GetFloatRef()
StdIO.Write("Return float (using ref) value from run-time method is " + MyFloatRef.Str())
MyString = GetString()
StdIO.Write("Return string value from run-time method is " + MyString)
MyTest1 = GetTest1()
StdIO.Write("Return string value from run-time Test1.Name() method is " + MyTest1.Name())
# Get method ref returned from the method call, and then call the method using the ref.
MyMethodRef = GetMethodRef1()
MyString = MyMethodRef(RandomInt(201,250)) # Executes method based on method ref returned from method.
StdIO.Write("Return string value using method ref from run-time method is " + MyString)
# Exit the application with a normal (success) return code to the OS.
exit 0
}
# Simple class used above for method return examples.
class Test1
{
method Test1
{
}
method<string> Name()
{
data<int> shared CallCount = 0
CallCount.Inc()
return("Test1_" + CallCount.Str())
}
}