lua-users home
lua-l archive

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


On 6/17/07, Rici Lake <lua@ricilake.net> wrote:
Perhaps I don't understand your problem sufficiently. Are you
trying to grab the output of an arbitrary unmodified Lua
script? Or do you simply want to run a script in a more
controlled communications environment?


I am simply attempting to grab the output from any lua script.

The second one can easily be accomplished by simply
writing your own read() and write() functions, and
letting the script call them.


The read and write functions are in C, using sockets (file
descriptors) over TCP.

You could achieve the first goal, too, by replacing the
entire io. library, but that's a lot of work. If your
target environment includes some equivalent of funopen()
(as in BSD) -- I think the Linux equivalent is called
fopencookie()), then you can just reopen the standard
file descriptors with new ones which invoke your functions.
I don't know if Windows has an equivalent facility or
what it might be, though.

Oh, I am most definately on a Linux box :-) I had given some thought
to setting environmental variables when the program begins and then
allowing both the host C program and any lua children to modify the
environs, however I am not sure of the reliability of this. I could
have simply written some functions for the lua lib that create global
buffers accessible from the C program, but I am trying to stay as
portable as possible. Providing custom lua patches for everyone who
want's to run my program is not a very nice thing to think about ;-)

So, here is basically what I want to do:
The user enters a script name and the host program checks the user's
variables, then it creates a modification for the original script
based on those variables, calls that script and then shows the output
to the user. Here is a sample:

--Output from the host
H = {[[d68c7c9f-1629-45ef-a678-6aae4298562d]]}
--Original script lines hereafter
print("Your unique user ID this session is: " .. H[1])
--End Script

So the host program would provide the contents of the table "H" and
the script would print it out. Of course, this is sort of like a
"Hello World" attempt. Future versions of this exchange would of
course utilize more output from the host program and actual functions
in the lua script.
The end result would be a C program with customizable output for
aesthetic purposes, as well as possible database management via
embedded Lua scripts.
I hope this clears things up a bit...

Thanks to Rici and Leonardo for their generous replies!
-Shane