AbbrevPath Beep

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.

Syntax

Assert( condition, message=nil )

bullet.gif    condition is an expression that produces a result (see Remarks).

bullet.gif    message is optional, and is displayed if condition fails.

Remarks

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 reference 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

Example

The following condition fails the Assert test and exits the script if fewer than 2 images were loaded.

 

V = LoadImages(2)

-- load 2 images and create a CImageView

Assert( V:Count() < 2 )

-- fails without a message if 2 images were not loaded

Related Topics

Exit


Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.