Quantcast eLua File Systems - eLua Wiki
Locked History Attachments

eLua File Systems

eLua File System Support

eLua is an independent development environment. It is neither an operating system nor does it depends on one to execute. File systems are traditionally a feature offered by an OS and eLua strives not only to support different storage media but also to make them available to Lua programs in the same way one would expect to find in an OS-based environment.

eLua currently supports three different "sub file systems", that we will simply refer to as "file systems" here, for the sake of simplicity. They are all active and available in the default builds and official distributions. Technically, they are treated as what we call eLua "components", allowing them to be included or not in custom builds. Here we will explore how to use them in Lua programs. Using the eLua portable file systems through the C API will be discussed in another tutorial.

The file systems currently supported are:

  • The ROM file system - Read only files stored in the internal MCU Flash memory
  • The MMC file system - Read/Write support for SD/MMC cards over an SPI interface
  • The RFS file system - Read/Write support for distributed files over UART connections (for now)

We refer to them as /ROM /MMC and /RFS respectively.

The ROM File System

The files in the ROM file system are part of the eLua binary image They can't be modified after the image is built and this is why this is called a read-only file system. For the same reason, you can't add/delete files after the image is built. The ROM file system doesn't support sub-directories.

The MMC File System

MMC stands for Multi Media Card and in eLua this is how we refer to the file system that stores files in SD and MMC cards. Differently from the ROM file system, you can read and write files on the MMC file system.

Obs: SD/MMC cards support for eLua was a contribution of Jesus Alvarez, as stated in our Credits page

The RFS File System

The eLua remote file system is currently supported over UART connections only. Ethernet (TCP/IP), SPI and other protocols may come in the future.

Obs: The last officially released version, eLua v0.7, does not include RFS yet. You can experiment with Remote File System before it is officially released but you must build an eLua image from the code repository trunk. You can also ask for a ready-to-use image on the '''eLua''' discussion list, specifying your target board and we'll be happy to provide one. There is also some initial doc on Remote File System for eLua on James Snyder blog at http://fanplastic.org/2009/05/11/lua-rpc/

Using the eLua File System

The eLua file systems are available from the eLua shell, from the Lua interpreter in interactive mode and from you Lua programs.

File operations from the Shell

From the shell prompt, you can list the files in the different file systems using a command similar to what you use in a Desktop environment. eLua even supports both Windows (dir) and Linux (ls) dialects, to make you feel at home no matter which world you come from. To list the files in the eLua file systems from the shell you type:

ls

or

dir

Files will be listed with their sizes, grouped in their respective file systems (when they exist), just like they were in separate sub-folders. Ex:

/rom
file1       xxxx KB
file2       xxxx KB

/mmc
file3       xxxx KB
file4       xxxx KB
file5       xxxx KB

Total:     xxxxx KB

You can also print the contents of a file with the commands type or cat

type /rom/led.lua

cat /rom/hangman.lua

File operations from Lua

eLua makes their file systems available to Lua programs via the usual Lua way, via the io module.

From the Lua interpreter prompt, you can execute a Lua program stored in one of the file systems simply including it on the file path:

dofile("/rom/hello.lua")

In a Lua program, you can open and access files through the io module:

f = io.open("/rom/myfile.txt")           -- open file & get it's handle
line = f:read("*l")                      -- read one line from file f
f:close()