lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


We use LuaJIT, particularly for the FFI, so we are stuck with 5.1. I suppose this will be an on going problem as the two projects diverge.


On Tue, May 27, 2014 at 4:16 PM, Ivan Sergeev <vsergeev@gmail.com> wrote:
I originally wrote it to support 5.1+, but ran into a few issues and inconveniences that made me opt for 5.2+.

From the Lua C API side of things, the only real issue was that many of the methods in the MMIO submodule require the full unsigned 32-bit integer range to work (specifying a base physical address, offset, 32-bit values, etc.). lua_tointeger() in 5.1 loses that information when it converts to a signed 32-bit integer, so the equivalent of lua_tounsigned() would need to be backported to lua-periphery for the MMIO submodule to work correctly. luaL_len() would also have to be backported/replaced as Harley pointed out, but it's only used a handful of times in the library to get the length of a table.

From the Lua language side of things, 5.2 has two features that make it more conducive to working with bits in this context. One is the stock bit32 library, which is pretty much essential for working with the SPI, I2C, and MMIO interfaces. The other is supporting hexadecimal escape characters in strings, like "\xaa\xbb\xcc", which is not essential (e.g. you could use string.char() in 5.1 instead), but handy for the Serial interface if you're working with binary data strings.

So lua-periphery could be modified to work with 5.1, but probably won't be very useful in the native language without additional libraries (at least to supply the bitwise operations) and I was aiming to make it useful with Lua out of the box. I suspect 5.3 will be an even more natural fit for lua-periphery with the native bitwise operators. (It would also be more awesome if it had equivalent of Python's struct.pack() and struct.unpack() built-in.)

Thanks,
~vsergeev
Ivan Sergeev


On Mon, May 26, 2014 at 1:23 PM, Harley Laue <losinggeneration@gmail.com> wrote:
A quick try says yes. First lua_Unsigned is used, as well as luaL_len. I'm sure with a bit more time though, a 5.1 & 5.2 compatible version could be made.


On 05/26/14 14:50, djczaski@gmail.com wrote:
Looks very interesting. Are there are issue getting it to run on 5.1.5?

On May 26, 2014, at 12:21 PM, Ivan Sergeev <vsergeev@gmail.com <mailto:vsergeev@gmail.com>> wrote:

Linux Peripheral I/O (GPIO, SPI, I2C, MMIO, Serial) with Lua

https://github.com/vsergeev/lua-periphery

lua-periphery is a library for GPIO, SPI, I2C, MMIO, and Serial peripheral I/O interface access in userspace Linux. It is useful in embedded Linux environments (including BeagleBone, Raspberry Pi, etc. platforms) for interfacing with external peripherals. lua-periphery requires Lua 5.2 or greater, has no dependencies outside the standard C library and Linux, is portable across architectures, and is MIT licensed.

github: https://github.com/vsergeev/lua-periphery
moonrocks: http://rocks.moonscript.org/modules/luarocks/lua-periphery
(and on luarocks)

linux-x86_64 binary rock: https://github.com/vsergeev/lua-periphery/releases/download/v1.0.1/lua-periphery-1.0.1-1.linux-x86_64.rock

linux-x86 binary rock: https://github.com/vsergeev/lua-periphery/releases/download/v1.0.1/lua-periphery-1.0.1-1.linux-x86.rock

linux-arm binary rock: https://github.com/vsergeev/lua-periphery/releases/download/v1.0.1/lua-periphery-1.0.1-1.linux-arm.rock

Thanks,
~vsergeev
Vanya Sergeev