lua-users home
lua-l archive

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


Just checked out the lua bash project. It's neat to be able to call

   enable -f ../luabash.so luabash

in bash to dynamically load a bash builtin.

My approach, however, is to include the standard Lua interpreter
itself into bash as
a builtin. The advantages include minimizing duplication and conforming to
standard. Moreover, I don't have to write much code--less than 40
lines of C code
actually and I have the full power of the interpreter (as oppose to
inventing builtin
command parameters to be translated).

Wei

On 3/9/07, Weiguang Shi <wgshizz@gmail.com> wrote:
Thank you! And sorry for calling it a bug. Will check out luabash soon.

I just put the whole interpreter as a builtin (called lexec) to bash
(and later zsh)
so that lua code maintains its state inside bash script, e.g.,

$ lexec -e "a=1"
$ ls
$ ...
$ lexec -e "a=a+1"
$ pwd
$ ...
$ lexec -e "print(a)"
2

This  way, I can create scripts that inter-mix bash and Lua code with one
Lua machine running from start to finish.

Wei


On 3/9/07, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
> > I've fixed the problem by calloc() a bigger piece of memory (just 4
> > bytes bigger) than necessary for argv[] instead of malloc() for the
> > exact amount of memory, i.e., argc*sizeof(char *).
>
> I gather you're running the Lua interpreter via exec (or its variants)
from
> bash...
>
> (BTW, are you aware of Lua Bash: http://freshmeat.net/projects/luabash/ ?)
>
> Your fix is correct but I think you missunderstand the requirements on
argv:
> it's an array with argc+1 positions, the last one being NULL. So, you need
> to malloc argc+1 positions for argv and set the last one to NULL before
> exec'ing an external program.
>
> Here are two references I found:
>
http://publications.gbdirect.co.uk/c_book/chapter10/arguments_to_main.html
>  http://www-ccs.ucsd.edu/c/lib_over.html (search for main)
>
> --lhf
>