Skip to Content
Lua Quick Start Guide
book

Lua Quick Start Guide

by Gabor Szauer
July 2018
Beginner
202 pages
5h 42m
English
Packt Publishing
Content preview from Lua Quick Start Guide

assert

Errors raised with pcall do not interfere with the stability of the program. When an error can be recovered from, it should be handled with pcall. But, if an error is catastrophic, it should be handled with assert. Unlike pcall, assert assumes an error is not recoverable and will simply kill the program.

The assert function takes two arguments, a test value and a string. If the test value evaluates to false or nil, assert will kill the program. If the test value evaluates to anything else, it is returned. The second argument is a string. This string will be printed out as the reason that the program has failed executing. The normalize example can be re-written to use an assertion, like so:

function Normalize(x, y, z)  local dot = x ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Lua Programming

Beginning Lua Programming

Kurt Jung, Aaron Brown
Vim Masterclass

Vim Masterclass

Jason Cannon

Publisher Resources

ISBN: 9781789343229Supplemental Content