tbert
tbert

Reputation: 2097

lua text interface library (i.e., writing a custom shell in lua)

Specifically, something which automates the drudgery along the lines of Perl's Term::Shell

Failing that, are there any good parsing libraries which would suit such a project?

I have a need to wrap an OEM-provided tool -- which, while usable, is utterly baroque -- in something a little friendlier to the human brain.

Thanks to all who reply!

Upvotes: 2

Views: 895

Answers (2)

Faylixe
Faylixe

Reputation: 478

Well, depending of your lua implementation, but the os.execute() function allow to call a shell function on your system (i do not know though if it will work since you are working on embedded device), but a custom shell is easy to write in Lua from scratch.

Just get the user input using io.read() / io.write() functions, then you can parse the user commande using such function :

function string.split(self,c)
local l , c , b = {} , c or " " , self
while b:find(c) do
    table.insert(l,b:sub(0,({b:find(c)})[1]-1))
    b = b:sub(({b:find(c)})[1]+(#c))
end
if not(b == "") then table.insert(l,b) end
    return l
end

The command name is given by the first token of the table, and all the arguments are following, dealing with table functions and unpack() parsing will be very fast to implement.

Upvotes: 1

kikito
kikito

Reputation: 52651

If your OEM has a C interface, consider writing a binary module instead. That way you will be able to use the default lua console:

$: lua

Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> oem = require 'baroque-oem'
> oem.foo('bar')

Upvotes: 0

Related Questions