m Data Types and Values

Scalars

m is not a strongly typed language. As such, it allows variables and array elements to assume any valid m data type (number, string, array, etc.) and to change that type at any time (positively put, m is "fully polymorphic"). Consequently, all variables and array elements in m are of type Runtime::Value. Internally, this is a union of eight bytes aligned on an eight byte boundary.

The following table summarizes the methods to set and get a Runtime::Value:

m typeC++ typeGetterSetter/Creator
NumberTRealGetNumberL()SetNumber()
NumberTIntGetIntL()SetNumber()
NumberTTimeGetTimeL()SetTime()
NumberTTimeIntervalMicroSeconds32GetTimeoutL()SetTimeout()
NumberTUidGetUidL()
BooleanTBoolGetBooleanL()SetBoolean()
StringRuntime::StringGetStringL()NewStringL()
StringTPtrCGetPtrCL()
ArrayRuntime::ArrayGetArrayL()NewArrayL()
nullIsNull()SetNull()

For most datatypes, there are also constructors or equivalent static methods, e.g. Runtime::BooleanValue.

The getters all leave if the type of the value is not the requested one. You can use IsNumber(), IsString() etc. to check for the type of a value.

GetTimeoutL() and SetTimeout() convert a millisecond number to a microsecond timeout value and vice versa. GetTimeoutL() also checks for the number not exceeding 231-1 microseconds (2147483 milliseconds).

GetUidL() correctly handles the signed/unsigned problems caused by Symbian's inconsistent definition of the TUid type: numbers in the ranges 0x80000000 to 0xffffffff and -0x7fffffff to -1 are both mapped to the correct TUid instance.

World Server Example, Continued

Returning to our world server example, we can already count the function calls and implement world.count with the above table:

// count this call
Runtime::Value &calls = runtime->GetVariableL(WORLD, CALLS);
calls.SetNumber(calls.GetNumberL() + 1);
switch (index) {
case CountFunction:
  // directly set the result
  result.SetNumber(server.NumberCities());
  break;

Furthermore, even though we don't know yet how to create the m array containing a city's data, we can declare the following function whic