lua-users home
lua-l archive

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



On 17-Jun-07, at 6:14 AM, Shane Lee wrote:

I was afraid this was going to be the answer. My own solution was
similar, except that I changed the io parameters inside the script
itself with a variable passed from the C code. Still, this solution to
me seems to be far too wasteful of system resources, even if you
continually removed the file(s) after the output was parsed. I guess
that's what the /tmp folder is for, though...
I don't suppose (without getting into threads) that there is any other
way to solve this issue? I was sort of hoping there was a set of
official Lua library functions that allowed this behavior. Of course,
I understand the futility of trying to embedd compiled C code into a
Lua script, but it seems to me that some sort of dynamic loading
system could be/has been devised for just such a problem.
Oh well, back to the stone ages with me, I guess. Thanks, Leonardo!


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?

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

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.