vsergeev / lua-periphery

A Lua library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
MIT License
186 stars 39 forks source link

error error #4

Closed cbnatrix closed 9 years ago

cbnatrix commented 9 years ago

The error is raised because I didn't sudo lua. If I do, periphery works fine except that errors have an issue: $ lua Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio

periphery = require('periphery') GPIO = periphery.GPIO i = GPIO(23, 'in') (error object is not a string) <-- here is the problem =periphery.version 1.0.4

Pi 2, Raspian

vsergeev commented 9 years ago

This is expected behavior for Lua 5.1. lua-periphery throws a table object on errors, which includes additional context that some applications may choose to use during error handling.

Unfortunately, the Lua 5.1 console does not call tostring() on error objects it encounters, and instead gives you the error message you reported above. Newer versions of Lua (5.2, 5.3), will call tostring() on error objects thrown to the console and format a more useful error message.

In all three versions, pcall() behaves the same way and can be used the same way for error handling. This issue only applies to Lua 5.1 formatting errors in the console.