lua-users home
lua-l archive

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


I've been given the task of writing a command line interface (CLI) for a
future product.  What the product does is less important than the execution
environment-- it's a Power PC processor core running the VxWorks operating
system.  I've already brought Lua up on the platfrom (it only required
small changes to the makefiles and a couple header files).  It was kind of
fun to create the minimal Lua shell, spit the text of the "life.lua"
program at it, and watch it run a few thousand generations...

I'm considering writing the CLI as a translator.  That is, I would accept
input, parse it, validate it, and then generate Lua code on the fly.  This
would then be executed by dostring().

For example, the CLI language has variables that start with a dollar sign
and engage in expressions:

     $example = (2 * $someVar) / 3

I would translate this line to this string:

     "var.example = (2 * var.someVar) / 3"

Which I would then execute with dostring().

Control-flow statements would work in a similar way.  If the user typed
this code in the CLI:

     while ($example < 10) {
          command argument1 argument2 $example
     }

I would translate it to this string:

     [[while var.example < 10 do
          command("argument1", "argument2", var.example)
     end]]

That's the general idea.  I basically want to transform an input language
into Lua and have Lua do all the acutal work.  But before I take on this
approach I wanted to find out if anyone saw any problems or had any
concerns.