Lua Blob v85840 Release

Although I've never officially announced it, it's no big secret that Rena is written almost entirely in Lua*. This beautiful language is what allows for such flexibility and extensibility.

*Actually, I've made some significant changes to the Lua source, making it no longer binary-compatible with existing code. Thus it can't technically be called Lua anymore. I'm calling the modified version Aura. It's basically just Lua with some useful new stuff.

One great thing about Lua is that it's a very lightweight language. This of course means it may not have everything you need for a big project. It's really designed to be used as a scripting engine in games or "anything that needs one", as stated on its website. However, it's simple to write libraries to add functionality that integrates seamlessly into the language. LuaGnome is one such library, providing the GUI.

One thing Lua isn't great at is working with large arrays of bytes. Raw image data, emulated memory, anything where you have a huge block of memory you need to access directly. Your options are to use a table, or manipulate characters in a string. Tables are not ideal for this job since they function more as hash maps than arrays, and the native numeric type is double (64-bit floating point) - a lot of overhead for one byte. Strings aren't ideal because they're intended for (duh) strings of text - they don't provide direct access to bytes, only functions to extract and piece together substrings. Either method is slow, wasteful and potentially awkward for large memory blocks.

To solve this problem I wrote the Blob library. It simply gives you a memory block which you can access like a table. It can be accessed as 8, 16, 32 or 64-bit integers, floats, and doubles, converted to string, and dumped to or created from a file. Using this in place of an ordinary table for Rena's texture graphics gave a significant speed boost. It also provides a pointer that can be passed to libraries such as LuaGL.

This library is released under the New BSD License, so it's free to use as you please.

No comments:

Post a Comment