Assert
The Assert function tests a condition and aborts the script if the condition tests false. This function mimics the common C and C++ ASSERT or assert macros.
Assert( condition ) Assert( condition, message ) where |
condition is an expression that produces a result.
message is optional, and is displayed if condition fails.
The condition can be any condition that produces a value that can be tested. For example, if testing a numeric expression, the Assert will exit the script if the expression evaluates false, numeric zero, or nil. The table below lists the conditions that cause failure.
Assert Expression Failure Conditions
Expression result: |
Failure condition: |
number |
0 |
string |
nil or 0-length |
table |
nil (non existent) |
boolean |
false |
C pointer |
NULL |
CFunction |
nil (non existent) |
Lua thread |
nil |
userdata |
nil (non existent) |
nil |
always |
The following condition fails the Assert test and exits the script if fewer than 2 images were loaded.
|
-- load 2 images and create a CImageView |
|
-- fails without a message if 2 images were not loaded |