wiki:UsingMutekH/LuaMicroShell

Version 1 (modified by Nicolas Pouillon, 14 years ago) (diff)

--

There is a shell demo application that comes with MutekH.

This applications uses two MutekH features as its core:

  • The in-kernel lua binding
  • The libtermui terminal interface with completion

Moreover, this application has optional parts that can demonstrate other services of the kernel. Depending on your configuration, more commands may be available. We'll see the complete list of features that can be built below.

Features

VFS access

When you use the CONFIG_VFS token, you'll have access to all file-related functions.

They are the usual shell commands (ls, cat, cd, pwd, mkdir, rm, mv, ln, hexdump), except they use a lua-ish syntax (with arguments like a function call).

Example:

[lua:] mkdir("foo")
[lua:] cd("foo")
[lua:foo] ls()
[lua:foo] append("file.txt", "abcd")
[lua:foo] ls()
file.txt [reg] 4
[lua:foo] cat("file.txt")
abcd[lua:foo] rm("file.txt")
[lua:foo] ls()
[lua:foo]

Il you compile other filesystem drivers (macro:CONFIG_DRIVER_FS_FAT16, macro:CONFIG_DRIVER_FS_ISO9660, macro:CONFIG_DRIVER_FS_DEVFS), you may even use mount().

[lua:] mkdir("dev")
[lua:] mount("devfs", "dev")
[lua:] cd("dev/child0")
[lua:child0] ls()
cpus-Ppc,405@0 [dir] 0
cpus-Ppc,405@1 [dir] 0
cpus-Ppc,405@2 [dir] 0
cpus-Ppc,405@3 [dir] 0
tty@0 [dir] 0
block@0 [dir] 0
xicu@0-out@0 [dir] 0
xicu@0-out@1 [dir] 0
xicu@0-out@2 [dir] 0
xicu@0-out@3 [dir] 0
xicu@0 [dir] 0
memory@0 [dir] 0
[lua:child0] cd("tty@0")
[lua:tty@0] ls()
handle [reg] 0
[lua:tty@0] append("handle", "message on tty")
message on tty[lua:tty@0]

You may watch the internal state of the VFS with

[lua:] vfs_dump()
...
[lua:]

Cryptographic functions

MutekH contains a cryptographic API. It is enabled with the macro:CONFIG_LIBCRYPTO

The shell can be used to apply some cryptographic operations on files. The first command to test is a hash of a file. This example requires macro:CONFIG_LIBCRYPTO_MD5:

[lua:] md5("test.txt")
58a8785971212ef137f04b05df26ea15

Timer functions

MutekH has a built-in timer. If you enabled support for the timer (with the macro:CONFIG_MUTEK_TIMERMS token), and if you have a proper timer device setup, you may use the following commands:

[lua:] printlater(12000, "silly delayed message")
[lua:] cat("test.txt")
silly delayed message
test contents line 1
contents line test 2
[lua:]