[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Protocol Specification in Lua
- From: Gyepi SAM <self-lua@...>
- Date: Sat, 2 Oct 2010 11:47:55 -0400
On Sat, Oct 02, 2010 at 12:20:15PM +0200, Ico wrote:
> * On 2010-10-02 Sean Conner <sean@conman.org> wrote :
>
> > Okay, now I'm curious---how does one *get* a compiled Lua table? I can
> > see how to get a Lua function (in fact, I'm doing that now, only between
> > separate Lua instances and not over a network connection) but a table?
>
> What about compiling a function returning the table:
>
> function foo()
> return { "one", "two", "three" }
> end
>
> local compiled = string.dump(foo)
>
> and to retrieve the table do a loadstring:
>
> ti loadstring(compiled)()
The function can be anonymous:
string.dump(function() return { "one", "two", "three" } end)
I usually generate data with other languages and feed them to lua.
Simple shell example:
cat <<EOS | luac -o data.luac -
do
return { "one", "two", "three" }
end
EOS
lua -e 'print(dofile("data.luac")[1])'
-Gyepi