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

pcall and error

Lua's most efficient way to handle errors is pcall, or protected call. The pcall function takes only one argument, the function to be called. Optionally, if the function takes arguments, they should also be passed to pcall as additional arguments. On success, it returns true and all of the values the function would normally return. On failure, it returns false, and any error messages that need to be returned as well.

When an error happens, the error function can be used to stop the execution of the current method. The error function expects only one argument (and even that's optional): an error message. This message can be a string, but doesn't have to be. The error message can be any valid value. The code here shows a simple ...

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