[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Chunk-within-chunk for multithreading - Lua 6?
- From: Asko Kauppi <askok@...>
- Date: Fri, 16 Feb 2007 18:05:20 +0200
In my tests with Lua Lanes, multithreaded programming using multiple
Lua states, I've come to the wish to embed separate chunks of Lua
code, within surrounding chunks. This can currently be done by using
strings, but has a few limitations to it:
thread [[
local a,b,c= ...
-- ...
return xx
]]
- Chunks embedded as strings are compiled (syntax checked) at runtime
(the 'thread' call), not at compile time
- Chunks embedded will have their own line numbering, not that of the
actual (surrounding) source file
- Chunk source takes up space (as a string) when it could actually be
stored as a byte-compiled 'chunk'
One could have a special syntactic format of declaring 'sub-chunks',
solving all the above issues at once. Maybe this could even be done
as a tkn fltr ;) --not saying the word, i bet there's already people
fltering out such posts!--
thread @[[
local a,b,c= ...
-- ...
return xx
]]
This would compile the subchunk into a bytecode string, which is then
the value of the @[[ ... ]] expression. Opinions?
Another approach would be to deal with it function-wise, maybe with a
new 'chunk' keyword:
thread( chunk( a,b,c )
-- ...
return xx
end
)
This would pass the parameters nicer, but isn't it misleading that
the resulting value would be a string, not a function. Actually, it
could even be a function, if that function is a wrapper to ignite the
thread once called. This would, however, marry threading and chunking
together in a non-Luaish way.
I would like to hear your comments on this. Doing the @[[ ]] syntax
would imho be a good start.
Also, are there other usage situations where embedding chunks of code
within another chunk has surfaced, in your work?
[ The difference to just using functions is, we cannot send closures
(easily) across separate Lua states (can we?). The chunk is intended
to be 'the' code that the separate Lua state is to run, and once it
returns, that state is getting eliminated. ]
-asko